diff options
author | Robin Rosenberg <robin.rosenberg@dewire.com> | 2014-04-26 10:55:42 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2014-04-27 10:35:21 +0200 |
commit | 6605255d9906c5277d215396ebcc395484b9f10c (patch) | |
tree | 76476317d92fcee58cd5b6b3f7d6ebc178169560 /org.eclipse.jgit | |
parent | 8923e67a1680d3a5fd7766cdce90d07bae1a407a (diff) | |
download | jgit-6605255d9906c5277d215396ebcc395484b9f10c.tar.gz jgit-6605255d9906c5277d215396ebcc395484b9f10c.zip |
Add methods to Repository to handle remote names
Instead of requiring the caller to know how to list remote
names or parse remote branch names, add a few utilities for
that.
Change-Id: Ib6b2403532f4abbce594a03c0b9da49d30b19f70
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java index c350dddb25..1538d277b1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java @@ -1276,6 +1276,40 @@ public abstract class Repository { /** * @param refName + * @return the remote branch name part of <code>refName</code>, i.e. without + * the <code>refs/remotes/<remote></code> prefix, if + * <code>refName</code> represents a remote tracking branch; + * otherwise null. + * @since 3.4 + */ + public String shortenRemoteBranchName(String refName) { + for (String remote : getRemoteNames()) { + String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$ + if (refName.startsWith(remotePrefix)) + return refName.substring(remotePrefix.length()); + } + return null; + } + + /** + * @param refName + * @return the remote name part of <code>refName</code>, i.e. without the + * <code>refs/remotes/<remote></code> prefix, if + * <code>refName</code> represents a remote tracking branch; + * otherwise null. + * @since 3.4 + */ + public String getRemoteName(String refName) { + for (String remote : getRemoteNames()) { + String remotePrefix = Constants.R_REMOTES + remote + "/"; //$NON-NLS-1$ + if (refName.startsWith(remotePrefix)) + return remote; + } + return null; + } + + /** + * @param refName * @return a {@link ReflogReader} for the supplied refname, or null if the * named ref does not exist. * @throws IOException @@ -1613,4 +1647,13 @@ public abstract class Repository { throws IOException { new RebaseTodoFile(this).writeRebaseTodoFile(path, steps, append); } + + /** + * @return the names of all known remotes + * @since 3.4 + */ + public Set<String> getRemoteNames() { + return getConfig() + .getSubsections(ConfigConstants.CONFIG_REMOTE_SECTION); + } } |