IndexModificationTimesTest: Open Git instances in try-with-resource
Change-Id: If52c071b71f5df822b1ac276a6f665515f6c9d00 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
de73fbf597
commit
217760fee5
|
@ -49,80 +49,81 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
|
|||
|
||||
@Test
|
||||
public void testLastModifiedTimes() throws Exception {
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content2");
|
||||
try (Git git = new Git(db)) {
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content2");
|
||||
|
||||
git.add().addFilepattern(path).call();
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
git.add().addFilepattern(path).call();
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCacheEntry entry2 = dc.getEntry(path);
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCacheEntry entry2 = dc.getEntry(path);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
|
||||
writeTrashFile(path, "new content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit2").call();
|
||||
writeTrashFile(path, "new content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit2").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
entry2 = dc.getEntry(path);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
entry2 = dc.getEntry(path);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModify() throws Exception {
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
try (Git git = new Git(db)) {
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
|
||||
long masterLastMod = entry.getLastModified();
|
||||
long masterLastMod = entry.getLastModified();
|
||||
|
||||
git.checkout().setCreateBranch(true).setName("side").call();
|
||||
git.checkout().setCreateBranch(true).setName("side").call();
|
||||
|
||||
Thread.sleep(10);
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "side content");
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
Thread.sleep(10);
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "side content");
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
long sideLastMode = entry.getLastModified();
|
||||
long sideLastMode = entry.getLastModified();
|
||||
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(2000);
|
||||
|
||||
writeTrashFile(path, "uncommitted content");
|
||||
git.checkout().setName("master").call();
|
||||
writeTrashFile(path, "uncommitted content");
|
||||
git.checkout().setName("master").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
|
||||
assertTrue("shall not equal master timestamp!",
|
||||
entry.getLastModified() == masterLastMod);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
|
||||
assertTrue("shall not equal master timestamp!",
|
||||
entry.getLastModified() == masterLastMod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue