public Properties getStatistics() throws GitAPIException { // not inside a doLocked/synchronized block because we don't want to block the server status service. return git.gc().getStatistics(); }
private void addNode(File nodeDir, File nodeFile, String fileContents) throws IOException, GitAPIException { createNewFile(nodeDir, nodeFile, fileContents); // add, commit, push node this.gitForPush.add().addFilepattern(formNodeFilePath(nodeDir.getName(), nodeFile.getName())).call(); this.gitForPush.commit().setMessage("Node commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }
public void run() throws Exception { addCommand.addFilepattern(CRUISE_CONFIG_XML).call(); git.commit().setAuthor(rev.getUsername(), STUDIOS_PRODUCT).setMessage(rev.getComment()).call(); } });
@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)); }
public Long commitCountOnMaster() throws GitAPIException, IncorrectObjectTypeException, MissingObjectException { // not inside a doLocked/synchronized block because we don't want to block the server status service. // we do a `git branch` because we switch branches as part of normal git operations, // and we don't care about number of commits on those branches. List<Ref> branches = git.branchList().call(); for (Ref branch : branches) { if (branch.getName().equals("refs/heads/master")) { Iterable<RevCommit> commits = git.log().add(branch.getObjectId()).call(); long count = 0; for (RevCommit commit : commits) { count++; } return count; } } return Long.valueOf(-1); } }
@Signature public void __construct(File directory, boolean create) throws IOException, GitAPIException { try { __wrappedObject = Git.open(directory, FS.DETECTED); } catch (RepositoryNotFoundException e) { if (create) { Git.init().setBare(false).setDirectory(directory).call(); __wrappedObject = Git.open(directory, FS.DETECTED); } } }
private void trackBranch(Git git, CheckoutCommand checkout, String label) { checkout.setCreateBranch(true).setName(label) .setUpstreamMode(SetupUpstreamMode.TRACK) .setStartPoint("origin/" + label); }
void createBranch(String branchName, RevCommit revCommit) throws GitAPIException { try { git.branchCreate().setName(branchName).setStartPoint(revCommit).call(); } catch (GitAPIException e) { LOGGER.error("[CONFIG_MERGE] Failed to create branch {} at revision {}", branchName, revCommit.getId(), e); throw e; } }
private List<Ref> getAllBranches() throws GitAPIException { return configRepo.git().branchList().setListMode(ListBranchCommand.ListMode.ALL).call(); } }
void deleteBranch(String branchName) throws GitAPIException { try { git.branchDelete().setBranchNames(branchName).setForce(true).call(); } catch (GitAPIException e) { LOGGER.error("[CONFIG_MERGE] Failed to delete branch {}", branchName, e); throw e; } }
public CloneCommand getCloneCommandByCloneRepository() { CloneCommand command = Git.cloneRepository(); return command; } }
@Signature public void rm(String filePattern, boolean cached) throws GitAPIException { getWrappedObject() .rm() .addFilepattern(filePattern) .setCached(cached) .call(); }
@Signature public List<String> branchDelete(String[] names, boolean force) throws GitAPIException { DeleteBranchCommand command = getWrappedObject().branchDelete(); command.setBranchNames(names); return command.call(); }
public Git getGitByOpen(File file) throws IOException { Git git = Git.open(file); return git; }
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException { createNewFile(edgeDir, edgeFile, fileContents); // add, commit, push edge this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call(); this.gitForPush.commit().setMessage("Edge commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); }