org.eclipse.jgit.api.errors.RefAlreadyExistsException Java Examples

The following examples show how to use org.eclipse.jgit.api.errors.RefAlreadyExistsException. 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 Project: Refactoring-Bot   Author: Refactoring-Bot   File: GitService.java    License: MIT License 6 votes vote down vote up
/**
 * This method creates a new branch.
 * 
 * @param gitConfig
 * @param branchName
 * @param origin
 * @throws BotRefactoringException
 * @throws GitWorkflowException
 */
public void createBranch(GitConfiguration gitConfig, String branchName, String newBranch, String origin)
		throws BotRefactoringException, GitWorkflowException {
	try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) {
		// Try to create new branch
		@SuppressWarnings("unused")
		Ref ref = git.checkout().setCreateBranch(true).setName(newBranch)
				.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
				.setStartPoint(origin + "/" + branchName).call();
		// Pull data
		git.pull();
		// If branch already exists
	} catch (RefAlreadyExistsException r) {
		logger.error(r.getMessage(), r);
		throw new BotRefactoringException(
				"Issue was already refactored in the past! The bot database might have been resetted but not the fork itself.");
	} catch (Exception e) {
		logger.error(e.getMessage(), e);
		throw new GitWorkflowException("Branch with the name " + "'" + newBranch + "' could not be created!");
	}
}
 
Example #2
Source Project: verigreen   Author: Verigreen   File: BranchOperator.java    License: Apache License 2.0 6 votes vote down vote up
private void submitBranch(
        String newrev,
        String ref,
        JGitOperator jgitOp,
        RevCommit commitMetadata,
        String shortId) {
    String vgBranchName = VerigreenUtils.getVerigreenBranchName(shortId);
    
    try
    {
   		jgitOp.createBranch(newrev, vgBranchName); 
    }
    catch(RuntimeException e){
   		if (!(e.getCause() instanceof RefAlreadyExistsException))
   		{
   			throw e;
   		}
    }
    BranchDescriptor branchData = new BranchDescriptor();
    branchData.setCommitter(commitMetadata.getCommitterIdent().getEmailAddress());
    branchData.setProtectedBranch(ref);
    branchData.setNewBranch(vgBranchName);
    branchData.setCommitId(shortId);
    
    new RestClientImpl().post(GitHookApi.getCreateBranchRequest(branchData));
}
 
Example #3
Source Project: smart-testing   Author: arquillian   File: GitCloner.java    License: Apache License 2.0 5 votes vote down vote up
private void checkoutAllBranches(Repository repository) throws GitAPIException {
    final Git git = Git.wrap(repository);
    for (final Ref ref : git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call()) {
        final String refName = ref.getName();
        final String branchName = refName.substring(refName.lastIndexOf('/') + 1);
        try {
            git.checkout().setCreateBranch(true).setName(branchName).setStartPoint("origin/" + branchName).call();
        } catch (RefAlreadyExistsException e) {
            LOGGER.warning("Already exists, so ignoring " + e.getMessage());
        }
    }
}
 
Example #4
Source Project: spring-cloud-config   Author: spring-cloud   File: JGitEnvironmentRepositoryConcurrencyTests.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Ref call() throws GitAPIException, RefAlreadyExistsException,
		RefNotFoundException, InvalidRefNameException, CheckoutConflictException {
	try {
		Thread.sleep(250);
	}
	catch (InterruptedException e) {
		e.printStackTrace();
	}
	return super.call();
}
 
Example #5
Source Project: gradle-gitsemver   Author: palantir   File: TagBasedVersionFactoryTest.java    License: Apache License 2.0 5 votes vote down vote up
private static Git initializeGitFlow(Repository repo)
        throws RefAlreadyExistsException, RefNotFoundException,
        InvalidRefNameException, GitAPIException {
    Git git = new Git(repo);
    git.commit().setCommitter(COMMITTER).setMessage("initial commit").call();
    return git;
}
 
Example #6
Source Project: gitflow-incremental-builder   Author: vackosar   File: MavenIntegrationTest.java    License: MIT License 4 votes vote down vote up
private void checkoutDevelop() throws GitAPIException, CheckoutConflictException, RefAlreadyExistsException,
        RefNotFoundException, InvalidRefNameException {
    Git git = localRepoMock.getGit();
    git.reset().setMode(ResetCommand.ResetType.HARD).setRef("HEAD").call();
    git.checkout().setName("develop").call();
}
 
Example #7
Source Project: juneau   Author: apache   File: GitControl.java    License: Apache License 2.0 4 votes vote down vote up
public void branch(String name) throws RefAlreadyExistsException, RefNotFoundException, InvalidRefNameException,
		CheckoutConflictException, GitAPIException {
	git.checkout().setName(name).setStartPoint("origin/".concat(name)).call();
}