Permalink
Browse files

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 <robin.rosenberg@dewire.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
  • Loading branch information...
1 parent 093920a commit 9c26a41ec0914b009bd96253fa387b73d271011e @robinrosenberg robinrosenberg committed with spearce Mar 7, 2009
@@ -926,7 +926,21 @@ public String getBranch() throws IOException {
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).
*/
@@ -51,6 +51,7 @@
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 @@ else if (TransportLocal.canHandle(remote))
final Collection<RefSpec> 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);

0 comments on commit 9c26a41

Please sign in to comment.