Browse Source

PushCommand: Allow adding any reference string

The simplified form of add(String) makes it easier for applications
to pass down user input and allow PushCommand to convert it to the
internal RefSpec object.

Change-Id: Ibd2e95852db0e52ea4a36032942c4c42a7fb4261
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.12
Shawn O. Pearce 14 years ago committed by Chris Aniszczyk
parent
commit
74a129328e
  1. 39
      org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java

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

@ -317,6 +317,45 @@ public class PushCommand extends GitCommand<Iterable<PushResult>> {
return this;
}
/**
* Add a reference to push.
*
* @param ref
* the source reference. The remote name will match.
* @return {@code this}.
*/
public PushCommand add(Ref ref) {
refSpecs.add(new RefSpec(ref.getLeaf().getName()));
return this;
}
/**
* Add a reference to push.
*
* @param nameOrSpec
* any reference name, or a reference specification.
* @return {@code this}.
* @throws JGitInternalException
* the reference name cannot be resolved.
*/
public PushCommand add(String nameOrSpec) throws JGitInternalException {
if (0 <= nameOrSpec.indexOf(':')) {
refSpecs.add(new RefSpec(nameOrSpec));
} else {
Ref src;
try {
src = repo.getRef(nameOrSpec);
} catch (IOException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,
e);
}
if (src != null)
add(src);
}
return this;
}
/**
* @return the dry run preference for the push operation
*/

Loading…
Cancel
Save