List of usage examples for org.eclipse.jgit.lib Repository hasObject
@Deprecated public boolean hasObject(AnyObjectId objectId)
From source file:com.madgag.agit.matchers.HasGitObjectMatcher.java
License:Open Source License
@Override public boolean matchesSafely(Repository repository) { return repository.hasObject(objectId); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitCollectChangesPolicy.java
License:Apache License
private List<RevCommit> getCommits(@NotNull RepositoryStateData state, @NotNull Repository r, @NotNull RevWalk walk) throws IOException { List<RevCommit> revisions = new ArrayList<RevCommit>(); for (String revision : state.getBranchRevisions().values()) { ObjectId id = ObjectId.fromString(GitUtils.versionRevision(revision)); if (r.hasObject(id)) { RevObject obj = walk.parseAny(id); if (obj.getType() == Constants.OBJ_COMMIT) revisions.add((RevCommit) obj); }//from w ww.j a v a 2 s.co m } return revisions; }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.AgentVcsSupportTest.java
License:Apache License
@TestFor(issues = "TW-20165") public void push_with_local_mirrors_should_go_to_original_repository() throws Exception { AgentRunningBuild build = createRunningBuild(true); myVcsSupport.updateSources(myRoot, CheckoutRules.DEFAULT, GitUtils.makeVersion("465ad9f630e451b9f2b782ffb09804c6a98c4bb9", 1289483394000L), myCheckoutDir, build, false);/*from www . ja va 2 s . com*/ final File fileToChange = new File(myCheckoutDir, "file"); FileUtil.writeToFile(fileToChange, "text".getBytes()); Repository r = new RepositoryBuilder().setWorkTree(myCheckoutDir).build(); Git git = new Git(r); git.add().addFilepattern("file").call(); RevCommit commitDuringTheBuild = git.commit().setMessage("Commit during the build").call(); new PushCommand().run(getGitPath(), myCheckoutDir.getAbsolutePath());//push using native git, seems like jgit doesn't respect url.insteadOf settings Repository remote = new RepositoryBuilder().setGitDir(myMainRepo).build(); assertTrue("Push didn't go to the remote repository", remote.hasObject(commitDuringTheBuild)); }
From source file:jetbrains.buildServer.buildTriggers.vcs.git.tests.CollectChangesTest.java
License:Apache License
@TestFor(issues = "TW-43643") public void should_fetch_all_refs_when_commit_not_found() throws Exception { File repo = getRemoteRepositoryDir("TW-43643-1"); VcsRoot rootBranch1 = vcsRoot().withFetchUrl(repo).withBranch("branch1").build(); //clone repository on server RepositoryStateData s1 = RepositoryStateData.createVersionState("refs/heads/branch1", "b56875abce7e1488991223c29ed14cc26ec4b786"); RepositoryStateData s2 = RepositoryStateData.createVersionState("refs/heads/branch1", "22d8a6d243915cb9f878a0ef95a0999bb5f56715"); git().getCollectChangesPolicy().collectChanges(rootBranch1, s1, s2, CheckoutRules.DEFAULT); //update remote repository: branch1 is removed, branch2 is added File updatedRepo = getRemoteRepositoryDir("TW-43643-2"); FileUtil.delete(repo);/* ww w .jav a 2 s .com*/ repo.mkdirs(); FileUtil.copyDir(updatedRepo, repo); //delete clone on server to emulate git gc which prunes the '22d8a6d243915cb9f878a0ef95a0999bb5f56715' //commit unreachable from branches (tags are not fetched by default) MirrorManagerImpl mirrors = new MirrorManagerImpl(myConfig.build(), new HashCalculatorImpl()); File cloneOnServer = mirrors.getMirrorDir(repo.getCanonicalPath()); FileUtil.delete(cloneOnServer); //collect changes in master to clone the repository VcsRoot rootMaster = vcsRoot().withFetchUrl(repo).withBranch("master").build(); RepositoryStateData s3 = RepositoryStateData.createVersionState("refs/heads/master", "b56875abce7e1488991223c29ed14cc26ec4b786"); RepositoryStateData s4 = RepositoryStateData.createVersionState("refs/heads/master", "ea5bd5a6e37ac1592fb1c4864bb38cbce95fa93a"); git().getCollectChangesPolicy().collectChanges(rootMaster, s3, s4, CheckoutRules.DEFAULT); //clone on the server doesn't contain the commit branch1 was pointing to: Repository repository = new RepositoryBuilder().setGitDir(cloneOnServer).setBare().build(); then(repository.hasObject(ObjectId.fromString("22d8a6d243915cb9f878a0ef95a0999bb5f56715"))).isFalse(); //but we we collect changes between branch1 and branch2 we should fetch all //available refs, get the '22d8a6d243915cb9f878a0ef95a0999bb5f56715' reachable from tag //and report changes: VcsRoot rootBranch2 = vcsRoot().withFetchUrl(repo).withBranch("branch2").build(); RepositoryStateData s5 = RepositoryStateData.createVersionState("refs/heads/branch2", "bc979d0e5bc0e6030a9db27c75004e6eb8cdb961"); List<ModificationData> changes = git().getCollectChangesPolicy().collectChanges(rootBranch1, s2, rootBranch2, s5, CheckoutRules.DEFAULT); then(changes).extracting("version").containsExactly("bc979d0e5bc0e6030a9db27c75004e6eb8cdb961"); }
From source file:svnserver.repository.git.GitSubmodules.java
License:GNU General Public License
@Nullable public GitObject<RevCommit> findCommit(@NotNull ObjectId objectId) throws IOException { for (Repository repo : repositories) { if (repo.hasObject(objectId)) { return new GitObject<>(repo, new RevWalk(repo).parseCommit(objectId)); }//from w w w .jav a 2s .co m } return null; }