Java Code Examples for org.eclipse.jgit.dircache.DirCacheBuilder#finish()
The following examples show how to use
org.eclipse.jgit.dircache.DirCacheBuilder#finish() .
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: 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 2
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 3
Source File: FilesWriteTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void writeLargeFile_shouldWork() throws IOException { repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null); repo = RepositoryUtils.createRepository(repoDir, true); DirCacheBuilder builder = CacheUtils.keepEverything(cache); byte[] largeData = new byte[50*1024*1024+1]; Random random = new Random(); random.nextBytes(largeData); AnyObjectId blobId = BlobUtils.insertBlob(largeData, repo); addFile("large.txt", REGULAR_FILE, blobId, builder); builder.finish(); commitToMaster(); initGitFileSystemForBranch(MASTER); byte[] data = someBytes(); Path file = gfs.getPath("/large.txt"); Files.write(file, data, APPEND); }
Example 4
Source File: FilesWriteTest.java From ParallelGit with Apache License 2.0 | 6 votes |
@Test public void writeLargeFile_shouldWork() throws IOException { repoDir = FileUtils.createTempDir(getClass().getSimpleName(), null, null); repo = RepositoryUtils.createRepository(repoDir, true); DirCacheBuilder builder = CacheUtils.keepEverything(cache); byte[] largeData = new byte[50*1024*1024+1]; Random random = new Random(); random.nextBytes(largeData); AnyObjectId blobId = BlobUtils.insertBlob(largeData, repo); addFile("large.txt", REGULAR_FILE, blobId, builder); builder.finish(); commitToMaster(); initGitFileSystemForBranch(MASTER); byte[] data = someBytes(); Path file = gfs.getPath("/large.txt"); Files.write(file, data, APPEND); }
Example 5
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 6
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 7
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void addFilesWithDirCacheBuilderTest() { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); String[] files = new String[] {"a/b/c1.txt", "a/c2.txt", "a/c3.txt", "a/b/c4.txt"}; for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder);builder.finish(); int entryCount = cache.getEntryCount(); assertEquals(4, entryCount); }
Example 8
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void addFilesWithDirCacheBuilderTest() { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); String[] files = new String[] {"a/b/c1.txt", "a/c2.txt", "a/c3.txt", "a/b/c4.txt"}; for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder);builder.finish(); int entryCount = cache.getEntryCount(); assertEquals(4, entryCount); }
Example 9
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void keepEverything_ExistingEntriesShouldBeKept() throws IOException { writeMultipleToCache("/file1.txt", "/file2.txt"); DirCacheBuilder builder = CacheUtils.keepEverything(cache); builder.finish(); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", cache)); }
Example 10
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Nonnull private static DirCache setupCache(String... files) { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder); builder.finish(); return cache; }
Example 11
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
protected void writeMultipleToCache(String... paths) throws IOException { DirCacheBuilder builder = CacheUtils.keepEverything(cache); for(String path : paths) { AnyObjectId blobId = repo != null ? BlobUtils.insertBlob(someBytes(), repo) : someObjectId(); addFile(path, REGULAR_FILE, blobId, builder); } builder.finish(); }
Example 12
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 13
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void checkoutCacheWithMultiStagesFile_shouldThrowIllegalStateException() 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).checkout(cache); }
Example 14
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test public void keepEverything_ExistingEntriesShouldBeKept() throws IOException { writeMultipleToCache("/file1.txt", "/file2.txt"); DirCacheBuilder builder = CacheUtils.keepEverything(cache); builder.finish(); assertNotNull(CacheUtils.getEntry("/file1.txt", cache)); assertNotNull(CacheUtils.getEntry("/file2.txt", cache)); }
Example 15
Source File: CacheUtilsEditTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Nonnull private static DirCache setupCache(String... files) { DirCache cache = DirCache.newInCore(); DirCacheBuilder builder = cache.builder(); for(String file : files) CacheUtils.addFile(file, REGULAR_FILE, zeroId(), builder); builder.finish(); return cache; }
Example 16
Source File: AbstractParallelGitTest.java From ParallelGit with Apache License 2.0 | 5 votes |
protected void writeMultipleToCache(String... paths) throws IOException { DirCacheBuilder builder = CacheUtils.keepEverything(cache); for(String path : paths) { AnyObjectId blobId = repo != null ? BlobUtils.insertBlob(someBytes(), repo) : someObjectId(); addFile(path, REGULAR_FILE, blobId, builder); } builder.finish(); }
Example 17
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 18
Source File: GfsDefaultCheckoutCacheTest.java From ParallelGit with Apache License 2.0 | 5 votes |
@Test(expected = IllegalStateException.class) public void checkoutCacheWithMultiStagesFile_shouldThrowIllegalStateException() 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).checkout(cache); }
Example 19
Source File: ResetTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testResetConflict () throws Exception { File file = new File(workDir, "file"); write(file, "init"); File[] files = new File[] { file }; add(files); commit(files); DirCache index = repository.lockDirCache(); DirCacheBuilder builder = index.builder(); DirCacheEntry e = index.getEntry(file.getName()); DirCacheEntry e1 = new DirCacheEntry(file.getName(), 1); e1.setCreationTime(e.getCreationTime()); e1.setFileMode(e.getFileMode()); e1.setLastModified(e.getLastModified()); e1.setLength(e.getLength()); e1.setObjectId(e.getObjectId()); builder.add(e1); builder.finish(); builder.commit(); GitClient client = getClient(workDir); Map<File, GitStatus> status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertTrue(status.get(file).isConflict()); assertEquals(GitConflictDescriptor.Type.BOTH_DELETED, status.get(file).getConflictDescriptor().getType()); client.reset(files, "HEAD", true, NULL_PROGRESS_MONITOR); status = client.getStatus(files, NULL_PROGRESS_MONITOR); assertFalse(status.get(file).isConflict()); }