diff options
author | Konrad Kügler <swamblumat-eclipsebugs@yahoo.de> | 2014-01-12 13:39:18 +0100 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2014-03-10 12:22:57 +0100 |
commit | efd91ef8a7e9d97fab08a6b9a5e181c846b744cb (patch) | |
tree | 6163a9c3c552506a697bba433ed9c5edde789ec0 /org.eclipse.jgit.test | |
parent | 7e258e6468a2bbb357bfb06d4e844cf694325b10 (diff) | |
download | jgit-efd91ef8a7e9d97fab08a6b9a5e181c846b744cb.tar.gz jgit-efd91ef8a7e9d97fab08a6b9a5e181c846b744cb.zip |
Take core.autocrlf into account for blame annotations
Blaming with core.autocrlf set to 'true' - even for freshly checked out
files - showed all lines as being locally modified. For autocrlf = true
the line breaks of the local file will be converted to LF for blaming.
This results in useful diffs and therefor in the desired blame
annotations.
For autocrlf = input no conversion takes place to cope with CRLF line
breaks in the repository, in addition to the usual LF. For autocrlf =
true CRLF line breaks in the repo can't be supported without additional
effort. In that case the whole local file will be blamed as being
locally modified.
Change-Id: If020dcca54d16b2fb79210a070b8480aec82e58e
Signed-off-by: Konrad Kügler <swamblumat-eclipsebugs@yahoo.de>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java index 7b2e85f003..20e93f88c4 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java @@ -45,9 +45,15 @@ package org.eclipse.jgit.api; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import java.io.File; + +import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.blame.BlameResult; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.eclipse.jgit.lib.ConfigConstants; +import org.eclipse.jgit.lib.CoreConfig.AutoCRLF; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.storage.file.FileBasedConfig; import org.junit.Test; /** @@ -325,4 +331,59 @@ public class BlameCommandTest extends RepositoryTestCase { assertEquals(commit3, lines.getSourceCommit(1)); assertEquals(commit3, lines.getSourceCommit(2)); } + + @Test + public void testCoreAutoCrlf1() throws Exception { + testCoreAutoCrlf(AutoCRLF.INPUT, AutoCRLF.FALSE); + } + + @Test + public void testCoreAutoCrlf2() throws Exception { + testCoreAutoCrlf(AutoCRLF.FALSE, AutoCRLF.FALSE); + } + + @Test + public void testCoreAutoCrlf3() throws Exception { + testCoreAutoCrlf(AutoCRLF.INPUT, AutoCRLF.INPUT); + } + + @Test + public void testCoreAutoCrlf4() throws Exception { + testCoreAutoCrlf(AutoCRLF.FALSE, AutoCRLF.INPUT); + } + + @Test + public void testCoreAutoCrlf5() throws Exception { + testCoreAutoCrlf(AutoCRLF.INPUT, AutoCRLF.TRUE); + } + + private void testCoreAutoCrlf(AutoCRLF modeForCommitting, + AutoCRLF modeForReset) throws Exception { + Git git = new Git(db); + FileBasedConfig config = db.getConfig(); + config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForCommitting); + config.save(); + + String joinedCrlf = "a\r\nb\r\nc\r\n"; + File trashFile = writeTrashFile("file.txt", joinedCrlf); + git.add().addFilepattern("file.txt").call(); + RevCommit commit = git.commit().setMessage("create file").call(); + + // re-create file from the repo + trashFile.delete(); + config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, modeForReset); + config.save(); + git.reset().setMode(ResetType.HARD).call(); + + BlameCommand command = new BlameCommand(db); + command.setFilePath("file.txt"); + BlameResult lines = command.call(); + + assertEquals(3, lines.getResultContents().size()); + assertEquals(commit, lines.getSourceCommit(0)); + assertEquals(commit, lines.getSourceCommit(1)); + assertEquals(commit, lines.getSourceCommit(2)); + } } |