org.eclipse.jgit.lib.AnyObjectId Java Examples
The following examples show how to use
org.eclipse.jgit.lib.AnyObjectId.
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: GfsMerge.java From ParallelGit with Apache License 2.0 | 6 votes |
@Nonnull private Result updateFileSystemStatus(GfsStatusProvider.Update update, Merger merger) throws IOException { AnyObjectId treeId = merger.getResultTreeId(); checkout(gfs, treeId); RevCommit newCommit = null; if(commit && !squash) { prepareCommitter(); newCommit = createCommit(message, treeId, committer, committer, Arrays.asList(headCommit, sourceHeadCommit), repo); BranchUtils.merge(branch, newCommit, sourceRef, "Merge made by " + strategy.getName() + ".", repo); update.commit(newCommit); } if(!commit) { update.mergeNote(MergeNote.mergeNoCommit(sourceHeadCommit, message)); return Result.mergedNotCommitted(); } if(squash) { update.mergeNote(MergeNote.mergeSquash(message)); return Result.mergedSquashed(); } return Result.merged(newCommit); }
Example #2
Source File: DefaultIndexManager.java From onedev with MIT License | 6 votes |
private String getCommitIndexVersion(final IndexSearcher searcher, AnyObjectId commitId) throws IOException { final AtomicReference<String> indexVersion = new AtomicReference<>(null); searcher.search(COMMIT_HASH.query(commitId.getName()), new SimpleCollector() { private int docBase; @Override public void collect(int doc) throws IOException { indexVersion.set(searcher.doc(docBase+doc).get(COMMIT_INDEX_VERSION.name())); } @Override protected void doSetNextReader(LeafReaderContext context) throws IOException { docBase = context.docBase; } @Override public boolean needsScores() { return false; } }); return indexVersion.get(); }
Example #3
Source File: RevWalk.java From onedev with MIT License | 6 votes |
/** * Locate a reference to a tree. * <p> * This method only returns successfully if the tree object exists, is * verified to be a tree. * * @param id * name of the tree object, or a commit or annotated tag that may * reference a tree. * @return reference to the tree object. Never null. * @throws org.eclipse.jgit.errors.MissingObjectException * the supplied tree does not exist. * @throws org.eclipse.jgit.errors.IncorrectObjectTypeException * the supplied id is not a tree, a commit or an annotated tag. * @throws java.io.IOException * a pack file or loose object could not be read. */ @NonNull public RevTree parseTree(AnyObjectId id) throws MissingObjectException, IncorrectObjectTypeException, IOException { RevObject c = peel(parseAny(id)); final RevTree t; if (c instanceof RevCommit) t = ((RevCommit) c).getTree(); else if (!(c instanceof RevTree)) throw new IncorrectObjectTypeException(id.toObjectId(), Constants.TYPE_TREE); else t = (RevTree) c; parseHeaders(t); return t; }
Example #4
Source File: GitUtils.java From jgitver with Apache License 2.0 | 6 votes |
/** * Computes inside the given repository the distance between the provided object and the root of the repository. * @param repository the git repository * @param objectId the id of the start of the distance computation * @return the computed distance */ public static int distanceToRoot(Repository repository, AnyObjectId objectId) { try (RootCommit.RootWalk rootWalk = new RootCommit.RootWalk(repository)) { RevCommit commit = repository.parseCommit(objectId); rootWalk.markStart(commit); Iterator<RevCommit> rootsIT = rootWalk.iterator(); if (!rootsIT.hasNext()) { throw new IllegalStateException("could not find at least one root commit in the repository"); } RevCommit foundRoot = rootsIT.next(); return DistanceCalculator.create(objectId, repository).distanceTo(foundRoot.getId()).get(); } catch (IOException e) { throw new IllegalStateException("failure retrieving root commit in the repository"); } }
Example #5
Source File: RevWalk.java From onedev with MIT License | 6 votes |
/** * Locate a reference to any object without loading it. * <p> * The object may or may not exist in the repository. It is impossible to * tell from this method's return value. * * @param id * name of the object. * @param type * type of the object. Must be a valid Git object type. * @return reference to the object. Never null. */ @NonNull public RevObject lookupAny(AnyObjectId id, int type) { RevObject r = objects.get(id); if (r == null) { switch (type) { case Constants.OBJ_COMMIT: r = createCommit(id); break; case Constants.OBJ_TREE: r = new RevTree(id); break; case Constants.OBJ_BLOB: r = new RevBlob(id); break; case Constants.OBJ_TAG: r = new RevTag(id); break; default: throw new IllegalArgumentException(MessageFormat.format( JGitText.get().invalidGitType, Integer.valueOf(type))); } objects.add(r); } return r; }
Example #6
Source File: GfsConfigurationTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void buildWithRevision() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); GitFileSystem gfs = Gfs.newFileSystem(commit, repo); assertEquals(commit, gfs.getStatusProvider().commit()); }
Example #7
Source File: GfsCommitAfterMergeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { initRepository(); writeSomethingToCache(); AnyObjectId base = commit(); writeToCache("/test_file.txt", "OUR VERSION"); commitToBranch(OURS, base); clearCache(); writeSomethingToCache(); commitToBranch(THEIRS, base); writeSomethingToCache(); commitToBranch(THEIRS); gfs = newFileSystem(OURS, repo); }
Example #8
Source File: GfsDefaultCheckoutTreeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test(expected = GfsCheckoutConflictException.class) public void case12_headHasFile_targetHasDirectory_worktreeHasFile_shouldThrowGfsCheckoutConflictException() throws IOException { initGitFileSystem("/test_target"); clearWorktreeAndWrite("/test_target/some_file.txt", someBytes()); AnyObjectId target = createTreeWithFile("/test_target", someBytes()); new GfsDefaultCheckout(gfs).checkout(target); }
Example #9
Source File: GitFileUtilsOpenFileTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void openFile_theResultInputStreamShouldProvideTheDataOfTheFile() throws IOException { byte[] expected = someBytes(); writeToCache("/test_file.txt", expected); AnyObjectId commit = commitToMaster(); byte[] actual = new byte[expected.length]; try(InputStream stream = GitFileUtils.openFile("/test_file.txt", commit.getName(), repo)) { assertEquals(expected.length, stream.read(actual)); } assertArrayEquals(expected, actual); }
Example #10
Source File: GfsDefaultCheckoutTreeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test(expected = GfsCheckoutConflictException.class) public void case15_headHasDirectory_targetAndWorktreeHaveDifferentFiles_shouldThrowGfsCheckoutConflictException() throws IOException { initGitFileSystem("/test_target/some_file.txt"); clearWorktreeAndWrite("/test_target", someBytes()); AnyObjectId target = createTreeWithFile("/test_target", someBytes()); new GfsDefaultCheckout(gfs).checkout(target); }
Example #11
Source File: GfsConfigurationTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void buildWithRevisionString() throws IOException { writeSomethingToCache(); AnyObjectId commit = commitToMaster(); GitFileSystem gfs = Gfs.newFileSystem(commit.getName(), repo); assertEquals(commit, gfs.getStatusProvider().commit()); }
Example #12
Source File: BranchUtilsDeleteBranchTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void deleteBranchWhenBranchIsTheRepositoryHead_repositoryHeadShouldDetachToTheBranchHeadCommit() throws IOException { writeSomethingToCache(); AnyObjectId headCommit = commitToBranch("test_branch"); RepositoryUtils.setRepositoryHead(repo, "test_branch"); BranchUtils.deleteBranch("refs/heads/test_branch", repo); assertEquals(headCommit.name(), repo.getBranch()); }
Example #13
Source File: GfsMergeAutoMergeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { initRepository(); writeToCache("/test_file.txt", "a\nb\nc\nd\ne"); AnyObjectId base = commit(); writeToCache("/test_file.txt", "a\nB\nc\nd\ne"); commitToBranch(OURS, base); writeToCache("/test_file.txt", "a\nb\nc\nD\nd\ne"); commitToBranch(THEIRS, base); gfs = newFileSystem(OURS, repo); }
Example #14
Source File: GfsDefaultCheckoutTreeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void case5_headEqualTarget_targetNotEqualWorktree_worktreeFileShouldRemainTheSame() throws IOException { initRepository(); byte[] someBytes = someBytes(); writeToCache("/test_file.txt", someBytes); commitToMaster(); initGitFileSystem(); byte[] expected = someBytes(); clearWorktreeAndWrite("/test_file.txt", expected); AnyObjectId target = createTreeWithFile("/test_file.txt", someBytes); new GfsDefaultCheckout(gfs).checkout(target); assertArrayEquals(expected, Files.readAllBytes(gfs.getPath("/test_file.txt"))); }
Example #15
Source File: GitFileAttributeViewTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void whenEmptyChildrenDirectoriesIAreCreated_getObjectIdShouldReturnSameValue() throws IOException { initGitFileSystem("/dir/some_file.txt"); AnyObjectId original = objectId("/dir"); Files.createDirectories(gfs.getPath("/dir/empty_dir1/empty_dir2")); assertEquals(original, objectId("/dir")); }
Example #16
Source File: CommitUtilsGetCommitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void getCommitFromTagId_theResultShouldEqualToTheTaggedCommit() throws IOException { writeSomethingToCache(); AnyObjectId commitId = commitToMaster(); AnyObjectId tagId = TagUtils.tagCommit("test_tag", commitId, repo).getObjectId(); assertEquals(commitId, CommitUtils.getCommit(tagId, repo)); }
Example #17
Source File: BranchUtilsTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void getBranchHeadCommitTest() throws IOException { AnyObjectId firstCommit = initRepository(); assertEquals(firstCommit, BranchUtils.getHeadCommit(Constants.MASTER, repo)); writeToCache("a.txt"); String branchName = "second"; AnyObjectId branchCommit = commitToBranch(branchName, firstCommit); assertEquals(branchCommit, BranchUtils.getHeadCommit(branchName, repo)); }
Example #18
Source File: GfsMerge.java From ParallelGit with Apache License 2.0 | 5 votes |
private boolean tryCheckout(AnyObjectId tree) throws IOException { try { checkout(gfs, tree); } catch(GfsCheckoutConflictException e) { return false; } return true; }
Example #19
Source File: GfsDefaultCheckoutTreeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test(expected = GfsCheckoutConflictException.class) public void case12_headHasFile_targetHasDirectory_worktreeHasFile_shouldThrowGfsCheckoutConflictException() throws IOException { initGitFileSystem("/test_target"); clearWorktreeAndWrite("/test_target/some_file.txt", someBytes()); AnyObjectId target = createTreeWithFile("/test_target", someBytes()); new GfsDefaultCheckout(gfs).checkout(target); }
Example #20
Source File: GfsMerge.java From ParallelGit with Apache License 2.0 | 5 votes |
private boolean tryCheckout(AnyObjectId tree) throws IOException { try { checkout(gfs, tree); } catch(GfsCheckoutConflictException e) { return false; } return true; }
Example #21
Source File: GfsMergeConflictingMergeTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { initRepository(); writeToCache("/test_file.txt", "base stuff"); AnyObjectId base = commit(); writeToCache("/test_file.txt", "base stuff + some stuff"); commitToBranch(OURS, base); writeToCache("/test_file.txt", "base stuff + other stuff"); commitToBranch(THEIRS, base); gfs = newFileSystem(OURS, repo); }
Example #22
Source File: GitFileAttributeViewTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void whenEmptyChildrenDirectoriesIAreCreated_getObjectIdShouldReturnSameValue() throws IOException { initGitFileSystem("/dir/some_file.txt"); AnyObjectId original = objectId("/dir"); Files.createDirectories(gfs.getPath("/dir/empty_dir1/empty_dir2")); assertEquals(original, objectId("/dir")); }
Example #23
Source File: GfsMergeUpToDateTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Before public void setUp() throws Exception { initRepository(); AnyObjectId base = commit(); AnyObjectId theirs = commitToBranch(THEIRS, base); commitToBranch(OURS, theirs); gfs = Gfs.newFileSystem(OURS, repo); }
Example #24
Source File: CommitUtilsCreateCommitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void createCommitFromTree_theResultCommitRootTreeShouldBeTheSpecifiedTree() throws IOException { writeSomethingToCache(); AnyObjectId treeId = CacheUtils.writeTree(cache, repo); RevCommit commit = CommitUtils.createCommit(someCommitMessage(), treeId, null, repo); assertEquals(treeId, commit.getTree()); }
Example #25
Source File: BranchUtilsGetBranchHistoryTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void getBranchHistory_shouldReturnAllCommitsStartedFromTheHeadCommit() throws IOException { String branch = "test_branch"; AnyObjectId[] expected = new AnyObjectId[3]; writeSomethingToCache(); expected[2] = commitToBranch(branch); writeSomethingToCache(); expected[1] = commitToBranch(branch, expected[2]); writeSomethingToCache(); expected[0] = commitToBranch(branch, expected[1]); List<RevCommit> history = BranchUtils.getHistory(branch, repo); AnyObjectId[] actual = new AnyObjectId[3]; history.toArray(actual); assertArrayEquals(expected, actual); }
Example #26
Source File: BranchUtilsSetBranchHeadTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void amendBranchHead_branchHeadShouldBecomeTheSpecifiedCommit() throws IOException { writeSomethingToCache(); AnyObjectId amendedCommit = commit(branchHead.getParent(0)); BranchUtils.amendCommit(TEST_BRANCH, amendedCommit, repo); assertEquals(amendedCommit, getHeadCommit(TEST_BRANCH, repo)); }
Example #27
Source File: DiffHelper.java From diff-check with GNU Lesser General Public License v2.1 | 5 votes |
public static DiffEntry createAddDiffEntry(String path, AnyObjectId id) { try { return (DiffEntry) DIFF_ENTRY_ADD_METHOD.invoke(null, path, id); } catch (Exception e) { throw new RuntimeException(e); } }
Example #28
Source File: CacheUtilsCreateTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void createCacheFromTag_theResultCacheShouldContainTheFilesInTheTaggedCommit() throws IOException { writeToCache("/file1.txt"); writeToCache("/file2.txt"); AnyObjectId tagId = TagUtils.tagCommit("test_tag", commit(someCommitMessage(), null), repo).getObjectId(); DirCache cache = CacheUtils.forRevision(tagId, repo); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", cache)); }
Example #29
Source File: ThreeWayMerger.java From onedev with MIT License | 5 votes |
/** {@inheritDoc} */ @Override public boolean merge(AnyObjectId... tips) throws IOException { if (tips.length != 2) return false; return super.merge(tips); }
Example #30
Source File: Merger.java From onedev with MIT License | 5 votes |
/** * Merge together two or more tree-ish objects. * <p> * Any tree-ish may be supplied as inputs. Commits and/or tags pointing at * trees or commits may be passed as input objects. * * @since 3.5 * @param flush * whether to flush and close the underlying object inserter when * finished to store any content-merged blobs and virtual merged * bases; if false, callers are responsible for flushing. * @param tips * source trees to be combined together. The merge base is not * included in this set. * @return true if the merge was completed without conflicts; false if the * merge strategy cannot handle this merge or there were conflicts * preventing it from automatically resolving all paths. * @throws IncorrectObjectTypeException * one of the input objects is not a commit, but the strategy * requires it to be a commit. * @throws java.io.IOException * one or more sources could not be read, or outputs could not * be written to the Repository. */ public boolean merge(boolean flush, AnyObjectId... tips) throws IOException { sourceObjects = new RevObject[tips.length]; for (int i = 0; i < tips.length; i++) sourceObjects[i] = walk.parseAny(tips[i]); sourceCommits = new RevCommit[sourceObjects.length]; for (int i = 0; i < sourceObjects.length; i++) { try { sourceCommits[i] = walk.parseCommit(sourceObjects[i]); } catch (IncorrectObjectTypeException err) { sourceCommits[i] = null; } } sourceTrees = new RevTree[sourceObjects.length]; for (int i = 0; i < sourceObjects.length; i++) sourceTrees[i] = walk.parseTree(sourceObjects[i]); try { boolean ok = mergeImpl(); if (ok && flush) inserter.flush(); return ok; } finally { if (flush) inserter.close(); reader.close(); } }