Skip to content

Commit

Permalink
Evaluate short refnames into full names during push
Browse files Browse the repository at this point in the history
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
robinrosenberg authored and spearce committed Mar 7, 2009
1 parent 093920a commit 9c26a41
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 4 deletions.
16 changes: 15 additions & 1 deletion org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down
21 changes: 18 additions & 3 deletions org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -243,10 +244,24 @@ public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
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);

Expand Down

0 comments on commit 9c26a41

Please sign in to comment.