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 File: GitService.java    From Refactoring-Bot with 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 File: BranchOperator.java    From verigreen with 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 File: GitCloner.java    From smart-testing with 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 File: JGitEnvironmentRepositoryConcurrencyTests.java    From spring-cloud-config with 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 File: TagBasedVersionFactoryTest.java    From gradle-gitsemver with 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 File: MavenIntegrationTest.java    From gitflow-incremental-builder with 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 File: GitControl.java    From juneau with 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();
}