Java Code Examples for org.eclipse.jgit.dircache.DirCache#unlock()

The following examples show how to use org.eclipse.jgit.dircache.DirCache#unlock() . 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: CheckoutIndexCommand.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@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 2
Source File: CheckoutTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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 3
Source File: AbstractGitTestCase.java    From netbeans with Apache License 2.0 6 votes vote down vote up
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: CleanTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertNullDirCacheEntry (Collection<File> files) throws Exception {
    DirCache cache = repository.lockDirCache();
    for (File f : files) {
        DirCacheEntry e = cache.getEntry(Utils.getRelativePath(workDir, f));
        assertNull(e);
    }
    cache.unlock();
}
 
Example 5
Source File: AddTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertDirCacheEntryModified (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());
        try (InputStream in = new FileInputStream(f)) {
            assertNotSame(e.getObjectId(), repository.newObjectInserter().idFor(Constants.OBJ_BLOB, f.length(), in));
        }
    }
    cache.unlock();
}
 
Example 6
Source File: AddTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertNullDirCacheEntry (Collection<File> files) throws Exception {
    DirCache cache = repository.lockDirCache();
    for (File f : files) {
        DirCacheEntry e = cache.getEntry(Utils.getRelativePath(workDir, f));
        assertNull(e);
    }
    cache.unlock();
}
 
Example 7
Source File: AddTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void assertDirCacheSize (int expectedSize) throws IOException {
    DirCache cache = repository.lockDirCache();
    try {
        assertEquals(expectedSize, cache.getEntryCount());
    } finally {
        cache.unlock();
    }
}