Browse Source

Add blame unit test for file that is renamed twice.

Bug: 354507
Change-Id: I853774ecc1662d095a50a9668431c6e3ce4156c4
Signed-off-by: Kevin Sawicki <kevin@github.com>
Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
stable-1.2
Kevin Sawicki 13 years ago committed by Chris Aniszczyk
parent
commit
37e4019fd9
  1. 42
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java

42
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java

@ -150,6 +150,48 @@ public class BlameCommandTest extends RepositoryTestCase {
assertEquals("file1.txt", lines.getSourcePath(2));
}
@Test
public void testTwoRenames() throws Exception {
Git git = new Git(db);
// Commit 1: Add file.txt
String[] content1 = new String[] { "a" };
writeTrashFile("file.txt", join(content1));
git.add().addFilepattern("file.txt").call();
RevCommit commit1 = git.commit().setMessage("create file").call();
// Commit 2: Rename to file1.txt
writeTrashFile("file1.txt", join(content1));
git.add().addFilepattern("file1.txt").call();
git.rm().addFilepattern("file.txt").call();
git.commit().setMessage("moving file").call();
// Commit 3: Edit file1.txt
String[] content2 = new String[] { "a", "b" };
writeTrashFile("file1.txt", join(content2));
git.add().addFilepattern("file1.txt").call();
RevCommit commit3 = git.commit().setMessage("editing file").call();
// Commit 4: Rename to file2.txt
writeTrashFile("file2.txt", join(content2));
git.add().addFilepattern("file2.txt").call();
git.rm().addFilepattern("file1.txt").call();
git.commit().setMessage("moving file again").call();
BlameCommand command = new BlameCommand(db);
command.setFollowFileRenames(true);
command.setFilePath("file2.txt");
BlameResult lines = command.call();
assertEquals(commit1, lines.getSourceCommit(0));
assertEquals(0, lines.getSourceLine(0));
assertEquals("file.txt", lines.getSourcePath(0));
assertEquals(commit3, lines.getSourceCommit(1));
assertEquals(1, lines.getSourceLine(1));
assertEquals("file1.txt", lines.getSourcePath(1));
}
@Test
public void testDeleteTrailingLines() throws Exception {
Git git = new Git(db);

Loading…
Cancel
Save