Merge branch 'stable-4.2'
* stable-4.2: FileTreeIteratorTest: Open Git and RevWalk in try-with-resource RebaseCommandTest: Open RevWalk in try-with-resource PullCommandTest: Open RevWalk in try-with-resource BlameGeneratorTest: Create Git instances in try-with-resource Remove unnecessary suppression of deprecation warnings in tests DiffEntryTest: Open Git and TreeWalk in try-with-resource DiffCommandTest: Open Git and RevWalk in try-with-resource CommitCommandTest: Open Git and TreeWalk in try-with-resource Change-Id: Ic886ec9b1a4b3b46f9fa14188b4df832ce36cfa6 Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
commit
27a6a52654
|
@ -186,7 +186,7 @@ public boolean isCaseSensitive() {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitNewSubmodule() throws Exception {
|
public void commitNewSubmodule() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit commit = git.commit().setMessage("create file").call();
|
RevCommit commit = git.commit().setMessage("create file").call();
|
||||||
|
@ -215,7 +215,7 @@ public void commitNewSubmodule() throws Exception {
|
||||||
RevCommit submoduleCommit = git.commit().setMessage("submodule add")
|
RevCommit submoduleCommit = git.commit().setMessage("submodule add")
|
||||||
.setOnly(path).call();
|
.setOnly(path).call();
|
||||||
assertNotNull(submoduleCommit);
|
assertNotNull(submoduleCommit);
|
||||||
TreeWalk walk = new TreeWalk(db);
|
try (TreeWalk walk = new TreeWalk(db)) {
|
||||||
walk.addTree(commit.getTree());
|
walk.addTree(commit.getTree());
|
||||||
walk.addTree(submoduleCommit.getTree());
|
walk.addTree(submoduleCommit.getTree());
|
||||||
walk.setFilter(TreeFilter.ANY_DIFF);
|
walk.setFilter(TreeFilter.ANY_DIFF);
|
||||||
|
@ -228,10 +228,12 @@ public void commitNewSubmodule() throws Exception {
|
||||||
assertEquals(commit, subDiff.getNewId().toObjectId());
|
assertEquals(commit, subDiff.getNewId().toObjectId());
|
||||||
assertEquals(path, subDiff.getNewPath());
|
assertEquals(path, subDiff.getNewPath());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitSubmoduleUpdate() throws Exception {
|
public void commitSubmoduleUpdate() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
RevCommit commit = git.commit().setMessage("create file").call();
|
RevCommit commit = git.commit().setMessage("create file").call();
|
||||||
|
@ -271,7 +273,7 @@ public void commitSubmoduleUpdate() throws Exception {
|
||||||
RevCommit submoduleEditCommit = git.commit()
|
RevCommit submoduleEditCommit = git.commit()
|
||||||
.setMessage("submodule add").setOnly(path).call();
|
.setMessage("submodule add").setOnly(path).call();
|
||||||
assertNotNull(submoduleEditCommit);
|
assertNotNull(submoduleEditCommit);
|
||||||
TreeWalk walk = new TreeWalk(db);
|
try (TreeWalk walk = new TreeWalk(db)) {
|
||||||
walk.addTree(submoduleAddCommit.getTree());
|
walk.addTree(submoduleAddCommit.getTree());
|
||||||
walk.addTree(submoduleEditCommit.getTree());
|
walk.addTree(submoduleEditCommit.getTree());
|
||||||
walk.setFilter(TreeFilter.ANY_DIFF);
|
walk.setFilter(TreeFilter.ANY_DIFF);
|
||||||
|
@ -285,11 +287,12 @@ public void commitSubmoduleUpdate() throws Exception {
|
||||||
assertEquals(path, subDiff.getNewPath());
|
assertEquals(path, subDiff.getNewPath());
|
||||||
assertEquals(path, subDiff.getOldPath());
|
assertEquals(path, subDiff.getOldPath());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitUpdatesSmudgedEntries() throws Exception {
|
public void commitUpdatesSmudgedEntries() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
File file1 = writeTrashFile("file1.txt", "content1");
|
File file1 = writeTrashFile("file1.txt", "content1");
|
||||||
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
|
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
|
||||||
File file2 = writeTrashFile("file2.txt", "content2");
|
File file2 = writeTrashFile("file2.txt", "content2");
|
||||||
|
@ -341,11 +344,11 @@ public void commitUpdatesSmudgedEntries() throws Exception {
|
||||||
assertEquals(file2Id, cache.getEntry("file2.txt").getObjectId());
|
assertEquals(file2Id, cache.getEntry("file2.txt").getObjectId());
|
||||||
assertEquals(file3Id, cache.getEntry("file3.txt").getObjectId());
|
assertEquals(file3Id, cache.getEntry("file3.txt").getObjectId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception {
|
public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
File file1 = writeTrashFile("file1.txt", "content1");
|
File file1 = writeTrashFile("file1.txt", "content1");
|
||||||
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
|
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
|
||||||
File file2 = writeTrashFile("file2.txt", "content2");
|
File file2 = writeTrashFile("file2.txt", "content2");
|
||||||
|
@ -391,11 +394,11 @@ public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception {
|
||||||
assertEquals(file1Size, cache.getEntry("file1.txt").getLength());
|
assertEquals(file1Size, cache.getEntry("file1.txt").getLength());
|
||||||
assertEquals(0, cache.getEntry("file2.txt").getLength());
|
assertEquals(0, cache.getEntry("file2.txt").getLength());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitAfterSquashMerge() throws Exception {
|
public void commitAfterSquashMerge() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
writeTrashFile("file1", "file1");
|
writeTrashFile("file1", "file1");
|
||||||
git.add().addFilepattern("file1").call();
|
git.add().addFilepattern("file1").call();
|
||||||
RevCommit first = git.commit().setMessage("initial commit").call();
|
RevCommit first = git.commit().setMessage("initial commit").call();
|
||||||
|
@ -431,18 +434,19 @@ public void commitAfterSquashMerge() throws Exception {
|
||||||
assertEquals("commit: Squashed commit of the following:", db
|
assertEquals("commit: Squashed commit of the following:", db
|
||||||
.getReflogReader(db.getBranch()).getLastEntry().getComment());
|
.getReflogReader(db.getBranch()).getLastEntry().getComment());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = WrongRepositoryStateException.class)
|
@Test(expected = WrongRepositoryStateException.class)
|
||||||
public void commitAmendOnInitialShouldFail() throws Exception {
|
public void commitAmendOnInitialShouldFail() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.commit().setAmend(true).setMessage("initial commit").call();
|
git.commit().setAmend(true).setMessage("initial commit").call();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime()
|
public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
writeTrashFile("file1", "file1");
|
writeTrashFile("file1", "file1");
|
||||||
git.add().addFilepattern("file1").call();
|
git.add().addFilepattern("file1").call();
|
||||||
|
|
||||||
|
@ -461,11 +465,11 @@ public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime()
|
||||||
assertEquals(authorEmail, amendedAuthor.getEmailAddress());
|
assertEquals(authorEmail, amendedAuthor.getEmailAddress());
|
||||||
assertEquals(authorDate.getTime(), amendedAuthor.getWhen().getTime());
|
assertEquals(authorDate.getTime(), amendedAuthor.getWhen().getTime());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitAmendWithAuthorShouldUseIt() throws Exception {
|
public void commitAmendWithAuthorShouldUseIt() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
writeTrashFile("file1", "file1");
|
writeTrashFile("file1", "file1");
|
||||||
git.add().addFilepattern("file1").call();
|
git.add().addFilepattern("file1").call();
|
||||||
git.commit().setMessage("initial commit").call();
|
git.commit().setMessage("initial commit").call();
|
||||||
|
@ -478,6 +482,7 @@ public void commitAmendWithAuthorShouldUseIt() throws Exception {
|
||||||
assertEquals("New Author", amendedAuthor.getName());
|
assertEquals("New Author", amendedAuthor.getName());
|
||||||
assertEquals("newauthor@example.org", amendedAuthor.getEmailAddress());
|
assertEquals("newauthor@example.org", amendedAuthor.getEmailAddress());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitEmptyCommits() throws Exception {
|
public void commitEmptyCommits() throws Exception {
|
||||||
|
@ -532,7 +537,7 @@ public void commitOnlyShouldCommitUnmergedPathAndNotAffectOthers()
|
||||||
+ "[unmerged2, mode:100644, stage:3]",
|
+ "[unmerged2, mode:100644, stage:3]",
|
||||||
indexState(0));
|
indexState(0));
|
||||||
|
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
RevCommit commit = git.commit().setOnly("unmerged1")
|
RevCommit commit = git.commit().setOnly("unmerged1")
|
||||||
.setMessage("Only one file").call();
|
.setMessage("Only one file").call();
|
||||||
|
|
||||||
|
@ -546,6 +551,7 @@ public void commitOnlyShouldCommitUnmergedPathAndNotAffectOthers()
|
||||||
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
|
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commitOnlyShouldHandleIgnored() throws Exception {
|
public void commitOnlyShouldHandleIgnored() throws Exception {
|
||||||
|
|
|
@ -70,7 +70,7 @@ public void testDiffModified() throws Exception {
|
||||||
File folder = new File(db.getWorkTree(), "folder");
|
File folder = new File(db.getWorkTree(), "folder");
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
write(new File(folder, "folder.txt"), "folder");
|
write(new File(folder, "folder.txt"), "folder");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(folder, "folder.txt"), "folder change");
|
write(new File(folder, "folder.txt"), "folder change");
|
||||||
|
@ -97,13 +97,14 @@ public void testDiffModified() throws Exception {
|
||||||
+ "\\ No newline at end of file\n";
|
+ "\\ No newline at end of file\n";
|
||||||
assertEquals(expected.toString(), actual);
|
assertEquals(expected.toString(), actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDiffCached() throws Exception {
|
public void testDiffCached() throws Exception {
|
||||||
write(new File(db.getWorkTree(), "test.txt"), "test");
|
write(new File(db.getWorkTree(), "test.txt"), "test");
|
||||||
File folder = new File(db.getWorkTree(), "folder");
|
File folder = new File(db.getWorkTree(), "folder");
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(folder, "folder.txt"), "folder");
|
write(new File(folder, "folder.txt"), "folder");
|
||||||
|
@ -131,6 +132,7 @@ public void testDiffCached() throws Exception {
|
||||||
+ "\\ No newline at end of file\n";
|
+ "\\ No newline at end of file\n";
|
||||||
assertEquals(expected.toString(), actual);
|
assertEquals(expected.toString(), actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDiffTwoCommits() throws Exception {
|
public void testDiffTwoCommits() throws Exception {
|
||||||
|
@ -138,7 +140,7 @@ public void testDiffTwoCommits() throws Exception {
|
||||||
File folder = new File(db.getWorkTree(), "folder");
|
File folder = new File(db.getWorkTree(), "folder");
|
||||||
folder.mkdir();
|
folder.mkdir();
|
||||||
write(new File(folder, "folder.txt"), "folder");
|
write(new File(folder, "folder.txt"), "folder");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(folder, "folder.txt"), "folder change");
|
write(new File(folder, "folder.txt"), "folder change");
|
||||||
|
@ -179,19 +181,19 @@ public void testDiffTwoCommits() throws Exception {
|
||||||
+ "\\ No newline at end of file\n";
|
+ "\\ No newline at end of file\n";
|
||||||
assertEquals(expected.toString(), actual);
|
assertEquals(expected.toString(), actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDiffWithPrefixes() throws Exception {
|
public void testDiffWithPrefixes() throws Exception {
|
||||||
write(new File(db.getWorkTree(), "test.txt"), "test");
|
write(new File(db.getWorkTree(), "test.txt"), "test");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(db.getWorkTree(), "test.txt"), "test change");
|
write(new File(db.getWorkTree(), "test.txt"), "test change");
|
||||||
|
|
||||||
OutputStream out = new ByteArrayOutputStream();
|
OutputStream out = new ByteArrayOutputStream();
|
||||||
git.diff().setOutputStream(out).setSourcePrefix("old/")
|
git.diff().setOutputStream(out).setSourcePrefix("old/")
|
||||||
.setDestinationPrefix("new/")
|
.setDestinationPrefix("new/").call();
|
||||||
.call();
|
|
||||||
|
|
||||||
String actual = out.toString();
|
String actual = out.toString();
|
||||||
String expected = "diff --git old/test.txt new/test.txt\n"
|
String expected = "diff --git old/test.txt new/test.txt\n"
|
||||||
|
@ -201,20 +203,20 @@ public void testDiffWithPrefixes() throws Exception {
|
||||||
+ "\\ No newline at end of file\n";
|
+ "\\ No newline at end of file\n";
|
||||||
assertEquals(expected.toString(), actual);
|
assertEquals(expected.toString(), actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDiffWithNegativeLineCount() throws Exception {
|
public void testDiffWithNegativeLineCount() throws Exception {
|
||||||
write(new File(db.getWorkTree(), "test.txt"),
|
write(new File(db.getWorkTree(), "test.txt"),
|
||||||
"0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
|
"0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("Initial commit").call();
|
git.commit().setMessage("Initial commit").call();
|
||||||
write(new File(db.getWorkTree(), "test.txt"),
|
write(new File(db.getWorkTree(), "test.txt"),
|
||||||
"0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
|
"0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
|
||||||
|
|
||||||
OutputStream out = new ByteArrayOutputStream();
|
OutputStream out = new ByteArrayOutputStream();
|
||||||
git.diff().setOutputStream(out).setContextLines(1)
|
git.diff().setOutputStream(out).setContextLines(1).call();
|
||||||
.call();
|
|
||||||
|
|
||||||
String actual = out.toString();
|
String actual = out.toString();
|
||||||
String expected = "diff --git a/test.txt b/test.txt\n"
|
String expected = "diff --git a/test.txt b/test.txt\n"
|
||||||
|
@ -223,12 +225,13 @@ public void testDiffWithNegativeLineCount() throws Exception {
|
||||||
+ "+4a\n" + " 5\n";
|
+ "+4a\n" + " 5\n";
|
||||||
assertEquals(expected.toString(), actual);
|
assertEquals(expected.toString(), actual);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNoOutputStreamSet() throws Exception {
|
public void testNoOutputStreamSet() throws Exception {
|
||||||
File file = writeTrashFile("test.txt", "a");
|
File file = writeTrashFile("test.txt", "a");
|
||||||
assertTrue(file.setLastModified(file.lastModified() - 5000));
|
assertTrue(file.setLastModified(file.lastModified() - 5000));
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
write(file, "b");
|
write(file, "b");
|
||||||
|
|
||||||
|
@ -240,6 +243,7 @@ public void testNoOutputStreamSet() throws Exception {
|
||||||
assertEquals("test.txt", diff.getOldPath());
|
assertEquals("test.txt", diff.getOldPath());
|
||||||
assertEquals("test.txt", diff.getNewPath());
|
assertEquals("test.txt", diff.getNewPath());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AbstractTreeIterator getTreeIterator(String name)
|
private AbstractTreeIterator getTreeIterator(String name)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
|
@ -247,8 +251,9 @@ private AbstractTreeIterator getTreeIterator(String name)
|
||||||
if (id == null)
|
if (id == null)
|
||||||
throw new IllegalArgumentException(name);
|
throw new IllegalArgumentException(name);
|
||||||
final CanonicalTreeParser p = new CanonicalTreeParser();
|
final CanonicalTreeParser p = new CanonicalTreeParser();
|
||||||
try (ObjectReader or = db.newObjectReader()) {
|
try (ObjectReader or = db.newObjectReader();
|
||||||
p.reset(or, new RevWalk(db).parseTree(id));
|
RevWalk rw = new RevWalk(db)) {
|
||||||
|
p.reset(or, rw.parseTree(id));
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,12 +140,13 @@ public void testPullMerge() throws Exception {
|
||||||
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
||||||
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
||||||
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
||||||
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
|
try (RevWalk rw = new RevWalk(dbTarget)) {
|
||||||
.getNewHead());
|
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
|
||||||
String message = "Merge branch 'master' of "
|
String message = "Merge branch 'master' of "
|
||||||
+ db.getWorkTree().getAbsolutePath();
|
+ db.getWorkTree().getAbsolutePath();
|
||||||
assertEquals(message, mergeCommit.getShortMessage());
|
assertEquals(message, mergeCommit.getShortMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPullConflict() throws Exception {
|
public void testPullConflict() throws Exception {
|
||||||
|
@ -259,12 +260,13 @@ public void testPullMergeProgrammaticConfiguration() throws Exception {
|
||||||
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
||||||
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
||||||
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
||||||
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
|
try (RevWalk rw = new RevWalk(dbTarget)) {
|
||||||
.getNewHead());
|
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
|
||||||
String message = "Merge branch 'other' of "
|
String message = "Merge branch 'other' of "
|
||||||
+ db.getWorkTree().getAbsolutePath();
|
+ db.getWorkTree().getAbsolutePath();
|
||||||
assertEquals(message, mergeCommit.getShortMessage());
|
assertEquals(message, mergeCommit.getShortMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPullMergeProgrammaticConfigurationImpliedTargetBranch()
|
public void testPullMergeProgrammaticConfigurationImpliedTargetBranch()
|
||||||
|
@ -293,12 +295,13 @@ public void testPullMergeProgrammaticConfigurationImpliedTargetBranch()
|
||||||
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
|
||||||
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
assertEquals(targetCommit.getId(), mergedCommits[0]);
|
||||||
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
assertEquals(sourceCommit.getId(), mergedCommits[1]);
|
||||||
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
|
try (RevWalk rw = new RevWalk(dbTarget)) {
|
||||||
.getNewHead());
|
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
|
||||||
String message = "Merge branch 'other' of "
|
String message = "Merge branch 'other' of "
|
||||||
+ db.getWorkTree().getAbsolutePath() + " into other";
|
+ db.getWorkTree().getAbsolutePath() + " into other";
|
||||||
assertEquals(message, mergeCommit.getShortMessage());
|
assertEquals(message, mergeCommit.getShortMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private enum TestPullMode {
|
private enum TestPullMode {
|
||||||
MERGE, REBASE, REBASE_PREASERVE
|
MERGE, REBASE, REBASE_PREASERVE
|
||||||
|
|
|
@ -288,13 +288,14 @@ public void testRebaseShouldIgnoreMergeCommits()
|
||||||
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
|
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
|
||||||
assertEquals(Status.OK, res.getStatus());
|
assertEquals(Status.OK, res.getStatus());
|
||||||
|
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
|
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
|
||||||
assertDerivedFrom(rw.next(), e);
|
assertDerivedFrom(rw.next(), e);
|
||||||
assertDerivedFrom(rw.next(), d);
|
assertDerivedFrom(rw.next(), d);
|
||||||
assertDerivedFrom(rw.next(), c);
|
assertDerivedFrom(rw.next(), c);
|
||||||
assertEquals(b, rw.next());
|
assertEquals(b, rw.next());
|
||||||
assertEquals(a, rw.next());
|
assertEquals(a, rw.next());
|
||||||
|
}
|
||||||
|
|
||||||
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
||||||
.getReverseEntries();
|
.getReverseEntries();
|
||||||
|
@ -354,8 +355,6 @@ public void testRebasePreservingMerges2() throws Exception {
|
||||||
*/
|
*/
|
||||||
private void doTestRebasePreservingMerges(boolean testConflict)
|
private void doTestRebasePreservingMerges(boolean testConflict)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
RevWalk rw = new RevWalk(db);
|
|
||||||
|
|
||||||
// create file1 on master
|
// create file1 on master
|
||||||
writeTrashFile(FILE1, FILE1);
|
writeTrashFile(FILE1, FILE1);
|
||||||
git.add().addFilepattern(FILE1).call();
|
git.add().addFilepattern(FILE1).call();
|
||||||
|
@ -409,8 +408,10 @@ private void doTestRebasePreservingMerges(boolean testConflict)
|
||||||
f = git.commit().setMessage("commit f").call();
|
f = git.commit().setMessage("commit f").call();
|
||||||
} else {
|
} else {
|
||||||
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
|
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
|
||||||
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
f = rw.parseCommit(result.getNewHead());
|
f = rw.parseCommit(result.getNewHead());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
RebaseResult res = git.rebase().setUpstream("refs/heads/master")
|
RebaseResult res = git.rebase().setUpstream("refs/heads/master")
|
||||||
.setPreserveMerges(true).call();
|
.setPreserveMerges(true).call();
|
||||||
|
@ -453,6 +454,7 @@ private void doTestRebasePreservingMerges(boolean testConflict)
|
||||||
assertEquals("file2", read("file2"));
|
assertEquals("file2", read("file2"));
|
||||||
assertEquals("more change", read("file3"));
|
assertEquals("more change", read("file3"));
|
||||||
|
|
||||||
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
|
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
|
||||||
RevCommit newF = rw.next();
|
RevCommit newF = rw.next();
|
||||||
assertDerivedFrom(newF, f);
|
assertDerivedFrom(newF, f);
|
||||||
|
@ -471,6 +473,7 @@ private void doTestRebasePreservingMerges(boolean testConflict)
|
||||||
assertEquals(b, rw.next());
|
assertEquals(b, rw.next());
|
||||||
assertEquals(a, rw.next());
|
assertEquals(a, rw.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String readFile(String path, RevCommit commit) throws IOException {
|
private String readFile(String path, RevCommit commit) throws IOException {
|
||||||
try (TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree())) {
|
try (TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree())) {
|
||||||
|
@ -517,7 +520,7 @@ public void testRebasePreservingMergesWithUnrelatedSide2() throws Exception {
|
||||||
*/
|
*/
|
||||||
private void doTestRebasePreservingMergesWithUnrelatedSide(
|
private void doTestRebasePreservingMergesWithUnrelatedSide(
|
||||||
boolean testConflict) throws Exception {
|
boolean testConflict) throws Exception {
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
rw.sort(RevSort.TOPO);
|
rw.sort(RevSort.TOPO);
|
||||||
|
|
||||||
writeTrashFile(FILE1, FILE1);
|
writeTrashFile(FILE1, FILE1);
|
||||||
|
@ -600,6 +603,7 @@ private void doTestRebasePreservingMergesWithUnrelatedSide(
|
||||||
assertEquals(b, rw.next());
|
assertEquals(b, rw.next());
|
||||||
assertEquals(a, rw.next());
|
assertEquals(a, rw.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRebaseParentOntoHeadShouldBeUptoDate() throws Exception {
|
public void testRebaseParentOntoHeadShouldBeUptoDate() throws Exception {
|
||||||
|
@ -687,8 +691,10 @@ public void testConflictFreeWithSingleFile() throws Exception {
|
||||||
checkFile(theFile, "1master\n2\n3\ntopic\n");
|
checkFile(theFile, "1master\n2\n3\ntopic\n");
|
||||||
// our old branch should be checked out again
|
// our old branch should be checked out again
|
||||||
assertEquals("refs/heads/topic", db.getFullBranch());
|
assertEquals("refs/heads/topic", db.getFullBranch());
|
||||||
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
|
assertEquals(lastMasterChange, rw.parseCommit(
|
||||||
db.resolve(Constants.HEAD)).getParent(0));
|
db.resolve(Constants.HEAD)).getParent(0));
|
||||||
|
}
|
||||||
assertEquals(origHead, db.readOrigHead());
|
assertEquals(origHead, db.readOrigHead());
|
||||||
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
||||||
.getReverseEntries();
|
.getReverseEntries();
|
||||||
|
@ -737,8 +743,10 @@ public void testDetachedHead() throws Exception {
|
||||||
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
|
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
|
||||||
assertEquals(Status.OK, res.getStatus());
|
assertEquals(Status.OK, res.getStatus());
|
||||||
checkFile(theFile, "1master\n2\n3\ntopic\n");
|
checkFile(theFile, "1master\n2\n3\ntopic\n");
|
||||||
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
|
assertEquals(lastMasterChange, rw.parseCommit(
|
||||||
db.resolve(Constants.HEAD)).getParent(0));
|
db.resolve(Constants.HEAD)).getParent(0));
|
||||||
|
}
|
||||||
|
|
||||||
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
|
||||||
.getReverseEntries();
|
.getReverseEntries();
|
||||||
|
@ -785,8 +793,10 @@ public void testFilesAddedFromTwoBranches() throws Exception {
|
||||||
|
|
||||||
// our old branch should be checked out again
|
// our old branch should be checked out again
|
||||||
assertEquals("refs/heads/file3", db.getFullBranch());
|
assertEquals("refs/heads/file3", db.getFullBranch());
|
||||||
assertEquals(addFile2, new RevWalk(db).parseCommit(
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
|
assertEquals(addFile2, rw.parseCommit(
|
||||||
db.resolve(Constants.HEAD)).getParent(0));
|
db.resolve(Constants.HEAD)).getParent(0));
|
||||||
|
}
|
||||||
|
|
||||||
checkoutBranch("refs/heads/file2");
|
checkoutBranch("refs/heads/file2");
|
||||||
assertTrue(new File(db.getWorkTree(), FILE1).exists());
|
assertTrue(new File(db.getWorkTree(), FILE1).exists());
|
||||||
|
@ -846,9 +856,10 @@ public void testStopOnConflict() throws Exception {
|
||||||
assertEquals(res.getStatus(), Status.ABORTED);
|
assertEquals(res.getStatus(), Status.ABORTED);
|
||||||
assertEquals("refs/heads/topic", db.getFullBranch());
|
assertEquals("refs/heads/topic", db.getFullBranch());
|
||||||
checkFile(FILE1, "1topic", "2", "3", "topic4");
|
checkFile(FILE1, "1topic", "2", "3", "topic4");
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
assertEquals(lastTopicCommit, rw
|
assertEquals(lastTopicCommit,
|
||||||
.parseCommit(db.resolve(Constants.HEAD)));
|
rw.parseCommit(db.resolve(Constants.HEAD)));
|
||||||
|
}
|
||||||
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||||
|
|
||||||
// rebase- dir in .git must be deleted
|
// rebase- dir in .git must be deleted
|
||||||
|
@ -909,9 +920,10 @@ public void testStopOnConflictAndAbortWithDetachedHEAD() throws Exception {
|
||||||
assertEquals(res.getStatus(), Status.ABORTED);
|
assertEquals(res.getStatus(), Status.ABORTED);
|
||||||
assertEquals(lastTopicCommit.getName(), db.getFullBranch());
|
assertEquals(lastTopicCommit.getName(), db.getFullBranch());
|
||||||
checkFile(FILE1, "1topic", "2", "3", "topic4");
|
checkFile(FILE1, "1topic", "2", "3", "topic4");
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
assertEquals(lastTopicCommit,
|
assertEquals(lastTopicCommit,
|
||||||
rw.parseCommit(db.resolve(Constants.HEAD)));
|
rw.parseCommit(db.resolve(Constants.HEAD)));
|
||||||
|
}
|
||||||
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||||
|
|
||||||
// rebase- dir in .git must be deleted
|
// rebase- dir in .git must be deleted
|
||||||
|
@ -966,12 +978,13 @@ public void testStopOnConflictAndContinue() throws Exception {
|
||||||
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||||
|
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
RevCommit rc = rw.parseCommit(headId);
|
RevCommit rc = rw.parseCommit(headId);
|
||||||
RevCommit parent = rw.parseCommit(rc.getParent(0));
|
RevCommit parent = rw.parseCommit(rc.getParent(0));
|
||||||
assertEquals("change file1 in topic\n\nThis is conflicting", parent
|
assertEquals("change file1 in topic\n\nThis is conflicting", parent
|
||||||
.getFullMessage());
|
.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStopOnConflictAndContinueWithNoDeltaToMaster()
|
public void testStopOnConflictAndContinueWithNoDeltaToMaster()
|
||||||
|
@ -1017,10 +1030,11 @@ public void testStopOnConflictAndContinueWithNoDeltaToMaster()
|
||||||
git.rebase().setOperation(Operation.SKIP).call();
|
git.rebase().setOperation(Operation.SKIP).call();
|
||||||
|
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
RevCommit rc = rw.parseCommit(headId);
|
RevCommit rc = rw.parseCommit(headId);
|
||||||
assertEquals("change file1 in master", rc.getFullMessage());
|
assertEquals("change file1 in master", rc.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testStopOnConflictAndFailContinueIfFileIsDirty()
|
public void testStopOnConflictAndFailContinueIfFileIsDirty()
|
||||||
|
@ -1308,11 +1322,12 @@ public void testStopOnConflictCommitAndContinue() throws Exception {
|
||||||
git.rebase().setOperation(Operation.SKIP).call();
|
git.rebase().setOperation(Operation.SKIP).call();
|
||||||
|
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
RevCommit rc = rw.parseCommit(headId);
|
RevCommit rc = rw.parseCommit(headId);
|
||||||
RevCommit parent = rw.parseCommit(rc.getParent(0));
|
RevCommit parent = rw.parseCommit(rc.getParent(0));
|
||||||
assertEquals("A different commit message", parent.getFullMessage());
|
assertEquals("A different commit message", parent.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private RevCommit writeFileAndCommit(String fileName, String commitMessage,
|
private RevCommit writeFileAndCommit(String fileName, String commitMessage,
|
||||||
String... lines) throws Exception {
|
String... lines) throws Exception {
|
||||||
|
@ -1420,9 +1435,10 @@ public void testStopOnConflictFileCreationAndDeletion() throws Exception {
|
||||||
res = git.rebase().setOperation(Operation.ABORT).call();
|
res = git.rebase().setOperation(Operation.ABORT).call();
|
||||||
assertEquals(res.getStatus(), Status.ABORTED);
|
assertEquals(res.getStatus(), Status.ABORTED);
|
||||||
assertEquals("refs/heads/topic", db.getFullBranch());
|
assertEquals("refs/heads/topic", db.getFullBranch());
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
assertEquals(conflicting, rw.parseCommit(db.resolve(Constants.HEAD)));
|
assertEquals(conflicting, rw.parseCommit(db.resolve(Constants.HEAD)));
|
||||||
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
|
||||||
|
}
|
||||||
|
|
||||||
// rebase- dir in .git must be deleted
|
// rebase- dir in .git must be deleted
|
||||||
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
|
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
|
||||||
|
@ -2286,7 +2302,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
assertEquals(RebaseResult.Status.OK, res2.getStatus());
|
assertEquals(RebaseResult.Status.OK, res2.getStatus());
|
||||||
|
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevWalk rw = new RevWalk(db);
|
try (RevWalk rw = new RevWalk(db)) {
|
||||||
RevCommit rc = rw.parseCommit(headId);
|
RevCommit rc = rw.parseCommit(headId);
|
||||||
|
|
||||||
ObjectId head1Id = db.resolve(Constants.HEAD + "~1");
|
ObjectId head1Id = db.resolve(Constants.HEAD + "~1");
|
||||||
|
@ -2295,6 +2311,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
assertEquals(rc.getFullMessage(), c4.getFullMessage());
|
assertEquals(rc.getFullMessage(), c4.getFullMessage());
|
||||||
assertEquals(rc1.getFullMessage(), c2.getFullMessage());
|
assertEquals(rc1.getFullMessage(), c2.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseRewordCommand() throws Exception {
|
public void testParseRewordCommand() throws Exception {
|
||||||
|
@ -2643,7 +2660,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
}
|
}
|
||||||
}).call();
|
}).call();
|
||||||
|
|
||||||
RevWalk walk = new RevWalk(db);
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevCommit headCommit = walk.parseCommit(headId);
|
RevCommit headCommit = walk.parseCommit(headId);
|
||||||
assertEquals(headCommit.getFullMessage(),
|
assertEquals(headCommit.getFullMessage(),
|
||||||
|
@ -2653,6 +2670,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
RevCommit head1Commit = walk.parseCommit(head2Id);
|
RevCommit head1Commit = walk.parseCommit(head2Id);
|
||||||
assertEquals("changed", head1Commit.getFullMessage());
|
assertEquals("changed", head1Commit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRebaseInteractiveMultipleSquash() throws Exception {
|
public void testRebaseInteractiveMultipleSquash() throws Exception {
|
||||||
|
@ -2722,7 +2740,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
}
|
}
|
||||||
}).call();
|
}).call();
|
||||||
|
|
||||||
RevWalk walk = new RevWalk(db);
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevCommit headCommit = walk.parseCommit(headId);
|
RevCommit headCommit = walk.parseCommit(headId);
|
||||||
assertEquals(headCommit.getFullMessage(),
|
assertEquals(headCommit.getFullMessage(),
|
||||||
|
@ -2734,6 +2752,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
"Add file1\nnew line\nAdd file2\nnew line\nupdated file1 on master\nnew line",
|
"Add file1\nnew line\nAdd file2\nnew line\nupdated file1 on master\nnew line",
|
||||||
head1Commit.getFullMessage());
|
head1Commit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRebaseInteractiveMixedSquashAndFixup() throws Exception {
|
public void testRebaseInteractiveMixedSquashAndFixup() throws Exception {
|
||||||
|
@ -2804,7 +2823,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
}
|
}
|
||||||
}).call();
|
}).call();
|
||||||
|
|
||||||
RevWalk walk = new RevWalk(db);
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevCommit headCommit = walk.parseCommit(headId);
|
RevCommit headCommit = walk.parseCommit(headId);
|
||||||
assertEquals(headCommit.getFullMessage(),
|
assertEquals(headCommit.getFullMessage(),
|
||||||
|
@ -2814,6 +2833,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
RevCommit head1Commit = walk.parseCommit(head2Id);
|
RevCommit head1Commit = walk.parseCommit(head2Id);
|
||||||
assertEquals("changed", head1Commit.getFullMessage());
|
assertEquals("changed", head1Commit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRebaseInteractiveSingleFixup() throws Exception {
|
public void testRebaseInteractiveSingleFixup() throws Exception {
|
||||||
|
@ -2855,7 +2875,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
}
|
}
|
||||||
}).call();
|
}).call();
|
||||||
|
|
||||||
RevWalk walk = new RevWalk(db);
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevCommit headCommit = walk.parseCommit(headId);
|
RevCommit headCommit = walk.parseCommit(headId);
|
||||||
assertEquals("update file2 on master\nnew line",
|
assertEquals("update file2 on master\nnew line",
|
||||||
|
@ -2866,6 +2886,7 @@ public String modifyCommitMessage(String commit) {
|
||||||
assertEquals("Add file2\nnew line",
|
assertEquals("Add file2\nnew line",
|
||||||
head1Commit.getFullMessage());
|
head1Commit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
|
public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
|
||||||
|
@ -2903,12 +2924,13 @@ public String modifyCommitMessage(String commit) {
|
||||||
}
|
}
|
||||||
}).call();
|
}).call();
|
||||||
|
|
||||||
RevWalk walk = new RevWalk(db);
|
try (RevWalk walk = new RevWalk(db)) {
|
||||||
ObjectId headId = db.resolve(Constants.HEAD);
|
ObjectId headId = db.resolve(Constants.HEAD);
|
||||||
RevCommit headCommit = walk.parseCommit(headId);
|
RevCommit headCommit = walk.parseCommit(headId);
|
||||||
assertEquals("Add file2",
|
assertEquals("Add file2",
|
||||||
headCommit.getFullMessage());
|
headCommit.getFullMessage());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = InvalidRebaseStepException.class)
|
@Test(expected = InvalidRebaseStepException.class)
|
||||||
public void testRebaseInteractiveFixupFirstCommitShouldFail()
|
public void testRebaseInteractiveFixupFirstCommitShouldFail()
|
||||||
|
|
|
@ -58,8 +58,7 @@
|
||||||
public class BlameGeneratorTest extends RepositoryTestCase {
|
public class BlameGeneratorTest extends RepositoryTestCase {
|
||||||
@Test
|
@Test
|
||||||
public void testBoundLineDelete() throws Exception {
|
public void testBoundLineDelete() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
String[] content1 = new String[] { "first", "second" };
|
String[] content1 = new String[] { "first", "second" };
|
||||||
writeTrashFile("file.txt", join(content1));
|
writeTrashFile("file.txt", join(content1));
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
|
@ -95,10 +94,11 @@ public void testBoundLineDelete() throws Exception {
|
||||||
assertFalse(generator.next());
|
assertFalse(generator.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testRenamedBoundLineDelete() throws Exception {
|
public void testRenamedBoundLineDelete() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
final String FILENAME_1 = "subdir/file1.txt";
|
final String FILENAME_1 = "subdir/file1.txt";
|
||||||
final String FILENAME_2 = "subdir/file2.txt";
|
final String FILENAME_2 = "subdir/file2.txt";
|
||||||
|
|
||||||
|
@ -162,11 +162,11 @@ public void testRenamedBoundLineDelete() throws Exception {
|
||||||
assertEquals(FILENAME_1, result.getSourcePath(2));
|
assertEquals(FILENAME_1, result.getSourcePath(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLinesAllDeletedShortenedWalk() throws Exception {
|
public void testLinesAllDeletedShortenedWalk() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
|
|
||||||
String[] content1 = new String[] { "first", "second", "third" };
|
String[] content1 = new String[] { "first", "second", "third" };
|
||||||
|
|
||||||
writeTrashFile("file.txt", join(content1));
|
writeTrashFile("file.txt", join(content1));
|
||||||
|
@ -195,6 +195,7 @@ public void testLinesAllDeletedShortenedWalk() throws Exception {
|
||||||
assertFalse(generator.next());
|
assertFalse(generator.next());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static String join(String... lines) {
|
private static String join(String... lines) {
|
||||||
StringBuilder joined = new StringBuilder();
|
StringBuilder joined = new StringBuilder();
|
||||||
|
|
|
@ -77,12 +77,12 @@ public class DiffEntryTest extends RepositoryTestCase {
|
||||||
public void shouldListAddedFileInInitialCommit() throws Exception {
|
public void shouldListAddedFileInInitialCommit() throws Exception {
|
||||||
// given
|
// given
|
||||||
writeTrashFile("a.txt", "content");
|
writeTrashFile("a.txt", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c = git.commit().setMessage("initial commit").call();
|
RevCommit c = git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
walk.addTree(c.getTree());
|
walk.addTree(c.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk);
|
List<DiffEntry> result = DiffEntry.scan(walk);
|
||||||
|
@ -96,18 +96,19 @@ public void shouldListAddedFileInInitialCommit() throws Exception {
|
||||||
assertThat(entry.getNewPath(), is("a.txt"));
|
assertThat(entry.getNewPath(), is("a.txt"));
|
||||||
assertThat(entry.getOldPath(), is(DEV_NULL));
|
assertThat(entry.getOldPath(), is(DEV_NULL));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListAddedFileBetweenTwoCommits() throws Exception {
|
public void shouldListAddedFileBetweenTwoCommits() throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
||||||
writeTrashFile("a.txt", "content");
|
writeTrashFile("a.txt", "content");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c2 = git.commit().setMessage("second commit").call();
|
RevCommit c2 = git.commit().setMessage("second commit").call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk);
|
List<DiffEntry> result = DiffEntry.scan(walk);
|
||||||
|
@ -121,11 +122,13 @@ public void shouldListAddedFileBetweenTwoCommits() throws Exception {
|
||||||
assertThat(entry.getNewPath(), is("a.txt"));
|
assertThat(entry.getNewPath(), is("a.txt"));
|
||||||
assertThat(entry.getOldPath(), is(DEV_NULL));
|
assertThat(entry.getOldPath(), is(DEV_NULL));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListModificationBetweenTwoCommits() throws Exception {
|
public void shouldListModificationBetweenTwoCommits() throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
File file = writeTrashFile("a.txt", "content");
|
File file = writeTrashFile("a.txt", "content");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
||||||
|
@ -134,7 +137,6 @@ public void shouldListModificationBetweenTwoCommits() throws Exception {
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk);
|
List<DiffEntry> result = DiffEntry.scan(walk);
|
||||||
|
@ -147,11 +149,13 @@ public void shouldListModificationBetweenTwoCommits() throws Exception {
|
||||||
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
||||||
assertThat(entry.getNewPath(), is("a.txt"));
|
assertThat(entry.getNewPath(), is("a.txt"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListDeletionBetweenTwoCommits() throws Exception {
|
public void shouldListDeletionBetweenTwoCommits() throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
File file = writeTrashFile("a.txt", "content");
|
File file = writeTrashFile("a.txt", "content");
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
||||||
|
@ -160,7 +164,6 @@ public void shouldListDeletionBetweenTwoCommits() throws Exception {
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk);
|
List<DiffEntry> result = DiffEntry.scan(walk);
|
||||||
|
@ -174,12 +177,14 @@ public void shouldListDeletionBetweenTwoCommits() throws Exception {
|
||||||
assertThat(entry.getNewPath(), is(DEV_NULL));
|
assertThat(entry.getNewPath(), is(DEV_NULL));
|
||||||
assertThat(entry.getChangeType(), is(ChangeType.DELETE));
|
assertThat(entry.getChangeType(), is(ChangeType.DELETE));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListModificationInDirWithoutModifiedTrees()
|
public void shouldListModificationInDirWithoutModifiedTrees()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
File tree = new File(new File(db.getWorkTree(), "a"), "b");
|
File tree = new File(new File(db.getWorkTree(), "a"), "b");
|
||||||
FileUtils.mkdirs(tree);
|
FileUtils.mkdirs(tree);
|
||||||
File file = new File(tree, "c.txt");
|
File file = new File(tree, "c.txt");
|
||||||
|
@ -192,7 +197,6 @@ public void shouldListModificationInDirWithoutModifiedTrees()
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
walk.setRecursive(true);
|
walk.setRecursive(true);
|
||||||
|
@ -206,11 +210,13 @@ public void shouldListModificationInDirWithoutModifiedTrees()
|
||||||
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
||||||
assertThat(entry.getNewPath(), is("a/b/c.txt"));
|
assertThat(entry.getNewPath(), is("a/b/c.txt"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListModificationInDirWithModifiedTrees() throws Exception {
|
public void shouldListModificationInDirWithModifiedTrees() throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
File tree = new File(new File(db.getWorkTree(), "a"), "b");
|
File tree = new File(new File(db.getWorkTree(), "a"), "b");
|
||||||
FileUtils.mkdirs(tree);
|
FileUtils.mkdirs(tree);
|
||||||
File file = new File(tree, "c.txt");
|
File file = new File(tree, "c.txt");
|
||||||
|
@ -223,7 +229,6 @@ public void shouldListModificationInDirWithModifiedTrees() throws Exception {
|
||||||
.call();
|
.call();
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk, true);
|
List<DiffEntry> result = DiffEntry.scan(walk, true);
|
||||||
|
@ -244,18 +249,19 @@ public void shouldListModificationInDirWithModifiedTrees() throws Exception {
|
||||||
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
|
||||||
assertThat(entry.getNewPath(), is("a/b/c.txt"));
|
assertThat(entry.getNewPath(), is("a/b/c.txt"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldListChangesInWorkingTree() throws Exception {
|
public void shouldListChangesInWorkingTree() throws Exception {
|
||||||
// given
|
// given
|
||||||
writeTrashFile("a.txt", "content");
|
writeTrashFile("a.txt", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c = git.commit().setMessage("initial commit").call();
|
RevCommit c = git.commit().setMessage("initial commit").call();
|
||||||
writeTrashFile("b.txt", "new line");
|
writeTrashFile("b.txt", "new line");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c.getTree());
|
walk.addTree(c.getTree());
|
||||||
walk.addTree(new FileTreeIterator(db));
|
walk.addTree(new FileTreeIterator(db));
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk, true);
|
List<DiffEntry> result = DiffEntry.scan(walk, true);
|
||||||
|
@ -267,11 +273,13 @@ public void shouldListChangesInWorkingTree() throws Exception {
|
||||||
assertThat(entry.getChangeType(), is(ChangeType.ADD));
|
assertThat(entry.getChangeType(), is(ChangeType.ADD));
|
||||||
assertThat(entry.getNewPath(), is("b.txt"));
|
assertThat(entry.getNewPath(), is("b.txt"));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldMarkEntriesWhenGivenMarkTreeFilter() throws Exception {
|
public void shouldMarkEntriesWhenGivenMarkTreeFilter() throws Exception {
|
||||||
// given
|
// given
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
||||||
FileUtils.mkdir(new File(db.getWorkTree(), "b"));
|
FileUtils.mkdir(new File(db.getWorkTree(), "b"));
|
||||||
writeTrashFile("a.txt", "a");
|
writeTrashFile("a.txt", "a");
|
||||||
|
@ -286,7 +294,6 @@ public void shouldMarkEntriesWhenGivenMarkTreeFilter() throws Exception {
|
||||||
TreeFilter filterB2 = PathFilterGroup.createFromStrings("b/2.txt");
|
TreeFilter filterB2 = PathFilterGroup.createFromStrings("b/2.txt");
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.addTree(c2.getTree());
|
walk.addTree(c2.getTree());
|
||||||
List<DiffEntry> result = DiffEntry.scan(walk, true, new TreeFilter[] {
|
List<DiffEntry> result = DiffEntry.scan(walk, true, new TreeFilter[] {
|
||||||
|
@ -332,6 +339,7 @@ public void shouldMarkEntriesWhenGivenMarkTreeFilter() throws Exception {
|
||||||
assertFalse(entryC.isMarked(2));
|
assertFalse(entryC.isMarked(2));
|
||||||
assertEquals(0, entryC.getTreeFilterMarks());
|
assertEquals(0, entryC.getTreeFilterMarks());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldThrowIAEWhenTreeWalkHasLessThanTwoTrees()
|
public void shouldThrowIAEWhenTreeWalkHasLessThanTwoTrees()
|
||||||
|
@ -339,10 +347,11 @@ public void shouldThrowIAEWhenTreeWalkHasLessThanTwoTrees()
|
||||||
// given - we don't need anything here
|
// given - we don't need anything here
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
try (TreeWalk walk = new TreeWalk(db)) {
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
DiffEntry.scan(walk);
|
DiffEntry.scan(walk);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldThrowIAEWhenTreeWalkHasMoreThanTwoTrees()
|
public void shouldThrowIAEWhenTreeWalkHasMoreThanTwoTrees()
|
||||||
|
@ -350,12 +359,13 @@ public void shouldThrowIAEWhenTreeWalkHasMoreThanTwoTrees()
|
||||||
// given - we don't need anything here
|
// given - we don't need anything here
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
try (TreeWalk walk = new TreeWalk(db)) {
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
DiffEntry.scan(walk);
|
DiffEntry.scan(walk);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = IllegalArgumentException.class)
|
||||||
public void shouldThrowIAEWhenScanShouldIncludeTreesAndWalkIsRecursive()
|
public void shouldThrowIAEWhenScanShouldIncludeTreesAndWalkIsRecursive()
|
||||||
|
@ -363,28 +373,28 @@ public void shouldThrowIAEWhenScanShouldIncludeTreesAndWalkIsRecursive()
|
||||||
// given - we don't need anything here
|
// given - we don't need anything here
|
||||||
|
|
||||||
// when
|
// when
|
||||||
TreeWalk walk = new TreeWalk(db);
|
try (TreeWalk walk = new TreeWalk(db)) {
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
walk.addTree(new EmptyTreeIterator());
|
walk.addTree(new EmptyTreeIterator());
|
||||||
walk.setRecursive(true);
|
walk.setRecursive(true);
|
||||||
DiffEntry.scan(walk, true);
|
DiffEntry.scan(walk, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReportFileModeChange() throws Exception {
|
public void shouldReportFileModeChange() throws Exception {
|
||||||
writeTrashFile("a.txt", "content");
|
writeTrashFile("a.txt", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
git.add().addFilepattern("a.txt").call();
|
git.add().addFilepattern("a.txt").call();
|
||||||
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
RevCommit c1 = git.commit().setMessage("initial commit").call();
|
||||||
DirCache cache = db.lockDirCache();
|
DirCache cache = db.lockDirCache();
|
||||||
DirCacheEditor editor = cache.editor();
|
DirCacheEditor editor = cache.editor();
|
||||||
final TreeWalk walk = new TreeWalk(db);
|
|
||||||
walk.addTree(c1.getTree());
|
walk.addTree(c1.getTree());
|
||||||
walk.setRecursive(true);
|
walk.setRecursive(true);
|
||||||
assertTrue(walk.next());
|
assertTrue(walk.next());
|
||||||
|
|
||||||
editor.add(new PathEdit("a.txt") {
|
editor.add(new PathEdit("a.txt") {
|
||||||
|
|
||||||
public void apply(DirCacheEntry ent) {
|
public void apply(DirCacheEntry ent) {
|
||||||
ent.setFileMode(FileMode.EXECUTABLE_FILE);
|
ent.setFileMode(FileMode.EXECUTABLE_FILE);
|
||||||
ent.setObjectId(walk.getObjectId(0));
|
ent.setObjectId(walk.getObjectId(0));
|
||||||
|
@ -406,3 +416,4 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertEquals(FileMode.REGULAR_FILE, diff.getOldMode());
|
assertEquals(FileMode.REGULAR_FILE, diff.getOldMode());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -84,7 +84,6 @@
|
||||||
import org.eclipse.jgit.util.FileUtils;
|
import org.eclipse.jgit.util.FileUtils;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class T0003_BasicTest extends SampleDataRepositoryTestCase {
|
public class T0003_BasicTest extends SampleDataRepositoryTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -77,7 +77,6 @@
|
||||||
import org.eclipse.jgit.util.IO;
|
import org.eclipse.jgit.util.IO;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class IndexDiffTest extends RepositoryTestCase {
|
public class IndexDiffTest extends RepositoryTestCase {
|
||||||
|
|
||||||
static PathEdit add(final Repository db, final File workdir,
|
static PathEdit add(final Repository db, final File workdir,
|
||||||
|
|
|
@ -53,7 +53,6 @@
|
||||||
import org.eclipse.jgit.lib.TreeFormatter;
|
import org.eclipse.jgit.lib.TreeFormatter;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public class ObjectWalkTest extends RevWalkTestCase {
|
public class ObjectWalkTest extends RevWalkTestCase {
|
||||||
protected ObjectWalk objw;
|
protected ObjectWalk objw;
|
||||||
|
|
||||||
|
|
|
@ -255,10 +255,11 @@ public void testComputeFileObjectId() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testDirCacheMatchingId() throws Exception {
|
public void testDirCacheMatchingId() throws Exception {
|
||||||
File f = writeTrashFile("file", "content");
|
File f = writeTrashFile("file", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("file", "content");
|
writeTrashFile("file", "content");
|
||||||
fsTick(f);
|
fsTick(f);
|
||||||
git.add().addFilepattern("file").call();
|
git.add().addFilepattern("file").call();
|
||||||
|
}
|
||||||
DirCacheEntry dce = db.readDirCache().getEntry("file");
|
DirCacheEntry dce = db.readDirCache().getEntry("file");
|
||||||
TreeWalk tw = new TreeWalk(db);
|
TreeWalk tw = new TreeWalk(db);
|
||||||
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
|
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
|
||||||
|
@ -282,11 +283,12 @@ public void testDirCacheMatchingId() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testIsModifiedSymlinkAsFile() throws Exception {
|
public void testIsModifiedSymlinkAsFile() throws Exception {
|
||||||
writeTrashFile("symlink", "content");
|
writeTrashFile("symlink", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
db.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null,
|
db.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||||
ConfigConstants.CONFIG_KEY_SYMLINKS, "false");
|
ConfigConstants.CONFIG_KEY_SYMLINKS, "false");
|
||||||
git.add().addFilepattern("symlink").call();
|
git.add().addFilepattern("symlink").call();
|
||||||
git.commit().setMessage("commit").call();
|
git.commit().setMessage("commit").call();
|
||||||
|
}
|
||||||
|
|
||||||
// Modify previously committed DirCacheEntry and write it back to disk
|
// Modify previously committed DirCacheEntry and write it back to disk
|
||||||
DirCacheEntry dce = db.readDirCache().getEntry("symlink");
|
DirCacheEntry dce = db.readDirCache().getEntry("symlink");
|
||||||
|
@ -305,7 +307,7 @@ public void testIsModifiedSymlinkAsFile() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void testIsModifiedFileSmudged() throws Exception {
|
public void testIsModifiedFileSmudged() throws Exception {
|
||||||
File f = writeTrashFile("file", "content");
|
File f = writeTrashFile("file", "content");
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
// The idea of this test is to check the smudged handling
|
// The idea of this test is to check the smudged handling
|
||||||
// Hopefully fsTick will make sure our entry gets smudged
|
// Hopefully fsTick will make sure our entry gets smudged
|
||||||
fsTick(f);
|
fsTick(f);
|
||||||
|
@ -319,6 +321,7 @@ public void testIsModifiedFileSmudged() throws Exception {
|
||||||
// resolution, so we force the index to have the
|
// resolution, so we force the index to have the
|
||||||
// same timestamp as the file we look at.
|
// same timestamp as the file we look at.
|
||||||
db.getIndexFile().setLastModified(lastModified);
|
db.getIndexFile().setLastModified(lastModified);
|
||||||
|
}
|
||||||
DirCacheEntry dce = db.readDirCache().getEntry("file");
|
DirCacheEntry dce = db.readDirCache().getEntry("file");
|
||||||
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
|
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
|
||||||
.getConfig().get(WorkingTreeOptions.KEY));
|
.getConfig().get(WorkingTreeOptions.KEY));
|
||||||
|
@ -334,7 +337,8 @@ public void testIsModifiedFileSmudged() throws Exception {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submoduleHeadMatchesIndex() throws Exception {
|
public void submoduleHeadMatchesIndex() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
final RevCommit id = git.commit().setMessage("create file").call();
|
final RevCommit id = git.commit().setMessage("create file").call();
|
||||||
|
@ -354,7 +358,6 @@ public void apply(DirCacheEntry ent) {
|
||||||
.setDirectory(new File(db.getWorkTree(), path)).call()
|
.setDirectory(new File(db.getWorkTree(), path)).call()
|
||||||
.getRepository().close();
|
.getRepository().close();
|
||||||
|
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
||||||
walk.addTree(indexIter);
|
walk.addTree(indexIter);
|
||||||
|
@ -364,10 +367,12 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertTrue(walk.next());
|
assertTrue(walk.next());
|
||||||
assertTrue(indexIter.idEqual(workTreeIter));
|
assertTrue(indexIter.idEqual(workTreeIter));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submoduleWithNoGitDirectory() throws Exception {
|
public void submoduleWithNoGitDirectory() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
final RevCommit id = git.commit().setMessage("create file").call();
|
final RevCommit id = git.commit().setMessage("create file").call();
|
||||||
|
@ -387,7 +392,6 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertTrue(submoduleRoot.mkdir());
|
assertTrue(submoduleRoot.mkdir());
|
||||||
assertTrue(new File(submoduleRoot, Constants.DOT_GIT).mkdir());
|
assertTrue(new File(submoduleRoot, Constants.DOT_GIT).mkdir());
|
||||||
|
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
||||||
walk.addTree(indexIter);
|
walk.addTree(indexIter);
|
||||||
|
@ -398,10 +402,12 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertFalse(indexIter.idEqual(workTreeIter));
|
assertFalse(indexIter.idEqual(workTreeIter));
|
||||||
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
|
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submoduleWithNoHead() throws Exception {
|
public void submoduleWithNoHead() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
final RevCommit id = git.commit().setMessage("create file").call();
|
final RevCommit id = git.commit().setMessage("create file").call();
|
||||||
|
@ -420,7 +426,6 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path))
|
assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path))
|
||||||
.call().getRepository());
|
.call().getRepository());
|
||||||
|
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
||||||
walk.addTree(indexIter);
|
walk.addTree(indexIter);
|
||||||
|
@ -431,10 +436,12 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertFalse(indexIter.idEqual(workTreeIter));
|
assertFalse(indexIter.idEqual(workTreeIter));
|
||||||
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
|
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submoduleDirectoryIterator() throws Exception {
|
public void submoduleDirectoryIterator() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
final RevCommit id = git.commit().setMessage("create file").call();
|
final RevCommit id = git.commit().setMessage("create file").call();
|
||||||
|
@ -454,7 +461,6 @@ public void apply(DirCacheEntry ent) {
|
||||||
.setDirectory(new File(db.getWorkTree(), path)).call()
|
.setDirectory(new File(db.getWorkTree(), path)).call()
|
||||||
.getRepository().close();
|
.getRepository().close();
|
||||||
|
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db.getWorkTree(),
|
FileTreeIterator workTreeIter = new FileTreeIterator(db.getWorkTree(),
|
||||||
db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY));
|
db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY));
|
||||||
|
@ -465,10 +471,12 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertTrue(walk.next());
|
assertTrue(walk.next());
|
||||||
assertTrue(indexIter.idEqual(workTreeIter));
|
assertTrue(indexIter.idEqual(workTreeIter));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void submoduleNestedWithHeadMatchingIndex() throws Exception {
|
public void submoduleNestedWithHeadMatchingIndex() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk walk = new TreeWalk(db)) {
|
||||||
writeTrashFile("file.txt", "content");
|
writeTrashFile("file.txt", "content");
|
||||||
git.add().addFilepattern("file.txt").call();
|
git.add().addFilepattern("file.txt").call();
|
||||||
final RevCommit id = git.commit().setMessage("create file").call();
|
final RevCommit id = git.commit().setMessage("create file").call();
|
||||||
|
@ -488,7 +496,6 @@ public void apply(DirCacheEntry ent) {
|
||||||
.setDirectory(new File(db.getWorkTree(), path)).call()
|
.setDirectory(new File(db.getWorkTree(), path)).call()
|
||||||
.getRepository().close();
|
.getRepository().close();
|
||||||
|
|
||||||
TreeWalk walk = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
||||||
walk.addTree(indexIter);
|
walk.addTree(indexIter);
|
||||||
|
@ -498,16 +505,17 @@ public void apply(DirCacheEntry ent) {
|
||||||
assertTrue(walk.next());
|
assertTrue(walk.next());
|
||||||
assertTrue(indexIter.idEqual(workTreeIter));
|
assertTrue(indexIter.idEqual(workTreeIter));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void idOffset() throws Exception {
|
public void idOffset() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db);
|
||||||
|
TreeWalk tw = new TreeWalk(db)) {
|
||||||
writeTrashFile("fileAinfsonly", "A");
|
writeTrashFile("fileAinfsonly", "A");
|
||||||
File fileBinindex = writeTrashFile("fileBinindex", "B");
|
File fileBinindex = writeTrashFile("fileBinindex", "B");
|
||||||
fsTick(fileBinindex);
|
fsTick(fileBinindex);
|
||||||
git.add().addFilepattern("fileBinindex").call();
|
git.add().addFilepattern("fileBinindex").call();
|
||||||
writeTrashFile("fileCinfsonly", "C");
|
writeTrashFile("fileCinfsonly", "C");
|
||||||
TreeWalk tw = new TreeWalk(db);
|
|
||||||
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
|
||||||
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
FileTreeIterator workTreeIter = new FileTreeIterator(db);
|
||||||
tw.addTree(indexIter);
|
tw.addTree(indexIter);
|
||||||
|
@ -527,6 +535,7 @@ public void idOffset() throws Exception {
|
||||||
"fileCinfsonly", tw);
|
"fileCinfsonly", tw);
|
||||||
assertFalse(tw.next());
|
assertFalse(tw.next());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void assertEntry(String sha1string, String path, TreeWalk tw)
|
private static void assertEntry(String sha1string, String path, TreeWalk tw)
|
||||||
throws MissingObjectException, IncorrectObjectTypeException,
|
throws MissingObjectException, IncorrectObjectTypeException,
|
||||||
|
|
Loading…
Reference in New Issue