diff options
author | Shawn Pearce <spearce@spearce.org> | 2014-02-14 09:53:48 -0800 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2014-02-18 22:08:07 +0100 |
commit | f2f24a304d7393f5d04c57db627890edae78768b (patch) | |
tree | 4553e9a96f4e4fcb9d6d4dcddf03aef85f8a7492 /org.eclipse.jgit.test/tst/org/eclipse/jgit/diff | |
parent | 2290516ddb5a92ccc296df500aa5e9e30cbc240e (diff) | |
download | jgit-f2f24a304d7393f5d04c57db627890edae78768b.tar.gz jgit-f2f24a304d7393f5d04c57db627890edae78768b.zip |
Fix diff header on renamed or copied files
When git-core renames or copies a file and the mode differs the
header shows the mode change first, then the rename or copy data:
diff --git a/COPYING b/LICENSE
old mode 100644
new mode 100755
similarity index 92%
rename from COPYING
rename to LICENSE
index d645695..54863be
--- a/COPYING
+++ b/LICENSE
@@ -56,20 +56,6 @@
JGit relies on this ordering inside of FileHeader. Parsing "new file
mode NNN" after "copy from/to" or "rename from/to" resets the change
type to be ADD, losing the COPIED or RENAMED status and old path.
This fixes a 4 year old bug in Gerrit Code Review that prevents
opening a file for review if the file was copied from another file,
modified in this change, and the mode was updated (e.g. execute
bit was added).
Change-Id: If4c9ecd61ef0ca8e3e1ea857301f7b5c948efb96
[ms: added test case]
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/diff')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java index 00e5f06747..145d899028 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java @@ -286,6 +286,29 @@ public class DiffFormatterTest extends RepositoryTestCase { } @Test + public void testCreateFileHeaderForRenameModeChange() + throws Exception { + DiffEntry a = DiffEntry.delete(PATH_A, ObjectId.zeroId()); + DiffEntry b = DiffEntry.add(PATH_B, ObjectId.zeroId()); + b.oldMode = FileMode.REGULAR_FILE; + b.newMode = FileMode.EXECUTABLE_FILE; + DiffEntry m = DiffEntry.pair(ChangeType.RENAME, a, b, 100); + m.oldId = null; + m.newId = null; + + FileHeader fh = df.toFileHeader(m); + //@formatter:off + String expected = DIFF + "a/src/a b/src/b\n" + + "old mode 100644\n" + + "new mode 100755\n" + + "similarity index 100%\n" + + "rename from src/a\n" + + "rename to src/b\n"; + //@formatter:on + assertEquals(expected, fh.getScriptText()); + } + + @Test public void testDiff() throws Exception { write(new File(db.getDirectory().getParent(), "test.txt"), "test"); File folder = new File(db.getDirectory().getParent(), "folder"); |