aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2019-07-03 01:07:14 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-07-18 03:27:52 +0200
commit95e8264cc8d2689cec10b58fbf15149856000df4 (patch)
tree02c5e1673058615c71778b436fd50855b96aed0f /org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
parent4db39f50742706091ee66207526cc801db40b780 (diff)
downloadjgit-95e8264cc8d2689cec10b58fbf15149856000df4.tar.gz
jgit-95e8264cc8d2689cec10b58fbf15149856000df4.zip
Use Instant instead of milliseconds for filesystem timestamp handling
This enables higher file timestamp resolution on filesystems like ext4, Mac APFS (1ns) or NTFS (100ns) providing high timestamp resolution on filesystem level. Note: - on some OSes Java 8,9 truncate milliseconds, see https://bugs.openjdk.java.net/browse/JDK-8177809, fixed in Java 10 - UnixFileAttributes truncates timestamp resolution to microseconds when converting the internal representation to FileTime exposed in the API, see https://bugs.openjdk.java.net/browse/JDK-8181493 - WindowsFileAttributes also provides only microsecond resolution Change-Id: I25ffff31a3c6f725fc345d4ddc2f26da3b88f6f2 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java24
1 files changed, 13 insertions, 11 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
index 3a13aa5a41..a6072a0f5f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
@@ -61,6 +61,7 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.junit.time.TimeUtil;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
@@ -311,11 +312,11 @@ public class CommitCommandTest extends RepositoryTestCase {
public void commitUpdatesSmudgedEntries() throws Exception {
try (Git git = new Git(db)) {
File file1 = writeTrashFile("file1.txt", "content1");
- assertTrue(file1.setLastModified(file1.lastModified() - 5000));
+ TimeUtil.setLastModifiedWithOffset(file1.toPath(), -5000L);
File file2 = writeTrashFile("file2.txt", "content2");
- assertTrue(file2.setLastModified(file2.lastModified() - 5000));
+ TimeUtil.setLastModifiedWithOffset(file2.toPath(), -5000L);
File file3 = writeTrashFile("file3.txt", "content3");
- assertTrue(file3.setLastModified(file3.lastModified() - 5000));
+ TimeUtil.setLastModifiedWithOffset(file3.toPath(), -5000L);
assertNotNull(git.add().addFilepattern("file1.txt")
.addFilepattern("file2.txt").addFilepattern("file3.txt").call());
@@ -346,11 +347,12 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(0, cache.getEntry("file2.txt").getLength());
assertEquals(0, cache.getEntry("file3.txt").getLength());
- long indexTime = db.getIndexFile().lastModified();
- db.getIndexFile().setLastModified(indexTime - 5000);
+ TimeUtil.setLastModifiedWithOffset(db.getIndexFile().toPath(),
+ -5000L);
write(file1, "content4");
- assertTrue(file1.setLastModified(file1.lastModified() + 2500));
+
+ TimeUtil.setLastModifiedWithOffset(file1.toPath(), 2500L);
assertNotNull(git.commit().setMessage("edit file").setOnly("file1.txt")
.call());
@@ -368,9 +370,9 @@ public class CommitCommandTest extends RepositoryTestCase {
public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception {
try (Git git = new Git(db)) {
File file1 = writeTrashFile("file1.txt", "content1");
- assertTrue(file1.setLastModified(file1.lastModified() - 5000));
+ TimeUtil.setLastModifiedWithOffset(file1.toPath(), -5000L);
File file2 = writeTrashFile("file2.txt", "content2");
- assertTrue(file2.setLastModified(file2.lastModified() - 5000));
+ TimeUtil.setLastModifiedWithOffset(file2.toPath(), -5000L);
assertNotNull(git.add().addFilepattern("file1.txt")
.addFilepattern("file2.txt").call());
@@ -399,11 +401,11 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(0, cache.getEntry("file1.txt").getLength());
assertEquals(0, cache.getEntry("file2.txt").getLength());
- long indexTime = db.getIndexFile().lastModified();
- db.getIndexFile().setLastModified(indexTime - 5000);
+ TimeUtil.setLastModifiedWithOffset(db.getIndexFile().toPath(),
+ -5000L);
write(file1, "content5");
- assertTrue(file1.setLastModified(file1.lastModified() + 1000));
+ TimeUtil.setLastModifiedWithOffset(file1.toPath(), 1000L);
assertNotNull(git.commit().setMessage("edit file").setOnly("file1.txt")
.call());