Просмотр исходного кода

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 лет назад
Родитель
Сommit
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
*/

Загрузка…
Отмена
Сохранить