org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode Java Examples

The following examples show how to use org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GitMergeUtil.java    From MergeProcessor with Apache License 2.0 6 votes vote down vote up
/**
 * {@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$
	}
}
 
Example #2
Source File: ResourcePackRepository.java    From I18nUpdateMod with MIT License 6 votes vote down vote up
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);
    }
}
 
Example #3
Source File: GitMergeUtil.java    From MergeProcessor with Apache License 2.0 5 votes vote down vote up
/**
 * 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$
	}
}
 
Example #4
Source File: VersionControlGit.java    From mdw with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
    }
}
 
Example #5
Source File: JGitEnvironmentRepository.java    From spring-cloud-config with Apache License 2.0 4 votes vote down vote up
private void trackBranch(Git git, CheckoutCommand checkout, String label) {
	checkout.setCreateBranch(true).setName(label)
			.setUpstreamMode(SetupUpstreamMode.TRACK)
			.setStartPoint("origin/" + label);
}