From 9c26a41ec0914b009bd96253fa387b73d271011e Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 7 Mar 2009 23:18:19 +0100 Subject: [PATCH] Evaluate short refnames into full names during push With this we can use short names like master instead of refs/heads/master when pushing. This is slightly more convenient. Pushing a delete still requires the long format. Signed-off-by: Robin Rosenberg Signed-off-by: Shawn O. Pearce --- .../src/org/spearce/jgit/lib/Repository.java | 16 +++++++++++++++- .../src/org/spearce/jgit/transport/Transport.java | 21 ++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java index 30bd4a30..8132e27b 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java @@ -926,7 +926,21 @@ public class Repository { return ref; } } - + + /** + * Get a ref by name. + * + * @param name + * the name of the ref to lookup. May be a short-hand form, e.g. + * "master" which is is automatically expanded to + * "refs/heads/master" if "refs/heads/master" already exists. + * @return the Ref with the given name, or null if it does not exist + * @throws IOException + */ + public Ref getRef(final String name) throws IOException { + return refs.readRef(name); + } + /** * @return all known refs (heads, tags, remotes). */ diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java index 3aec5cab..a0a25751 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java @@ -51,6 +51,7 @@ import java.util.Map; import org.spearce.jgit.errors.NotSupportedException; import org.spearce.jgit.errors.TransportException; +import org.spearce.jgit.lib.Constants; import org.spearce.jgit.lib.NullProgressMonitor; import org.spearce.jgit.lib.ProgressMonitor; import org.spearce.jgit.lib.Ref; @@ -243,10 +244,24 @@ public abstract class Transport { final Collection procRefs = expandPushWildcardsFor(db, specs); for (final RefSpec spec : procRefs) { - final String srcRef = spec.getSource(); + String srcRef = spec.getSource(); + final Ref src = db.getRef(srcRef); + if (src != null) + srcRef = src.getName(); + String remoteName = spec.getDestination(); // null destination (no-colon in ref-spec) is a special case - final String remoteName = (spec.getDestination() == null ? spec - .getSource() : spec.getDestination()); + if (remoteName == null) { + remoteName = srcRef; + } else { + if (!remoteName.startsWith(Constants.R_REFS)) { + // null source is another special case (delete) + if (srcRef != null) { + // assume the same type of ref at the destination + String srcPrefix = srcRef.substring(0, srcRef.indexOf('/', Constants.R_REFS.length())); + remoteName = srcPrefix + "/" + remoteName; + } + } + } final boolean forceUpdate = spec.isForceUpdate(); final String localName = findTrackingRefName(remoteName, fetchSpecs); -- 2.11.4.GIT