throw new JGitInternalException(e.getMessage(), e); } catch (RefNotFoundException e) { throw new JGitInternalException(e.getMessage(), e);
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()); } } }
/** * 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!"); } }
throw new JGitInternalException(e.getMessage(), e); } catch (RefNotFoundException e) { throw new JGitInternalException(e.getMessage(), e);
throw new JGitInternalException(e.getMessage(), e); } catch (RefNotFoundException e) { throw new JGitInternalException(e.getMessage(), e);