Java源码示例:org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode
示例1
/**
* {@code git checkout}
*/
private void checkout() {
final String localBranch = getLocalTargetBranch();
if (localBranch == null) {
return;
}
try {
final List<Ref> branchListResult = repo.branchList().call();
final boolean localBranchExists = branchListResult.stream()
.anyMatch(ref -> ref.getName().endsWith(localBranch));
CheckoutCommand branchCmd = repo.checkout().setName(localBranch);
if (!localBranchExists) {
branchCmd = branchCmd.setCreateBranch(true).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint(mergeUnit.getBranchTarget());
}
branchCmd.call();
} catch (GitAPIException e) {
exception = new MergeUnitException(String.format("Could not checkout branch '%s'", localBranch), e); //$NON-NLS-1$
}
}
示例2
public void reset(ProgressMonitor monitor) {
try {
// create branch and set upstream
gitRepo.branchCreate()
.setName(branch)
.setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint("origin/" + branch)
.setForce(true)
.call();
// reset to remote head
gitRepo.reset()
.setProgressMonitor(monitor)
.setMode(ResetType.SOFT)
.setRef("refs/remotes/origin/" + branch)
.call();
} catch (Exception e) {
logger.error("Exception caught while reseting to remote head: ", e);
}
}
示例3
/**
* Evaluate the commit message for the merge unit.
*/
private void evaluteCommitMessage() {
final String localBranch = getLocalSourceBranch();
if (localBranch == null) {
return;
}
try {
final List<Ref> branchListResult = repo.branchList().call();
final boolean localBranchExists = branchListResult.stream()
.anyMatch(ref -> ref.getName().endsWith(localBranch));
CheckoutCommand branchCmd = repo.checkout().setName(localBranch);
if (!localBranchExists) {
branchCmd = branchCmd.setCreateBranch(true).setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
.setStartPoint(mergeUnit.getBranchSource());
}
branchCmd.call();
final ObjectId id = ObjectId.fromString(mergeUnit.getRevisionInfo());
commitMessage = repo.log().add(id).call().iterator().next().getFullMessage();
/*
* Remove merge processor commit information, if the commmit is done by merge
* processor e.g. MP [29c64cf540d8f3ea116c3683eade862c3d996dfb] V1.1 -> master:
* (2018-03-06 12:17:22)
*/
commitMessage = commitMessage.replaceAll("MP \\[[A-Za-z0-9]*\\] .* -> .*: \\(.*\\) ", ""); //$NON-NLS-1$ //$NON-NLS-2$
} catch (GitAPIException | MissingObjectException | IncorrectObjectTypeException e) {
exception = new MergeUnitException(String.format("Could not checkout branch '%s'", localBranch), e); //$NON-NLS-1$
}
}
示例4
/**
* Create a local branch for remote tracking if it doesn't exist already.
*/
protected void createBranchIfNeeded(String branch) throws Exception {
if (localRepo.findRef(branch) == null) {
git.branchCreate()
.setName(branch)
.setUpstreamMode(SetupUpstreamMode.TRACK)
.setStartPoint("origin/" + branch)
.call();
}
}
示例5
private void trackBranch(Git git, CheckoutCommand checkout, String label) {
checkout.setCreateBranch(true).setName(label)
.setUpstreamMode(SetupUpstreamMode.TRACK)
.setStartPoint("origin/" + label);
}