From 74a129328ede11dab19b9647ff6adca4e12d51ac Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Mon, 14 Mar 2011 08:14:46 -0700 Subject: [PATCH] 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 --- .../src/org/eclipse/jgit/api/PushCommand.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java index d3512cc0c..40bade884 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java @@ -317,6 +317,45 @@ public class PushCommand extends GitCommand> { 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 */