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>
tags/v1.2.0.201112221803-r
Kevin Sawicki 12 years ago
parent
commit
37e4019fd9
1 changed files with 42 additions and 0 deletions
  1. 42
    0
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java

+ 42
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java View File

@@ -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