瀏覽代碼

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>
tags/v0.12.1
Shawn O. Pearce 13 年之前
父節點
當前提交
74a129328e
共有 1 個文件被更改,包括 39 次插入0 次删除
  1. 39
    0
      org.eclipse.jgit/src/org/eclipse/jgit/api/PushCommand.java

+ 39
- 0
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…
取消
儲存