void cleanAndResetToMaster() throws IOException { try { git.reset().setMode(ResetCommand.ResetType.HARD).call(); checkout("master"); deleteBranch(BRANCH_AT_REVISION); deleteBranch(BRANCH_AT_HEAD); } catch (Exception e) { String currentBranch = git.getRepository().getBranch(); LOGGER.error("Error while trying to clean up config repository, CurrentBranch: {} \n : \n Message: {} \n StackTrace: {}", currentBranch, e.getMessage(), e.getStackTrace(), e); throw new RuntimeException(e); } }
@Signature public String getBranch() throws IOException { return getWrappedObject().getRepository().getBranch(); }
@Test public void shouldSwitchToMasterAndDeleteTempBranches() throws Exception, GitAPIException { configRepo.checkin(goConfigRevision("v1", "md5-1")); configRepo.createBranch(ConfigRepository.BRANCH_AT_HEAD, configRepo.getCurrentRevCommit()); configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit()); configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call(); assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION)); assertThat(configRepo.git().branchList().call().size(), is(3)); configRepo.cleanAndResetToMaster(); assertThat(configRepo.git().getRepository().getBranch(), is("master")); assertThat(configRepo.git().branchList().call().size(), is(1)); }
@Test public void shouldCleanAndResetToMasterDuringInitialization() throws Exception { configRepo.checkin(goConfigRevision("v1", "md5-1")); configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit()); configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call(); assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION)); new ConfigRepository(systemEnvironment).initialize(); assertThat(configRepo.git().getRepository().getBranch(), is("master")); assertThat(configRepo.git().branchList().call().size(), is(1)); }
@Test public void shouldCleanAndResetToMasterOnceMergeFlowIsComplete() throws Exception { String original = "first\nsecond\n"; String changeOnBranch = "first\nsecond\nthird\n"; String changeOnMaster = "1st\nsecond\n"; String oldMd5 = "md5-1"; configRepo.checkin(goConfigRevision(original, oldMd5)); configRepo.checkin(goConfigRevision(changeOnMaster, "md5-2")); configRepo.getConfigMergedWithLatestRevision(goConfigRevision(changeOnBranch, "md5-3"), oldMd5); assertThat(configRepo.git().getRepository().getBranch(), is("master")); assertThat(configRepo.git().branchList().call().size(), is(1)); }
@Override public String getBranchName() throws GitCommitIdExecutionException { try { return git.getBranch(); } catch (IOException e) { throw new GitCommitIdExecutionException(e); } }
public GitTool() { File gitWorkDir = new File("."); try { Git git = Git.open(gitWorkDir); Iterable<RevCommit> commits = git.log().all().call(); Repository repo = git.getRepository(); branch = repo.getBranch(); RevCommit latestCommit = commits.iterator().next(); name = latestCommit.getName(); message = latestCommit.getFullMessage(); } catch (Throwable e) { name = ""; message = ""; branch = ""; } }
/** * Get merge configuration for the current branch of the repository * * @param repo * a {@link org.eclipse.jgit.lib.Repository} object. * @return merge configuration for the current branch of the repository */ public static MergeConfig getConfigForCurrentBranch(Repository repo) { try { String branch = repo.getBranch(); if (branch != null) return repo.getConfig().get(getParser(branch)); } catch (IOException e) { // ignore } // use defaults if branch can't be determined return new MergeConfig(); }
private String getBranch() { try { return repository.getBranch(); } catch (IOException e) { return null; } }
public String currentBranch(Git git) { try { return git.getRepository().getBranch(); } catch (IOException e) { LOG.warn("Failed to get the current branch due: " + e.getMessage() + ". This exception is ignored.", e); return null; } }
private String getCurrentBranch(Repository repository) throws ExecutionException { try { return repository.getBranch(); } catch (IOException e) { throw new ExecutionException(UIText.RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage, e); } } }
@Override public String getCurrentBranchName(final Git repo) throws IOException { return repo.getRepository().getBranch(); }
/** * Returns the name of the current branch in the repository. * * @return - the name of the branch. * @throws IOException - failed */ public String currentBranchName() throws IOException { return git.getRepository().getBranch(); }
private void fillValues(final Repository repository) throws IOException { gitDir.setText(repository.getDirectory().getAbsolutePath()); branch.setText(repository.getBranch()); workDir.setText(repository.getWorkTree().getAbsolutePath()); state.setText(repository.getRepositoryState().getDescription()); }
private String currentBranch(File projectDir) { Git git = this.gitFactory.open(projectDir); try { return git.getRepository().getBranch(); } catch (IOException e) { throw new IllegalStateException(e); } finally { git.close(); } }
public void init(String jiraProjectId, Logger logger) throws IOException { // Open an existing repository existingRepo = new FileRepositoryBuilder() .setGitDir(new File(".git")) .build(); logger.quiet("Current branch " + existingRepo.getBranch()); this.logger = logger; this.smartCommitPattern = Pattern.compile(".*(" + jiraProjectId + "-\\d*).*"); }
@Test public void attachHeadToNewBranch_theRepositoryHeadShouldBecomeTheSpecifiedBranch() throws IOException { RepositoryUtils.attachRepositoryHead(repo, "refs/heads/new_branch"); assertEquals("new_branch", repo.getBranch()); }
@Override public List<String> getLogForBranch(final Git repo, String branchName) throws GitAPIException, IOException { String oldBranch = repo.getRepository().getBranch(); repo.checkout().setName(branchName).call(); List<String> results = getLogForCurrentBranch(repo); repo.checkout().setName(oldBranch).call(); return results; }
@Test public void deleteOrphanBranch_orphanBranchShouldNotBeAffected() throws IOException { RepositoryUtils.setRepositoryHead(repo, "orphan_branch"); BranchUtils.deleteBranch("orphan_branch", repo); assertEquals("orphan_branch", repo.getBranch()); }
@Test public void setHeadToCommit_theRepositoryHeadShouldDetachToTheSpecifiedCommit() throws IOException { writeSomethingToCache(); AnyObjectId commitId = commitToMaster(); RepositoryUtils.setRepositoryHead(repo, commitId.getName()); assertEquals(commitId.getName(), repo.getBranch()); }