org.eclipse.jgit.dircache.DirCache Java Examples
The following examples show how to use
org.eclipse.jgit.dircache.DirCache.
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: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void checkoutCacheWithIgnoringSomeFile_theIgnoredFileShouldNotBeCheckedOut() throws IOException { initGitFileSystem("/some_existing_file.txt"); DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); builder.add(someEntry("/test_file1.txt")); builder.add(someEntry("/test_file2.txt")); builder.add(someEntry("/test_file3.txt")); builder.finish(); new GfsDefaultCheckout(gfs).ignoredFiles(singleton("/test_file2.txt")).checkout(cache); assertTrue(Files.exists(gfs.getPath("/test_file1.txt"))); assertFalse(Files.exists(gfs.getPath("/test_file2.txt"))); assertTrue(Files.exists(gfs.getPath("/test_file3.txt"))); }
Example #2
Source File: SubtreeMerger.java From git-merge-repos with Apache License 2.0 | 6 votes |
public ObjectId createMergeCommit(Map<SubtreeConfig, RevCommit> parentCommits, String message) throws IOException { PersonIdent latestIdent = getLatestPersonIdent(parentCommits.values()); DirCache treeDirCache = createTreeDirCache(parentCommits, message); List<? extends ObjectId> parentIds = new ArrayList<>(parentCommits.values()); try (ObjectInserter inserter = repository.newObjectInserter()) { ObjectId treeId = treeDirCache.writeTree(inserter); PersonIdent repositoryUser = new PersonIdent(repository); PersonIdent ident = new PersonIdent(repositoryUser, latestIdent.getWhen().getTime(), latestIdent.getTimeZoneOffset()); CommitBuilder commitBuilder = new CommitBuilder(); commitBuilder.setTreeId(treeId); commitBuilder.setAuthor(ident); commitBuilder.setCommitter(ident); commitBuilder.setMessage(message); commitBuilder.setParentIds(parentIds); ObjectId mergeCommit = inserter.insert(commitBuilder); inserter.flush(); return mergeCommit; } }
Example #3
Source File: AbstractGitTestCase.java From netbeans with Apache License 2.0 | 6 votes |
protected static void assertDirCacheEntry (Repository repository, File workDir, Collection<File> files) throws IOException { DirCache cache = repository.lockDirCache(); for (File f : files) { String relativePath = Utils.getRelativePath(workDir, f); DirCacheEntry e = cache.getEntry(relativePath); assertNotNull(e); assertEquals(relativePath, e.getPathString()); if (f.lastModified() != e.getLastModified()) { assertEquals((f.lastModified() / 1000) * 1000, (e.getLastModified() / 1000) * 1000); } try (InputStream in = new FileInputStream(f)) { assertEquals(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in)); } if (e.getLength() == 0 && f.length() != 0) { assertTrue(e.isSmudged()); } else { assertEquals(f.length(), e.getLength()); } } cache.unlock(); }
Example #4
Source File: GitManagerImpl.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 6 votes |
private DirCacheEntry[] findEntrys(Repository repository, String path) throws IOException { DirCache dirCache = repository.readDirCache(); int eIdx = dirCache.findEntry(path); if (eIdx < 0) { throw new GitInvalidPathException(format("%s is not found in git index", path)); } int lastIdx = dirCache.nextEntry(eIdx); final DirCacheEntry[] entries = new DirCacheEntry[lastIdx - eIdx]; for (int i=0; i<entries.length; i++) { entries[i] = dirCache.getEntry(eIdx + i); } return entries; }
Example #5
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void deleteFilesWithDirCacheEditorTest() { DirCache cache = setupCache("a/b/c1.txt", "a/b/c2.txt", "a/c3.txt", "a/c4.txt", "a/c5.txt", "a/c6.txt"); DirCacheEditor editor = cache.editor(); CacheUtils.deleteFile("a/b/c1.txt", editor); CacheUtils.deleteFile("a/c3.txt", editor); CacheUtils.deleteFile("a/c4.txt", editor); CacheUtils.deleteFile("a/c6.txt", editor); editor.finish(); assertEquals(2, cache.getEntryCount()); assertNull(cache.getEntry("a/b/c1.txt")); assertNotNull(cache.getEntry("a/b/c2.txt")); assertNotNull(cache.getEntry("a/c5.txt")); }
Example #6
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void deleteTreeTest() { DirCache cache = setupCache("a/b/c1.txt", "a/b/c2.txt", "a/c3.txt", "a/c4.txt", "a/c5.txt", "a/c6.txt"); CacheUtils.deleteDirectory("a/b", cache); assertEquals(4, cache.getEntryCount()); assertNull(cache.getEntry("a/b/c1.txt")); assertNull(cache.getEntry("a/b/c2.txt")); assertNotNull(cache.getEntry("a/c3.txt")); assertNotNull(cache.getEntry("a/c4.txt")); assertNotNull(cache.getEntry("a/c5.txt")); assertNotNull(cache.getEntry("a/c6.txt")); }
Example #7
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void deleteMultipleTreesTest() { DirCache cache = setupCache("a/b/c1.txt", "a/b/c2.txt", "a/d/c3.txt", "a/d/c4.txt", "a/c5.txt", "a/c6.txt"); DirCacheEditor editor = cache.editor(); CacheUtils.deleteDirectory("a/b", editor); CacheUtils.deleteDirectory("a/d", editor); editor.finish(); assertEquals(2, cache.getEntryCount()); assertNotNull(cache.getEntry("a/c5.txt")); assertNotNull(cache.getEntry("a/c6.txt")); }
Example #8
Source File: CheckoutTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testJGitCheckout () throws Exception { File file1 = new File(workDir, "file1"); write(file1, "blablablabla"); Git git = new Git(repository); org.eclipse.jgit.api.AddCommand cmd = git.add(); cmd.addFilepattern("file1"); cmd.call(); org.eclipse.jgit.api.CommitCommand commitCmd = git.commit(); commitCmd.setAuthor("author", "author@something"); commitCmd.setMessage("commit message"); commitCmd.call(); String commitId = git.log().call().iterator().next().getId().getName(); DirCache cache = repository.lockDirCache(); try { DirCacheCheckout checkout = new DirCacheCheckout(repository, null, cache, new RevWalk(repository).parseCommit(repository.resolve(commitId)).getTree()); checkout.checkout(); } finally { cache.unlock(); } }
Example #9
Source File: GitFlowGraphMonitorTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Test (dependsOnMethods = "testUpdateNode") public void testRemoveEdge() throws GitAPIException, IOException { // delete a config file edge1File.delete(); //Node1 has 1 edge before delete Set<FlowEdge> edgeSet = this.flowGraph.getEdges("node1"); Assert.assertEquals(edgeSet.size(), 1); // delete, commit, push DirCache ac = this.gitForPush.rm().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call(); RevCommit cc = this.gitForPush.commit().setMessage("Edge remove commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitFlowGraphMonitor.processGitConfigChanges(); //Check if edge1 has been deleted from the graph edgeSet = this.flowGraph.getEdges("node1"); Assert.assertTrue(edgeSet.size() == 0); }
Example #10
Source File: GitConfigMonitorTest.java From incubator-gobblin with Apache License 2.0 | 6 votes |
@Test(dependsOnMethods = "testUpdateConfig") public void testDeleteConfig() throws IOException, GitAPIException, URISyntaxException { // delete a config file testFlowFile.delete(); // flow catalog has 1 entry before the config is deleted Collection<Spec> specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 1); // add, commit, push DirCache ac = this.gitForPush.rm().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName())) .call(); RevCommit cc = this.gitForPush.commit().setMessage("Fourth commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.gitConfigMonitor.processGitConfigChanges(); specs = this.flowCatalog.getSpecs(); Assert.assertTrue(specs.size() == 0); }
Example #11
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void deleteMultipleTreesTest() { DirCache cache = setupCache("a/b/c1.txt", "a/b/c2.txt", "a/d/c3.txt", "a/d/c4.txt", "a/c5.txt", "a/c6.txt"); DirCacheEditor editor = cache.editor(); CacheUtils.deleteDirectory("a/b", editor); CacheUtils.deleteDirectory("a/d", editor); editor.finish(); assertEquals(2, cache.getEntryCount()); assertNotNull(cache.getEntry("a/c5.txt")); assertNotNull(cache.getEntry("a/c6.txt")); }
Example #12
Source File: CleanCommand.java From netbeans with Apache License 2.0 | 6 votes |
private void deleteIfUnversioned(DirCache cache, String path, WorkingTreeIterator f, Repository repository, TreeWalk treeWalk) throws IOException, NoWorkTreeException { if (cache.getEntry(path) == null && // not in index !f.isEntryIgnored() && // not ignored !Utils.isFromNested(f.getEntryFileMode().getBits())) { File file = new File(repository.getWorkTree().getAbsolutePath() + File.separator + path); if(file.isDirectory()) { String[] s = file.list(); if(s != null && s.length > 0) { // XXX is there no better way to find out if empty? // not empty return; } } file.delete(); listener.notifyFile(file, treeWalk.getPathString()); } }
Example #13
Source File: SubtreeMerger.java From git-merge-repos with Apache License 2.0 | 6 votes |
private DirCache createTreeDirCache(Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage) throws IOException { try (TreeWalk treeWalk = new TreeWalk(repository)) { treeWalk.setRecursive(true); addTrees(parentCommits, treeWalk); DirCacheBuilder builder = DirCache.newInCore().builder(); while (treeWalk.next()) { AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage); if (iterator == null) { throw new IllegalStateException( "Tree walker did not return a single tree (should not happen): " + treeWalk.getPathString()); } byte[] path = Arrays.copyOf(iterator.getEntryPathBuffer(), iterator.getEntryPathLength()); DirCacheEntry entry = new DirCacheEntry(path); entry.setFileMode(iterator.getEntryFileMode()); entry.setObjectId(iterator.getEntryObjectId()); builder.add(entry); } builder.finish(); return builder.getDirCache(); } }
Example #14
Source File: GitManagerImpl.java From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License | 6 votes |
private AbstractTreeIterator prepareTreeParser(Repository repository, String ref) throws IOException { if ("~~staged~~".equals(ref)) { return new DirCacheIterator(DirCache.read(repository)); } else if ("~~unstaged~~".equals(ref)) { return new FileTreeIterator(repository); } try (RevWalk walk = new RevWalk(repository)) { ObjectId commitObjectId = repository.resolve(ref); if (commitObjectId == null) { throw new GitInvalidRefException(format("invalid git ref %s", ref)); } log.debug("ref: {}, commit id: {}", ref, commitObjectId.toString()); RevCommit commit = walk.parseCommit(commitObjectId); RevTree tree = walk.parseTree(commit.getTree().getId()); CanonicalTreeParser treeParser = new CanonicalTreeParser(); try (ObjectReader objectReader = repository.newObjectReader()) { treeParser.reset(objectReader, tree.getId()); } return treeParser; } }
Example #15
Source File: OldGitNotebookRepo.java From zeppelin with Apache License 2.0 | 6 votes |
@Override public Revision checkpoint(String pattern, String commitMessage, AuthenticationInfo subject) { Revision revision = Revision.EMPTY; try { List<DiffEntry> gitDiff = git.diff().call(); if (!gitDiff.isEmpty()) { LOG.debug("Changes found for pattern '{}': {}", pattern, gitDiff); DirCache added = git.add().addFilepattern(pattern).call(); LOG.debug("{} changes are about to be commited", added.getEntryCount()); RevCommit commit = git.commit().setMessage(commitMessage).call(); revision = new Revision(commit.getName(), commit.getShortMessage(), commit.getCommitTime()); } else { LOG.debug("No changes found {}", pattern); } } catch (GitAPIException e) { LOG.error("Failed to add+commit {} to Git", pattern, e); } return revision; }
Example #16
Source File: GitNotebookRepo.java From zeppelin with Apache License 2.0 | 6 votes |
@Override public Revision checkpoint(String noteId, String notePath, String commitMessage, AuthenticationInfo subject) throws IOException { String noteFileName = buildNoteFileName(noteId, notePath); Revision revision = Revision.EMPTY; try { List<DiffEntry> gitDiff = git.diff().call(); boolean modified = gitDiff.parallelStream().anyMatch(diffEntry -> diffEntry.getNewPath().equals(noteFileName)); if (modified) { LOGGER.debug("Changes found for pattern '{}': {}", noteFileName, gitDiff); DirCache added = git.add().addFilepattern(noteFileName).call(); LOGGER.debug("{} changes are about to be commited", added.getEntryCount()); RevCommit commit = git.commit().setMessage(commitMessage).call(); revision = new Revision(commit.getName(), commit.getShortMessage(), commit.getCommitTime()); } else { LOGGER.debug("No changes found {}", noteFileName); } } catch (GitAPIException e) { LOGGER.error("Failed to add+commit {} to Git", noteFileName, e); } return revision; }
Example #17
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void deleteFilesWithDirCacheEditorTest() { DirCache cache = setupCache("a/b/c1.txt", "a/b/c2.txt", "a/c3.txt", "a/c4.txt", "a/c5.txt", "a/c6.txt"); DirCacheEditor editor = cache.editor(); CacheUtils.deleteFile("a/b/c1.txt", editor); CacheUtils.deleteFile("a/c3.txt", editor); CacheUtils.deleteFile("a/c4.txt", editor); CacheUtils.deleteFile("a/c6.txt", editor); editor.finish(); assertEquals(2, cache.getEntryCount()); assertNull(cache.getEntry("a/b/c1.txt")); assertNotNull(cache.getEntry("a/b/c2.txt")); assertNotNull(cache.getEntry("a/c5.txt")); }
Example #18
Source File: ResolveMerger.java From onedev with MIT License | 6 votes |
/** * Reverts the worktree after an unsuccessful merge. We know that for all * modified files the old content was in the old index and the index * contained only stage 0. In case if inCore operation just clear the * history of modified files. * * @throws java.io.IOException * @throws org.eclipse.jgit.errors.CorruptObjectException * @throws org.eclipse.jgit.errors.NoWorkTreeException * @since 3.4 */ protected void cleanUp() throws NoWorkTreeException, CorruptObjectException, IOException { if (inCore) { modifiedFiles.clear(); return; } DirCache dc = nonNullRepo().readDirCache(); Iterator<String> mpathsIt=modifiedFiles.iterator(); while(mpathsIt.hasNext()) { String mpath = mpathsIt.next(); DirCacheEntry entry = dc.getEntry(mpath); if (entry != null) { DirCacheCheckout.checkoutEntry(db, entry, reader, false, checkoutMetadata.get(mpath)); } mpathsIt.remove(); } }
Example #19
Source File: CheckoutIndexCommand.java From netbeans with Apache License 2.0 | 6 votes |
@Override protected void run() throws GitException { Repository repository = getRepository(); DirCache cache = null; try { // cache must be locked because checkout index may modify its entries cache = repository.lockDirCache(); DirCacheBuilder builder = cache.builder(); if (cache.getEntryCount() > 0) { builder.keep(0, cache.getEntryCount()); } builder.finish(); new CheckoutIndex(repository, cache, roots, recursively, listener, monitor, true).checkout(); // cache must be saved to disk because checkout index may modify its entries builder.commit(); } catch (IOException ex) { throw new GitException(ex); } finally { if (cache != null) { cache.unlock(); } } }
Example #20
Source File: ResolveMerger.java From onedev with MIT License | 6 votes |
/** * Constructor for ResolveMerger. * * @param local * the {@link org.eclipse.jgit.lib.Repository}. * @param inCore * a boolean. */ protected ResolveMerger(Repository local, boolean inCore) { super(local); Config config = local.getConfig(); mergeAlgorithm = getMergeAlgorithm(config); inCoreLimit = getInCoreLimit(config); commitNames = defaultCommitNames(); this.inCore = inCore; if (inCore) { implicitDirCache = false; dircache = DirCache.newInCore(); } else { implicitDirCache = true; workingTreeOptions = local.getConfig().get(WorkingTreeOptions.KEY); } }
Example #21
Source File: CommitUtils.java From ParallelGit with Apache License 2.0 | 5 votes |
@Nonnull public static RevCommit createCommit(String message, DirCache cache, PersonIdent author, PersonIdent committer, List<? extends AnyObjectId> parents, Repository repo) throws IOException { try(ObjectInserter inserter = repo.newObjectInserter()) { AnyObjectId commitId = insertCommit(message, cache.writeTree(inserter), author, committer, parents, inserter); inserter.flush(); return CommitUtils.getCommit(commitId, repo); } }
Example #22
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void checkoutCacheWithIgnoringMultiStagesFile_theIgnoredFileShouldNotBeCheckedOut() throws IOException { initGitFileSystem("/some_existing_file.txt"); DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); builder.add(someEntry("/test_file.txt", STAGE_1)); builder.add(someEntry("/test_file.txt", STAGE_2)); builder.add(someEntry("/test_file.txt", STAGE_3)); builder.finish(); new GfsDefaultCheckout(gfs).ignoredFiles(singleton("/test_file.txt")).checkout(cache); assertFalse(Files.exists(gfs.getPath("/test_file.txt"))); }
Example #23
Source File: GitPushWindow.java From XACML with MIT License | 5 votes |
protected Object generateUntrackedEntry(final GitEntry entry) { Button add = new Button("Add"); add.setImmediate(true); add.addClickListener(new ClickListener() { private static final long serialVersionUID = 1L; @Override public void buttonClick(ClickEvent event) { try { DirCache cache = self.git.add().addFilepattern(entry.getName()).call(); DirCacheEntry cacheEntry = cache.getEntry(entry.getName()); assert(cacheEntry != null); if (cacheEntry == null) { return; } if (cacheEntry.isMerged()) { self.refreshStatus(); } } catch (GitAPIException e) { String error = "Failed to add: " + e.getLocalizedMessage(); logger.error(error); AdminNotification.error(error); } } }); return add; }
Example #24
Source File: CacheUtilsCreateTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void createCacheFromCommit_theResultCacheShouldContainTheFilesInTheSpecifiedCommit() throws IOException { writeToCache("/file1.txt"); writeToCache("/file2.txt"); AnyObjectId commitId = commit(someCommitMessage(), null); DirCache cache = CacheUtils.forRevision(commitId, repo); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", cache)); }
Example #25
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void deleteFileTest() { DirCache cache = setupCache("a/b/c1.txt", "a/c2.txt", "a/c3.txt"); CacheUtils.deleteFile("non_existent_file", cache); assertEquals(3, cache.getEntryCount()); CacheUtils.deleteFile("a/b/c1.txt", cache); assertEquals(2, cache.getEntryCount()); CacheUtils.deleteFile("a/c2.txt", cache); assertEquals(1, cache.getEntryCount()); }
Example #26
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
private static int assertCacheSameSize(DirCache expected, DirCache actual, String header) { int actualSize = actual.getEntryCount(); int expectedSize = expected.getEntryCount(); if(actualSize != expectedSize) fail(header + "cache sizes differed, expected.size=" + expectedSize + " actual.size=" + actualSize); return expectedSize; }
Example #27
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void checkoutCacheWithIgnoringMultiStagesFile_theIgnoredFileShouldNotBeCheckedOut() throws IOException { initGitFileSystem("/some_existing_file.txt"); DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); builder.add(someEntry("/test_file.txt", STAGE_1)); builder.add(someEntry("/test_file.txt", STAGE_2)); builder.add(someEntry("/test_file.txt", STAGE_3)); builder.finish(); new GfsDefaultCheckout(gfs).ignoredFiles(singleton("/test_file.txt")).checkout(cache); assertFalse(Files.exists(gfs.getPath("/test_file.txt"))); }
Example #28
Source File: CacheUtilsCreateTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void createCacheFromTagRef_theResultCacheShouldContainTheFilesInTheTaggedCommit() throws IOException { writeToCache("/file1.txt"); writeToCache("/file2.txt"); Ref tagRef = TagUtils.tagCommit("test_tag", commit(someCommitMessage(), null), repo); DirCache cache = CacheUtils.forRevision(tagRef, repo); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", cache)); }
Example #29
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
public static void assertCacheEquals(@Nullable String message, DirCache expected, DirCache actual) { if(expected != actual) { String header = message == null ? "" : message + ": "; int cacheSize = assertCacheSameSize(expected, actual, header); DirCacheEntry[] expectedEntries = expected.getEntriesWithin(""); DirCacheEntry[] actualEntries = actual.getEntriesWithin(""); for(int i = 0; i < cacheSize; ++i) { DirCacheEntry expectedEntry = expectedEntries[i]; DirCacheEntry actualEntry = actualEntries[i]; assertCacheEntryEquals(expectedEntry, actualEntry, header, i); } } }
Example #30
Source File: WrapGit.java From jphp with Apache License 2.0 | 5 votes |
@Signature public void add(String filePattern, ArrayMemory settings) throws GitAPIException { AddCommand addCommand = getWrappedObject().add(); addCommand.addFilepattern(filePattern); if (settings != null && settings.isNotNull()) { addCommand.setUpdate(settings.valueOfIndex("update").toBoolean()); } DirCache dirCache = addCommand.call(); }