Java Code Examples for org.eclipse.jgit.lib.Repository#shortenRefName()

The following examples show how to use org.eclipse.jgit.lib.Repository#shortenRefName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Branch.java    From orion.server with Eclipse Public License 1.0 6 votes vote down vote up
@PropertyDescription(name = GitConstants.KEY_REMOTE)
private JSONArray getRemotes() throws URISyntaxException, JSONException, IOException, CoreException {
	String branchName = Repository.shortenRefName(ref.getName());
	String remoteName = getConfig().getString(ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REMOTE);
	List<RemoteConfig> remoteConfigs = RemoteConfig.getAllRemoteConfigs(getConfig());
	ArrayList<JSONObject> remotes = new ArrayList<JSONObject>();
	for (RemoteConfig remoteConfig : remoteConfigs) {
		if (!remoteConfig.getFetchRefSpecs().isEmpty()) {
			Remote r = new Remote(cloneLocation, db, remoteConfig.getName());
			r.setNewBranch(branchName);
			// Ensure that the remote tracking branch is the first in the list.
			// Insert at the beginning of the list as well when the remote tracking branch is not set but the branch has been pushed to the remote
			if (remoteConfig.getName().equals(remoteName) || (remoteName == null && db.resolve(Constants.R_REMOTES + remoteConfig.getName() + "/" + branchName) != null)) {
				remotes.add(0, r.toJSON());
			} else {
				remotes.add(r.toJSON());
			}
		}
	}
	JSONArray result = new JSONArray();
	for (JSONObject remote : remotes) {
		result.put(remote);
	}
	return result;
}
 
Example 2
Source File: UIGit.java    From hop with Apache License 2.0 5 votes vote down vote up
@Override
public String getShortenedName( String name, String type ) {
  if ( name.length() == Constants.OBJECT_ID_STRING_LENGTH ) {
    return name.substring( 0, 7 );
  } else {
    return Repository.shortenRefName( name );
  }
}
 
Example 3
Source File: Branch.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public String getName(boolean fullName, boolean encode) {
	String name = ref.getName();
	if (!fullName)
		name = Repository.shortenRefName(ref.getName());
	if (encode)
		name = GitUtils.encode(name);
	return name;
}
 
Example 4
Source File: RemoteBranch.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private String getName(boolean fullName, boolean encode) {
	String name = Constants.R_REMOTES + remote.getName() + "/" + this.name; //$NON-NLS-1$
	if (!fullName)
		name = Repository.shortenRefName(name);
	if (encode)
		name = GitUtils.encode(name);
	return name;
}
 
Example 5
Source File: Tag.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
private String getName(boolean fullName, boolean encode) {
	String name = null;
	if (tag != null)
		name = fullName ? Constants.R_TAGS + tag.getTagName() : tag.getTagName();
	if (ref != null)
		name = fullName ? ref.getName() : Repository.shortenRefName(ref.getName());
	if (name == null)
		return null;
	if (encode)
		name = GitUtils.encode(name);
	return name;
}
 
Example 6
Source File: MergeMessageFormatter.java    From onedev with MIT License 4 votes vote down vote up
/**
 * Construct the merge commit message.
 *
 * @param refsToMerge
 *            the refs which will be merged
 * @param target
 *            the branch ref which will be merged into
 * @return merge commit message
 */
public String format(List<Ref> refsToMerge, Ref target) {
	StringBuilder sb = new StringBuilder();
	sb.append("Merge "); //$NON-NLS-1$

	List<String> branches = new ArrayList<>();
	List<String> remoteBranches = new ArrayList<>();
	List<String> tags = new ArrayList<>();
	List<String> commits = new ArrayList<>();
	List<String> others = new ArrayList<>();
	for (Ref ref : refsToMerge) {
		if (ref.getName().startsWith(Constants.R_HEADS)) {
			branches.add("'" + Repository.shortenRefName(ref.getName()) //$NON-NLS-1$
					+ "'"); //$NON-NLS-1$
		} else if (ref.getName().startsWith(Constants.R_REMOTES)) {
			remoteBranches.add("'" //$NON-NLS-1$
					+ Repository.shortenRefName(ref.getName()) + "'"); //$NON-NLS-1$
		} else if (ref.getName().startsWith(Constants.R_TAGS)) {
			tags.add("'" + Repository.shortenRefName(ref.getName()) + "'"); //$NON-NLS-1$ //$NON-NLS-2$
		} else {
			ObjectId objectId = ref.getObjectId();
			if (objectId != null && ref.getName().equals(objectId.getName())) {
				commits.add("'" + ref.getName() + "'"); //$NON-NLS-1$ //$NON-NLS-2$
			} else {
				others.add(ref.getName());
			}
		}
	}

	List<String> listings = new ArrayList<>();

	if (!branches.isEmpty())
		listings.add(joinNames(branches, "branch", "branches")); //$NON-NLS-1$//$NON-NLS-2$

	if (!remoteBranches.isEmpty())
		listings.add(joinNames(remoteBranches, "remote-tracking branch", //$NON-NLS-1$
				"remote-tracking branches")); //$NON-NLS-1$

	if (!tags.isEmpty())
		listings.add(joinNames(tags, "tag", "tags")); //$NON-NLS-1$ //$NON-NLS-2$

	if (!commits.isEmpty())
		listings.add(joinNames(commits, "commit", "commits")); //$NON-NLS-1$ //$NON-NLS-2$

	if (!others.isEmpty())
		listings.add(StringUtils.join(others, ", ", " and ")); //$NON-NLS-1$ //$NON-NLS-2$

	sb.append(StringUtils.join(listings, ", ")); //$NON-NLS-1$

	String targetName = target.getLeaf().getName();
	if (!targetName.equals(Constants.R_HEADS + Constants.MASTER)) {
		String targetShortName = Repository.shortenRefName(targetName);
		sb.append(" into " + targetShortName); //$NON-NLS-1$
	}

	return sb.toString();
}