diff options
Diffstat (limited to 'org.eclipse.jgit.test/tst/org')
7 files changed, 367 insertions, 684 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java index b175ead8ec..f47f447375 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java @@ -13,247 +13,50 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.util.Iterator; - import org.eclipse.jgit.api.Git; import org.eclipse.jgit.blame.BlameGenerator; import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.lib.Constants; -import org.eclipse.jgit.merge.MergeStrategy; -import org.eclipse.jgit.revwalk.FilteredRevCommit; import org.eclipse.jgit.revwalk.RevCommit; -import org.eclipse.jgit.revwalk.RevWalk; import org.junit.Test; /** Unit tests of {@link BlameGenerator}. */ public class BlameGeneratorTest extends RepositoryTestCase { - - public static final String OTHER_FILE = "other_file.txt"; - - public static final String INTERESTING_FILE = "interesting_file.txt"; - @Test - public void testSingleBlame() throws Exception { - - /** - * <pre> - * (ts) OTHER_FILE INTERESTING_FILE - * 1 a - * 2 a, b - * 3 1, 2 c1 <-- - * 4 a, b, c | - * 5 1, 2, 3 c2--- - * </pre> - */ - try (Git git = new Git(db); - RevWalk revWalk = new RevWalk(git.getRepository())) { - writeTrashFile(OTHER_FILE, join("a")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("create file").call(); - - writeTrashFile(OTHER_FILE, join("a", "b")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("amend file").call(); - - writeTrashFile(INTERESTING_FILE, join("1", "2")); - git.add().addFilepattern(INTERESTING_FILE).call(); + public void testBoundLineDelete() throws Exception { + try (Git git = new Git(db)) { + String[] content1 = new String[] { "first", "second" }; + writeTrashFile("file.txt", join(content1)); + git.add().addFilepattern("file.txt").call(); RevCommit c1 = git.commit().setMessage("create file").call(); - writeTrashFile(OTHER_FILE, join("a", "b", "c")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("amend file").call(); - - writeTrashFile(INTERESTING_FILE, join("1", "2", "3")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c2 = git.commit().setMessage("amend file").call(); - - RevCommit filteredC1 = new FilteredRevCommit(c1); - RevCommit filteredC2 = new FilteredRevCommit(c2, filteredC1); - - revWalk.parseHeaders(filteredC2); + String[] content2 = new String[] { "third", "first", "second" }; + writeTrashFile("file.txt", join(content2)); + git.add().addFilepattern("file.txt").call(); + RevCommit c2 = git.commit().setMessage("create file").call(); - try (BlameGenerator generator = new BlameGenerator(db, - INTERESTING_FILE)) { - generator.push(filteredC2); + try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) { + generator.push(null, db.resolve(Constants.HEAD)); assertEquals(3, generator.getResultContents().size()); assertTrue(generator.next()); assertEquals(c2, generator.getSourceCommit()); assertEquals(1, generator.getRegionLength()); - assertEquals(2, generator.getResultStart()); - assertEquals(3, generator.getResultEnd()); - assertEquals(2, generator.getSourceStart()); - assertEquals(3, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); - - assertTrue(generator.next()); - assertEquals(c1, generator.getSourceCommit()); - assertEquals(2, generator.getRegionLength()); assertEquals(0, generator.getResultStart()); - assertEquals(2, generator.getResultEnd()); + assertEquals(1, generator.getResultEnd()); assertEquals(0, generator.getSourceStart()); - assertEquals(2, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); - - assertFalse(generator.next()); - } - } - } - - @Test - public void testMergeSingleBlame() throws Exception { - try (Git git = new Git(db); - RevWalk revWalk = new RevWalk(git.getRepository())) { - - /** - * - * - * <pre> - * refs/heads/master - * A - * / \ refs/heads/side - * / ----------------> side - * / | - * merge <------------------- - * </pre> - */ - - writeTrashFile(INTERESTING_FILE, join("1", "2")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c1 = git.commit().setMessage("create file").call(); - - createBranch(c1, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - writeTrashFile(INTERESTING_FILE, join("1", "2", "3", "4")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit sideCommit = git.commit() - .setMessage("amend file in another branch").call(); - - checkoutBranch("refs/heads/master"); - git.merge().setMessage("merge").include(sideCommit) - .setStrategy(MergeStrategy.RESOLVE).call(); - - Iterator<RevCommit> it = git.log().call().iterator(); - RevCommit mergeCommit = it.next(); - - RevCommit filteredC1 = new FilteredRevCommit(c1); - RevCommit filteredSide = new FilteredRevCommit(sideCommit, - filteredC1); - RevCommit filteredMerge = new FilteredRevCommit(mergeCommit, - filteredSide, filteredC1); - - revWalk.parseHeaders(filteredMerge); - - try (BlameGenerator generator = new BlameGenerator(db, - INTERESTING_FILE)) { - generator.push(filteredMerge); - assertEquals(4, generator.getResultContents().size()); - - assertTrue(generator.next()); - assertEquals(mergeCommit, generator.getSourceCommit()); - assertEquals(2, generator.getRegionLength()); - assertEquals(2, generator.getResultStart()); - assertEquals(4, generator.getResultEnd()); - assertEquals(2, generator.getSourceStart()); - assertEquals(4, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); + assertEquals(1, generator.getSourceEnd()); + assertEquals("file.txt", generator.getSourcePath()); assertTrue(generator.next()); - assertEquals(filteredC1, generator.getSourceCommit()); + assertEquals(c1, generator.getSourceCommit()); assertEquals(2, generator.getRegionLength()); - assertEquals(0, generator.getResultStart()); - assertEquals(2, generator.getResultEnd()); - assertEquals(0, generator.getSourceStart()); - assertEquals(2, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); - - assertFalse(generator.next()); - } - } - } - - @Test - public void testMergeBlame() throws Exception { - try (Git git = new Git(db); - RevWalk revWalk = new RevWalk(git.getRepository())) { - - /** - * - * - * <pre> - * refs/heads/master - * A - * / \ refs/heads/side - * B ----------------> side - * / | - * merge <------------------- - * </pre> - */ - writeTrashFile(INTERESTING_FILE, join("1", "2")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c1 = git.commit().setMessage("create file").call(); - - createBranch(c1, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - writeTrashFile(INTERESTING_FILE, join("1", "2", "3")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit sideCommit = git.commit().setMessage("amend file").call(); - - checkoutBranch("refs/heads/master"); - writeTrashFile(INTERESTING_FILE, join("1", "2", "4")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c2 = git.commit().setMessage("delete and amend file") - .call(); - - git.merge().setMessage("merge").include(sideCommit) - .setStrategy(MergeStrategy.RESOLVE).call(); - writeTrashFile(INTERESTING_FILE, join("1", "2", "3", "4")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit mergeCommit = git.commit().setMessage("merge commit") - .call(); - - RevCommit filteredC1 = new FilteredRevCommit(c1); - RevCommit filteredSide = new FilteredRevCommit(sideCommit, - filteredC1); - RevCommit filteredC2 = new FilteredRevCommit(c2, filteredC1); - - RevCommit filteredMerge = new FilteredRevCommit(mergeCommit, - filteredSide, filteredC2); - - revWalk.parseHeaders(filteredMerge); - - try (BlameGenerator generator = new BlameGenerator(db, - INTERESTING_FILE)) { - generator.push(filteredMerge); - assertEquals(4, generator.getResultContents().size()); - - assertTrue(generator.next()); - assertEquals(filteredC2, generator.getSourceCommit()); - assertEquals(1, generator.getRegionLength()); - assertEquals(3, generator.getResultStart()); - assertEquals(4, generator.getResultEnd()); - assertEquals(2, generator.getSourceStart()); - assertEquals(3, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); - - assertTrue(generator.next()); - assertEquals(filteredSide, generator.getSourceCommit()); - assertEquals(1, generator.getRegionLength()); - assertEquals(2, generator.getResultStart()); + assertEquals(1, generator.getResultStart()); assertEquals(3, generator.getResultEnd()); - assertEquals(2, generator.getSourceStart()); - assertEquals(3, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); - - assertTrue(generator.next()); - assertEquals(filteredC1, generator.getSourceCommit()); - assertEquals(2, generator.getRegionLength()); - assertEquals(0, generator.getResultStart()); - assertEquals(2, generator.getResultEnd()); assertEquals(0, generator.getSourceStart()); assertEquals(2, generator.getSourceEnd()); - assertEquals(INTERESTING_FILE, generator.getSourcePath()); + assertEquals("file.txt", generator.getSourcePath()); assertFalse(generator.next()); } @@ -261,83 +64,6 @@ public class BlameGeneratorTest extends RepositoryTestCase { } @Test - public void testSingleBlame_compareWithWalk() throws Exception { - /** - * <pre> - * (ts) OTHER_FILE INTERESTING_FILE - * 1 a - * 2 a, b - * 3 1, 2 c1 <-- - * 4 a, b, c | - * 6 3, 1, 2 c2--- - * </pre> - */ - try (Git git = new Git(db); - RevWalk revWalk = new RevWalk(git.getRepository())) { - writeTrashFile(OTHER_FILE, join("a")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("create file").call(); - - writeTrashFile(OTHER_FILE, join("a", "b")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("amend file").call(); - - writeTrashFile(INTERESTING_FILE, join("1", "2")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c1 = git.commit().setMessage("create file").call(); - - writeTrashFile(OTHER_FILE, join("a", "b", "c")); - git.add().addFilepattern(OTHER_FILE).call(); - git.commit().setMessage("amend file").call(); - - writeTrashFile(INTERESTING_FILE, join("3", "1", "2")); - git.add().addFilepattern(INTERESTING_FILE).call(); - RevCommit c2 = git.commit().setMessage("prepend").call(); - - RevCommit filteredC1 = new FilteredRevCommit(c1); - RevCommit filteredC2 = new FilteredRevCommit(c2, filteredC1); - - revWalk.parseHeaders(filteredC2); - - try (BlameGenerator g1 = new BlameGenerator(db, INTERESTING_FILE); - BlameGenerator g2 = new BlameGenerator(db, - INTERESTING_FILE)) { - g1.push(null, c2); - g2.push(null, filteredC2); - - assertEquals(g1.getResultContents().size(), - g2.getResultContents().size()); // 3 - - assertTrue(g1.next()); - assertTrue(g2.next()); - - assertEquals(g1.getSourceCommit(), g2.getSourceCommit()); // c2 - assertEquals(INTERESTING_FILE, g1.getSourcePath()); - assertEquals(g1.getRegionLength(), g2.getRegionLength()); // 1 - assertEquals(g1.getResultStart(), g2.getResultStart()); // 0 - assertEquals(g1.getResultEnd(), g2.getResultEnd()); // 1 - assertEquals(g1.getSourceStart(), g2.getSourceStart()); // 0 - assertEquals(g1.getSourceEnd(), g2.getSourceEnd()); // 1 - assertEquals(g1.getSourcePath(), g2.getSourcePath()); // INTERESTING_FILE - - assertTrue(g1.next()); - assertTrue(g2.next()); - - assertEquals(g1.getSourceCommit(), g2.getSourceCommit()); // c1 - assertEquals(g1.getRegionLength(), g2.getRegionLength()); // 2 - assertEquals(g1.getResultStart(), g2.getResultStart()); // 1 - assertEquals(g1.getResultEnd(), g2.getResultEnd()); // 3 - assertEquals(g1.getSourceStart(), g2.getSourceStart()); // 0 - assertEquals(g1.getSourceEnd(), g2.getSourceEnd()); // 2 - assertEquals(g1.getSourcePath(), g2.getSourcePath()); // INTERESTING_FILE - - assertFalse(g1.next()); - assertFalse(g2.next()); - } - } - } - - @Test public void testRenamedBoundLineDelete() throws Exception { try (Git git = new Git(db)) { final String FILENAME_1 = "subdir/file1.txt"; @@ -361,8 +87,7 @@ public class BlameGeneratorTest extends RepositoryTestCase { git.add().addFilepattern(FILENAME_2).call(); RevCommit c2 = git.commit().setMessage("change file2").call(); - try (BlameGenerator generator = new BlameGenerator(db, - FILENAME_2)) { + try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) { generator.push(null, db.resolve(Constants.HEAD)); assertEquals(3, generator.getResultContents().size()); @@ -388,8 +113,7 @@ public class BlameGeneratorTest extends RepositoryTestCase { } // and test again with other BlameGenerator API: - try (BlameGenerator generator = new BlameGenerator(db, - FILENAME_2)) { + try (BlameGenerator generator = new BlameGenerator(db, FILENAME_2)) { generator.push(null, db.resolve(Constants.HEAD)); BlameResult result = generator.computeBlameResult(); @@ -412,22 +136,21 @@ public class BlameGeneratorTest extends RepositoryTestCase { try (Git git = new Git(db)) { String[] content1 = new String[] { "first", "second", "third" }; - writeTrashFile(INTERESTING_FILE, join(content1)); - git.add().addFilepattern(INTERESTING_FILE).call(); + writeTrashFile("file.txt", join(content1)); + git.add().addFilepattern("file.txt").call(); git.commit().setMessage("create file").call(); String[] content2 = new String[] { "" }; - writeTrashFile(INTERESTING_FILE, join(content2)); - git.add().addFilepattern(INTERESTING_FILE).call(); + writeTrashFile("file.txt", join(content2)); + git.add().addFilepattern("file.txt").call(); git.commit().setMessage("create file").call(); - writeTrashFile(INTERESTING_FILE, join(content1)); - git.add().addFilepattern(INTERESTING_FILE).call(); + writeTrashFile("file.txt", join(content1)); + git.add().addFilepattern("file.txt").call(); RevCommit c3 = git.commit().setMessage("create file").call(); - try (BlameGenerator generator = new BlameGenerator(db, - INTERESTING_FILE)) { + try (BlameGenerator generator = new BlameGenerator(db, "file.txt")) { generator.push(null, db.resolve(Constants.HEAD)); assertEquals(3, generator.getResultContents().size()); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SymlinkMergeTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SymlinkMergeTest.java new file mode 100644 index 0000000000..3cdc8da34e --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SymlinkMergeTest.java @@ -0,0 +1,296 @@ +/* + * Copyright (C) 2022 Thomas Wolf <twolf@apache.org> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.merge; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.LinkOption; + +import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.api.MergeResult; +import org.eclipse.jgit.api.MergeResult.MergeStatus; +import org.eclipse.jgit.api.ResetCommand.ResetType; +import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.junit.TestRepository; +import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.lib.Repository; +import org.eclipse.jgit.lib.StoredConfig; +import org.eclipse.jgit.revwalk.RevCommit; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameter; +import org.junit.runners.Parameterized.Parameters; + +/** + * Tests for merges involving symlinks. + */ +@RunWith(Parameterized.class) +public class SymlinkMergeTest extends RepositoryTestCase { + + @Parameters(name = "target={0}, core.symlinks={1}") + public static Object[][] parameters() { + return new Object[][] { + { Target.NONE, Boolean.TRUE }, + { Target.FILE, Boolean.TRUE }, + { Target.DIRECTORY, Boolean.TRUE }, + { Target.NONE, Boolean.FALSE }, + { Target.FILE, Boolean.FALSE }, + { Target.DIRECTORY, Boolean.FALSE }, + }; + } + + public enum Target { + NONE, FILE, DIRECTORY + } + + @Parameter(0) + public Target target; + + @Parameter(1) + public boolean useSymLinks; + + private void setTargets() throws IOException { + switch (target) { + case DIRECTORY: + assertTrue(new File(trash, "target").mkdir()); + assertTrue(new File(trash, "target1").mkdir()); + assertTrue(new File(trash, "target2").mkdir()); + break; + case FILE: + writeTrashFile("target", "t"); + writeTrashFile("target1", "t1"); + writeTrashFile("target2", "t2"); + break; + default: + break; + } + } + + private void checkTargets() throws IOException { + File t = new File(trash, "target"); + File t1 = new File(trash, "target1"); + File t2 = new File(trash, "target2"); + switch (target) { + case DIRECTORY: + assertTrue(t.isDirectory()); + assertTrue(t1.isDirectory()); + assertTrue(t2.isDirectory()); + break; + case FILE: + checkFile(t, "t"); + checkFile(t1, "t1"); + checkFile(t2, "t2"); + break; + default: + assertFalse(Files.exists(t.toPath(), LinkOption.NOFOLLOW_LINKS)); + assertFalse(Files.exists(t1.toPath(), LinkOption.NOFOLLOW_LINKS)); + assertFalse(Files.exists(t2.toPath(), LinkOption.NOFOLLOW_LINKS)); + break; + } + } + + private void assertSymLink(File link, String content) throws Exception { + if (useSymLinks) { + assertTrue(Files.isSymbolicLink(link.toPath())); + assertEquals(content, db.getFS().readSymLink(link)); + } else { + assertFalse(Files.isSymbolicLink(link.toPath())); + assertTrue(link.isFile()); + checkFile(link, content); + } + } + + // Link/link conflict: C git records the conflict but leaves the link in the + // working tree unchanged. + + @Test + public void mergeWithSymlinkConflict() throws Exception { + assumeTrue(db.getFS().supportsSymlinks() || !useSymLinks); + StoredConfig config = db.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_SYMLINKS, useSymLinks); + config.save(); + try (TestRepository<Repository> repo = new TestRepository<>(db)) { + db.incrementOpen(); + // Create the links directly in the git repo, then use a hard reset + // to get them into the workspace. This enables us to run these + // tests also with core.symLinks = false. + RevCommit base = repo + .commit(repo.tree(repo.link("link", repo.blob("target")))); + RevCommit side = repo.commit( + repo.tree(repo.link("link", repo.blob("target1"))), base); + RevCommit head = repo.commit( + repo.tree(repo.link("link", repo.blob("target2"))), base); + try (Git git = new Git(db)) { + setTargets(); + git.reset().setMode(ResetType.HARD).setRef(head.name()).call(); + File link = new File(trash, "link"); + assertSymLink(link, "target2"); + MergeResult result = git.merge().include(side) + .setMessage("merged").call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + // Link should be unmodified + assertSymLink(link, "target2"); + checkTargets(); + assertEquals("[link, mode:120000, stage:1, content:target]" + + "[link, mode:120000, stage:2, content:target2]" + + "[link, mode:120000, stage:3, content:target1]", + indexState(CONTENT)); + } + } + } + + // In file/link conflicts, C git never does a content merge. It records the + // stages in the index, and always puts the file into the workspace. + + @Test + public void mergeWithFileSymlinkConflict() throws Exception { + assumeTrue(db.getFS().supportsSymlinks() || !useSymLinks); + StoredConfig config = db.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_SYMLINKS, useSymLinks); + config.save(); + try (TestRepository<Repository> repo = new TestRepository<>(db)) { + db.incrementOpen(); + RevCommit base = repo.commit(repo.tree()); + RevCommit side = repo.commit( + repo.tree(repo.link("link", repo.blob("target1"))), base); + RevCommit head = repo.commit( + repo.tree(repo.file("link", repo.blob("not a link"))), + base); + try (Git git = new Git(db)) { + setTargets(); + git.reset().setMode(ResetType.HARD).setRef(head.name()).call(); + File link = new File(trash, "link"); + assertFalse(Files.isSymbolicLink(link.toPath())); + checkFile(link, "not a link"); + MergeResult result = git.merge().include(side) + .setMessage("merged").call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + // File should be unmodified + assertFalse(Files.isSymbolicLink(link.toPath())); + checkFile(link, "not a link"); + checkTargets(); + assertEquals("[link, mode:100644, stage:2, content:not a link]" + + "[link, mode:120000, stage:3, content:target1]", + indexState(CONTENT)); + } + } + } + + @Test + public void mergeWithSymlinkFileConflict() throws Exception { + assumeTrue(db.getFS().supportsSymlinks() || !useSymLinks); + StoredConfig config = db.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_SYMLINKS, useSymLinks); + config.save(); + try (TestRepository<Repository> repo = new TestRepository<>(db)) { + db.incrementOpen(); + RevCommit base = repo.commit(repo.tree()); + RevCommit side = repo.commit( + repo.tree(repo.file("link", repo.blob("not a link"))), + base); + RevCommit head = repo.commit( + repo.tree(repo.link("link", repo.blob("target2"))), base); + try (Git git = new Git(db)) { + setTargets(); + git.reset().setMode(ResetType.HARD).setRef(head.name()).call(); + File link = new File(trash, "link"); + assertSymLink(link, "target2"); + MergeResult result = git.merge().include(side) + .setMessage("merged").call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + // Should now be a file! + assertFalse(Files.isSymbolicLink(link.toPath())); + checkFile(link, "not a link"); + checkTargets(); + assertEquals("[link, mode:120000, stage:2, content:target2]" + + "[link, mode:100644, stage:3, content:not a link]", + indexState(CONTENT)); + } + } + } + + // In Delete/modify conflicts with the non-deleted side a link, C git puts + // the link into the working tree. + + @Test + public void mergeWithSymlinkDeleteModify() throws Exception { + assumeTrue(db.getFS().supportsSymlinks() || !useSymLinks); + StoredConfig config = db.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_SYMLINKS, useSymLinks); + config.save(); + try (TestRepository<Repository> repo = new TestRepository<>(db)) { + db.incrementOpen(); + RevCommit base = repo + .commit(repo.tree(repo.link("link", repo.blob("target")))); + RevCommit side = repo.commit( + repo.tree(repo.link("link", repo.blob("target1"))), base); + RevCommit head = repo.commit(repo.tree(), base); + try (Git git = new Git(db)) { + setTargets(); + git.reset().setMode(ResetType.HARD).setRef(head.name()).call(); + File link = new File(trash, "link"); + assertFalse( + Files.exists(link.toPath(), LinkOption.NOFOLLOW_LINKS)); + MergeResult result = git.merge().include(side) + .setMessage("merged").call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + // Link should have the content from side + assertSymLink(link, "target1"); + checkTargets(); + assertEquals("[link, mode:120000, stage:1, content:target]" + + "[link, mode:120000, stage:3, content:target1]", + indexState(CONTENT)); + } + } + } + + @Test + public void mergeWithSymlinkModifyDelete() throws Exception { + assumeTrue(db.getFS().supportsSymlinks() || !useSymLinks); + StoredConfig config = db.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_SYMLINKS, useSymLinks); + config.save(); + try (TestRepository<Repository> repo = new TestRepository<>(db)) { + db.incrementOpen(); + RevCommit base = repo + .commit(repo.tree(repo.link("link", repo.blob("target")))); + RevCommit side = repo.commit(repo.tree(), base); + RevCommit head = repo.commit( + repo.tree(repo.link("link", repo.blob("target2"))), base); + try (Git git = new Git(db)) { + setTargets(); + git.reset().setMode(ResetType.HARD).setRef(head.name()).call(); + File link = new File(trash, "link"); + assertSymLink(link, "target2"); + MergeResult result = git.merge().include(side) + .setMessage("merged").call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + // Link should be unmodified + assertSymLink(link, "target2"); + checkTargets(); + assertEquals("[link, mode:120000, stage:1, content:target]" + + "[link, mode:120000, stage:2, content:target2]", + indexState(CONTENT)); + } + } + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevCommitTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevCommitTest.java deleted file mode 100644 index 49ce47ef42..0000000000 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevCommitTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright (C) 2022, Google LLC. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0 which is available at - * https://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - * - * @since 6.3 - */ -package org.eclipse.jgit.revwalk; - -import static java.nio.charset.StandardCharsets.UTF_8; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertSame; - -import java.util.Arrays; - -import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription; -import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository; -import org.eclipse.jgit.junit.TestRepository; -import org.eclipse.jgit.lib.AnyObjectId; -import org.eclipse.jgit.lib.ObjectLoader; -import org.junit.Before; -import org.junit.Test; - -public class FilteredRevCommitTest { - private TestRepository<InMemoryRepository> tr; - - private RevWalk rw; - - @Before - public void setUp() throws Exception { - tr = new TestRepository<>( - new InMemoryRepository(new DfsRepositoryDescription("test"))); - rw = tr.getRevWalk(); - } - - @Test - public void testParseHeaders_noParent() throws Exception { - RevCommit root = tr.commit().add("todelete", "to be deleted").create(); - RevCommit orig = tr.commit().parent(root).rm("todelete") - .add("foo", "foo contents").add("bar", "bar contents") - .add("dir/baz", "baz contents").create(); - FilteredRevCommit filteredRevCommit = new FilteredRevCommit(orig); - filteredRevCommit.parseHeaders(rw); - tr.branch("master").update(filteredRevCommit); - assertEquals("foo contents", blobAsString(filteredRevCommit, "foo")); - assertEquals("bar contents", blobAsString(filteredRevCommit, "bar")); - assertEquals("baz contents", - blobAsString(filteredRevCommit, "dir/baz")); - } - - @Test - public void testParents() throws Exception { - RevCommit commit1 = tr.commit().add("foo", "foo contents\n").create(); - RevCommit commit2 = tr.commit().parent(commit1) - .message("original message").add("bar", "bar contents") - .create(); - RevCommit commit3 = tr.commit().parent(commit2).message("commit3") - .add("foo", "foo contents\n new line\n").create(); - - FilteredRevCommit filteredCommitHead = new FilteredRevCommit(commit3, - commit1); - - assertEquals(commit1, Arrays.stream(filteredCommitHead.getParents()) - .findFirst().get()); - assertEquals("commit3", filteredCommitHead.getFullMessage()); - assertEquals("foo contents\n new line\n", - blobAsString(filteredCommitHead, "foo")); - assertEquals(filteredCommitHead.getTree(), commit3.getTree()); - - } - - @Test - public void testFlag() throws Exception { - RevCommit root = tr.commit().add("todelete", "to be deleted").create(); - RevCommit orig = tr.commit().parent(root).rm("todelete") - .add("foo", "foo contents").add("bar", "bar contents") - .add("dir/baz", "baz contents").create(); - - FilteredRevCommit filteredRevCommit = new FilteredRevCommit(orig, root); - assertEquals(RevObject.PARSED, orig.flags); - assertEquals(RevObject.PARSED, filteredRevCommit.flags); - } - - @Test - public void testCommitState() throws Exception { - RevCommit root = tr.commit().add("todelete", "to be deleted").create(); - RevCommit orig = tr.commit().parent(root).rm("todelete") - .add("foo", "foo contents").add("bar", "bar contents") - .add("dir/baz", "baz contents").create(); - - FilteredRevCommit filteredRevCommit = new FilteredRevCommit(orig, root); - assertEquals(filteredRevCommit.getParentCount(), 1); - assertSame(filteredRevCommit.getRawBuffer(), orig.getRawBuffer()); - assertSame(filteredRevCommit.getTree(), orig.getTree()); - assertEquals(filteredRevCommit.getFullMessage(), orig.getFullMessage()); - assertEquals(filteredRevCommit.commitTime, orig.commitTime); - assertSame(filteredRevCommit.parents, RevCommit.NO_PARENTS); - } - - @Test - public void testParseCommit_withParents_parsesRealParents() - throws Exception { - RevCommit commit1 = tr.commit().add("foo", "foo contents\n").create(); - RevCommit commit2 = tr.commit().parent(commit1) - .message("original message").add("bar", "bar contents") - .create(); - RevCommit commit3 = tr.commit().parent(commit2).message("commit3") - .add("foo", "foo contents\n new line\n").create(); - - FilteredRevCommit filteredCommitHead = new FilteredRevCommit(commit3, - commit1); - - RevCommit parsedCommit = rw.parseCommit(filteredCommitHead.getId()); - assertEquals(filteredCommitHead.getId(), commit3.getId()); - // This is an intended behavior as revWalk#parseCommit doesn't parse - // through the overridden parents rather uses the real parents. - assertNotEquals( - Arrays.stream(parsedCommit.getParents()).findFirst().get(), - Arrays.stream(filteredCommitHead.getParents()).findFirst() - .get()); - } - - private String blobAsString(AnyObjectId treeish, String path) - throws Exception { - RevObject obj = tr.get(rw.parseTree(treeish), path); - assertSame(RevBlob.class, obj.getClass()); - ObjectLoader loader = rw.getObjectReader().open(obj); - return new String(loader.getCachedBytes(), UTF_8); - } -} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevWalkTest.java deleted file mode 100644 index b1f8c0c0e9..0000000000 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FilteredRevWalkTest.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2022, Google LLC. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Distribution License v. 1.0 which is available at - * https://www.eclipse.org/org/documents/edl-v10.php. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -package org.eclipse.jgit.revwalk; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; - -import org.eclipse.jgit.internal.storage.file.FileRepository; -import org.eclipse.jgit.junit.TestRepository; -import org.junit.Before; -import org.junit.Test; - -public class FilteredRevWalkTest extends RevWalkTestCase { - private TestRepository<FileRepository> repository; - - @Override - @Before - public void setUp() throws Exception { - super.setUp(); - repository = new TestRepository<>(db); - } - - @Test - public void testWalk() throws Exception { - writeTrashFile("a.txt", "content"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c1 = repository.git().commit().setMessage("first commit") - .call(); - - writeTrashFile("b.txt", "new file added"); - repository.git().add().addFilepattern("b.txt").call(); - repository.git().commit().setMessage("second commit").call(); - - writeTrashFile("a.txt", "content added"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c3 = repository.git().commit().setMessage("third commit") - .call(); - - RevWalk revWalk = repository.getRevWalk(); - FilteredRevCommit filteredRevCommit = new FilteredRevCommit(c3, c1); - - revWalk.markStart(filteredRevCommit); - assertEquals(c3, revWalk.next()); - assertEquals(c1, revWalk.next()); - } - - @Test - public void testParseBody() throws Exception { - writeTrashFile("a.txt", "content"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c1 = repository.git().commit().setMessage("first commit") - .call(); - - writeTrashFile("b.txt", "new file added"); - repository.git().add().addFilepattern("b.txt").call(); - repository.git().commit().setMessage("second commit").call(); - - writeTrashFile("a.txt", "content added"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c3 = repository.git().commit().setMessage("third commit") - .call(); - - FilteredRevCommit filteredRevCommit = new FilteredRevCommit(c3, c1); - filteredRevCommit.disposeBody(); - - RevWalk revWalk = repository.getRevWalk(); - - revWalk.parseBody(filteredRevCommit); - assertEquals(filteredRevCommit.getFullMessage(), c3.getFullMessage()); - assertEquals(filteredRevCommit.getShortMessage(), c3.getShortMessage()); - assertEquals(filteredRevCommit.commitTime, c3.commitTime); - assertSame(filteredRevCommit.getTree(), c3.getTree()); - assertSame(filteredRevCommit.parents, RevCommit.NO_PARENTS); - - } - - /** - * Test that the uninteresting flag is carried over correctly. Every commit - * should have the uninteresting flag resulting in a RevWalk returning no - * commit. - * - * @throws Exception - */ - @Test - public void testRevWalkCarryUninteresting() throws Exception { - writeTrashFile("a.txt", "content"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c1 = repository.git().commit().setMessage("first commit") - .call(); - - writeTrashFile("b.txt", "new file added"); - repository.git().add().addFilepattern("b.txt").call(); - RevCommit c2 = repository.git().commit().setMessage("second commit") - .call(); - - writeTrashFile("a.txt", "content added"); - repository.git().add().addFilepattern("a.txt").call(); - RevCommit c3 = repository.git().commit().setMessage("third commit") - .call(); - - RevWalk revWalk = repository.getRevWalk(); - FilteredRevCommit filteredCommit1 = new FilteredRevCommit(c1); - FilteredRevCommit filteredCommit2 = new FilteredRevCommit(c2, - filteredCommit1); - FilteredRevCommit filteredCommit3 = new FilteredRevCommit(c3, - filteredCommit2); - - revWalk.markStart(filteredCommit2); - markUninteresting(filteredCommit3); - assertNull("Found an unexpected commit", rw.next()); - } -} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FirstParentRevWalkTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FirstParentRevWalkTest.java index 146d16953c..c8256b89c0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FirstParentRevWalkTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/FirstParentRevWalkTest.java @@ -12,7 +12,6 @@ package org.eclipse.jgit.revwalk; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.revwalk.filter.MessageRevFilter; @@ -424,41 +423,9 @@ public class FirstParentRevWalkTest extends RevWalkTestCase { rw.sort(RevSort.TOPO, true); rw.setTreeFilter(PathFilterGroup.createFromStrings("0")); markStart(d); - - assertEquals(d, rw.next()); - assertEquals(c, rw.next()); - assertEquals(b, rw.next()); - assertNull(rw.next()); - } - - @Test - public void testWithTopoSortAndTreeFilter_shouldUseFilteredRevCommits() - throws Exception { - RevCommit a = commit(); - RevCommit b = commit(tree(file("0", blob("b"))), a); - RevCommit c = commit(tree(file("0", blob("c"))), b, a); - RevCommit d = commit(tree(file("0", blob("d"))), c); - - rw.reset(); - rw.setFirstParent(true); - rw.sort(RevSort.TOPO, true); - rw.setTreeFilter(PathFilterGroup.createFromStrings("0")); - markStart(d); - - RevCommit x = rw.next(); - assertTrue(x instanceof FilteredRevCommit); - assertEquals(1, x.getParentCount()); - assertEquals(c, x.getParent(0)); - - RevCommit y = rw.next(); - assertTrue(y instanceof FilteredRevCommit); - assertEquals(1, y.getParentCount()); - assertEquals(b, y.getParent(0)); - - RevCommit z = rw.next(); - assertTrue(z instanceof FilteredRevCommit); - assertEquals(0, z.getParentCount()); - + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertCommit(b, rw.next()); assertNull(rw.next()); } @@ -474,8 +441,8 @@ public class FirstParentRevWalkTest extends RevWalkTestCase { rw.sort(RevSort.TOPO, true); rw.setTreeFilter(PathFilterGroup.createFromStrings("0")); markStart(d); - assertEquals(d, rw.next()); - assertEquals(c, rw.next()); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); assertNull(rw.next()); } @@ -491,9 +458,9 @@ public class FirstParentRevWalkTest extends RevWalkTestCase { rw.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER, true); rw.setTreeFilter(PathFilterGroup.createFromStrings("0")); markStart(d); - assertEquals(d, rw.next()); - assertEquals(c, rw.next()); - assertEquals(b, rw.next()); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertCommit(b, rw.next()); assertNull(rw.next()); } @@ -509,8 +476,8 @@ public class FirstParentRevWalkTest extends RevWalkTestCase { rw.sort(RevSort.TOPO_KEEP_BRANCH_TOGETHER, true); rw.setTreeFilter(PathFilterGroup.createFromStrings("0")); markStart(d); - assertEquals(d, rw.next()); - assertEquals(c, rw.next()); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); assertNull(rw.next()); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java index 20478ef709..c62136e64d 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkFollowFilterTest.java @@ -9,7 +9,6 @@ */ package org.eclipse.jgit.revwalk; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import java.util.ArrayList; @@ -56,7 +55,7 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase { final RevCommit a = commit(tree(file("0", blob("0")))); follow("0"); markStart(a); - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertNull(rw.next()); assertNoRenames(); @@ -73,8 +72,8 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase { follow("b"); markStart(renameCommit); - assertEquals(renameCommit, rw.next()); - assertEquals(a, rw.next()); + assertCommit(renameCommit, rw.next()); + assertCommit(a, rw.next()); assertNull(rw.next()); assertRenames("a->b"); @@ -102,10 +101,10 @@ public class RevWalkFollowFilterTest extends RevWalkTestCase { follow("a"); markStart(renameCommit3); - assertEquals(renameCommit3, rw.next()); - assertEquals(renameCommit2, rw.next()); - assertEquals(renameCommit1, rw.next()); - assertEquals(a, rw.next()); + assertCommit(renameCommit3, rw.next()); + assertCommit(renameCommit2, rw.next()); + assertCommit(renameCommit1, rw.next()); + assertCommit(a, rw.next()); assertNull(rw.next()); assertRenames("c->a", "b->c", "a->b"); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java index d933a6fc72..5cce11aa1f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevWalkPathFilter1Test.java @@ -11,7 +11,6 @@ package org.eclipse.jgit.revwalk; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import java.util.Collections; @@ -24,8 +23,8 @@ import org.junit.Test; public class RevWalkPathFilter1Test extends RevWalkTestCase { protected void filter(String path) { - rw.setTreeFilter(AndTreeFilter.create( - PathFilterGroup.createFromStrings(Collections.singleton(path)), + rw.setTreeFilter(AndTreeFilter.create(PathFilterGroup + .createFromStrings(Collections.singleton(path)), TreeFilter.ANY_DIFF)); } @@ -50,7 +49,7 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { final RevCommit a = commit(tree(file("0", blob("0")))); filter("0"); markStart(a); - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertNull(rw.next()); } @@ -73,10 +72,10 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { final RevCommit d = commit(tree(file("0", blob("d"))), c); filter("0"); markStart(d); - assertEquals(d, rw.next()); - assertEquals(c, rw.next()); - assertEquals(b, rw.next()); - assertEquals(a, rw.next()); + assertCommit(d, rw.next()); + assertCommit(c, rw.next()); + assertCommit(b, rw.next()); + assertCommit(a, rw.next()); assertNull(rw.next()); } @@ -88,11 +87,11 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { filter("d/f"); markStart(c); - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(a, c.getParent(0)); // b was skipped + assertCommit(a, c.getParent(0)); // b was skipped - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @@ -107,11 +106,11 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { markStart(c); rw.setRewriteParents(false); - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(b, c.getParent(0)); + assertCommit(b, c.getParent(0)); - assertEquals(a, rw.next()); // b was skipped + assertCommit(a, rw.next()); // b was skipped assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @@ -126,18 +125,18 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { markStart(d); // d was skipped - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(a, c.getParent(0)); // b was skipped + assertCommit(a, c.getParent(0)); // b was skipped - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @Test public void testStringOfPearls_FilePath2_NoParentRewriting() - throws Exception { + throws Exception { final RevCommit a = commit(tree(file("d/f", blob("a")))); final RevCommit b = commit(tree(file("d/f", blob("a"))), a); final RevCommit c = commit(tree(file("d/f", blob("b"))), b); @@ -147,12 +146,12 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { rw.setRewriteParents(false); // d was skipped - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(b, c.getParent(0)); + assertCommit(b, c.getParent(0)); // b was skipped - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @@ -167,11 +166,11 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { markStart(d); // d was skipped - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(a, c.getParent(0)); // b was skipped + assertCommit(a, c.getParent(0)); // b was skipped - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @@ -212,15 +211,15 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { filter("d/f"); markStart(i); - assertEquals(i, rw.next()); + assertCommit(i, rw.next()); assertEquals(1, i.getParentCount()); - assertEquals(c, i.getParent(0)); // h..d was skipped + assertCommit(c, i.getParent(0)); // h..d was skipped - assertEquals(c, rw.next()); + assertCommit(c, rw.next()); assertEquals(1, c.getParentCount()); - assertEquals(a, c.getParent(0)); // b was skipped + assertCommit(a, c.getParent(0)); // b was skipped - assertEquals(a, rw.next()); + assertCommit(a, rw.next()); assertEquals(0, a.getParentCount()); assertNull(rw.next()); } @@ -274,49 +273,4 @@ public class RevWalkPathFilter1Test extends RevWalkTestCase { assertCommit(b, rw.next()); assertCommit(a, rw.next()); } - - @Test - public void testCommitHeaders_rewrittenParents() throws Exception { - final RevCommit a = commit(tree(file("d/f", blob("a")))); - final RevCommit b = commit(tree(file("d/f", blob("a"))), a); - final RevCommit c = commit(tree(file("d/f", blob("b"))), b); - filter("d/f"); - markStart(c); - - RevCommit cBar = rw.next(); - assertNotNull(cBar.getShortMessage()); - assertEquals(cBar.getCommitTime(), c.getCommitTime()); - - RevCommit aBar = rw.next(); - assertNotNull(aBar.getShortMessage()); - assertEquals(aBar.getCommitTime(), a.getCommitTime()); - - assertNull(rw.next()); - } - - @Test - public void testFlags_rewrittenParents() throws Exception { - final RevCommit a = commit(tree(file("d/f", blob("a")))); - final RevCommit b = commit(tree(file("d/f", blob("a"))), a); - final RevCommit c = commit(tree(file("d/f", blob("b"))), b); - - final RevFlag flag1 = rw.newFlag("flag1"); - final RevFlag flag2 = rw.newFlag("flag2"); - - a.add(flag1); - c.add(flag2); - - filter("d/f"); - markStart(c); - - RevCommit cBar = rw.next(); - assertEquals(cBar.flags & RevObject.PARSED, 1); - assertEquals(cBar.flags & flag2.mask, flag2.mask); - - RevCommit aBar = rw.next(); - assertEquals(aBar.flags & RevObject.PARSED, 1); - assertEquals(aBar.flags & flag1.mask, flag1.mask); - - assertNull(rw.next()); - } } |