Browse Source

PushCommand: Default to pushing HEAD

If no RefSpec was specified, push the branch that is currently
checked out as HEAD.

Change-Id: I6f13ef6346188698a14e000fc590850afbc34b21
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.12
Shawn O. Pearce 14 years ago
parent
commit
c3c4398b64
  1. 7
      org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java

7
org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java

@ -58,6 +58,7 @@ import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor; import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ProgressMonitor; import org.eclipse.jgit.lib.ProgressMonitor;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.CredentialsProvider;
import org.eclipse.jgit.transport.PushResult; import org.eclipse.jgit.transport.PushResult;
@ -123,6 +124,12 @@ public class PushCommand extends GitCommand<Iterable<PushResult>> {
ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3); ArrayList<PushResult> pushResults = new ArrayList<PushResult>(3);
try { try {
if (refSpecs.isEmpty()) {
Ref head = repo.getRef(Constants.HEAD);
if (head != null && head.isSymbolic())
refSpecs.add(new RefSpec(head.getLeaf().getName()));
}
if (force) { if (force) {
for (int i = 0; i < refSpecs.size(); i++) for (int i = 0; i < refSpecs.size(); i++)
refSpecs.set(i, refSpecs.get(i).setForceUpdate(true)); refSpecs.set(i, refSpecs.get(i).setForceUpdate(true));

Loading…
Cancel
Save