summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2016-05-24 16:44:03 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2016-05-24 16:44:03 +0200
commitfc0ec94bc3453b2dc2f5fd7e5728177cdcb32eed (patch)
tree337fb2ca02c41a485cbc5473e75155144db77332 /org.eclipse.jgit.test
parentb4c6a41adc82cd1a7d68e50475a11ca85ee80df6 (diff)
parentffa237e7dbd56df2f28d45113fe0ea03337900f1 (diff)
downloadjgit-fc0ec94bc3453b2dc2f5fd7e5728177cdcb32eed.tar.gz
jgit-fc0ec94bc3453b2dc2f5fd7e5728177cdcb32eed.zip
Merge branch 'stable-4.3' into stable-4.4
* stable-4.3: Fix computation of id in WorkingTreeIterator with autocrlf and smudging Prepare 4.3.2-SNAPSHOT builds JGit v4.3.1.201605051710-r Scan loose ref before packed in case gc about to remove the loose Fix possible NPEs when reporting transport errors Fix calling of clean/smudge filters from Checkout,MergeCommands Fix ApplyCommand when result of patch is an empty file Change-Id: I829f06699f6670e519d04c927bdba4b82df29199 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch7
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage0
-rw-r--r--org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage1
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java10
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java37
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java56
6 files changed, 87 insertions, 24 deletions
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch
new file mode 100644
index 0000000000..cfecb8c5c4
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W.patch
@@ -0,0 +1,7 @@
+diff --git a/W b/W
+index a3648a1..2d44096 100644
+--- a/W
++++ b/W
+@@ -1 +0,0 @@
+-a
+\ No newline at end of file \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PostImage
diff --git a/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage
new file mode 100644
index 0000000000..2e65efe2a1
--- /dev/null
+++ b/org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/W_PreImage
@@ -0,0 +1 @@
+a \ No newline at end of file
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
index 239c844c33..f2b5b3ba95 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java
@@ -147,6 +147,16 @@ public class ApplyCommandTest extends RepositoryTestCase {
}
@Test
+ public void testModifyW() throws Exception {
+ ApplyResult result = init("W");
+ assertEquals(1, result.getUpdatedFiles().size());
+ assertEquals(new File(db.getWorkTree(), "W"),
+ result.getUpdatedFiles().get(0));
+ checkFile(new File(db.getWorkTree(), "W"),
+ b.getString(0, b.size(), false));
+ }
+
+ @Test
public void testModifyX() throws Exception {
ApplyResult result = init("X");
assertEquals(1, result.getUpdatedFiles().size());
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
index 8162ac4575..0bb6610a24 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java
@@ -88,7 +88,6 @@ import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class CheckoutCommandTest extends RepositoryTestCase {
@@ -740,11 +739,9 @@ public class CheckoutCommandTest extends RepositoryTestCase {
}
@Test
- @Ignore
- public void testSmudgeAndClean() throws IOException, GitAPIException {
- // @TODO: fix this test
- File clean_filter = writeTempFile("sed s/V1/@version/g -");
- File smudge_filter = writeTempFile("sed s/@version/V1/g -");
+ public void testSmudgeAndClean() throws Exception {
+ File clean_filter = writeTempFile("sed s/V1/@version/g");
+ File smudge_filter = writeTempFile("sed s/@version/V1/g");
try (Git git2 = new Git(db)) {
StoredConfig config = git.getRepository().getConfig();
@@ -753,33 +750,39 @@ public class CheckoutCommandTest extends RepositoryTestCase {
config.setString("filter", "tstFilter", "clean",
"sh " + slashify(clean_filter.getPath()));
config.save();
- writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
+ writeTrashFile(".gitattributes", "filterTest.txt filter=tstFilter");
git2.add().addFilepattern(".gitattributes").call();
git2.commit().setMessage("add attributes").call();
- writeTrashFile("filterTest.txt", "hello world, V1");
+ fsTick(writeTrashFile("filterTest.txt", "hello world, V1\n"));
git2.add().addFilepattern("filterTest.txt").call();
- git2.commit().setMessage("add filterText.txt").call();
+ RevCommit one = git2.commit().setMessage("add filterText.txt").call();
assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ "[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:hello world, @version\n]",
indexState(CONTENT));
- git2.checkout().setCreateBranch(true).setName("test2").call();
- writeTrashFile("filterTest.txt", "bon giorno world, V1");
+ fsTick(writeTrashFile("filterTest.txt", "bon giorno world, V1\n"));
git2.add().addFilepattern("filterTest.txt").call();
- git2.commit().setMessage("modified filterText.txt").call();
+ RevCommit two = git2.commit().setMessage("modified filterTest.txt").call();
assertTrue(git2.status().call().isClean());
assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]",
+ "[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:bon giorno world, @version\n]",
indexState(CONTENT));
- git2.checkout().setName("refs/heads/test").call();
+ git2.checkout().setName(one.getName()).call();
assertTrue(git2.status().call().isClean());
assertEquals(
- "[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
+ "[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:hello world, @version\n]",
indexState(CONTENT));
- assertEquals("hello world, V1", read("filterTest.txt"));
+ assertEquals("hello world, V1\n", read("filterTest.txt"));
+
+ git2.checkout().setName(two.getName()).call();
+ assertTrue(git2.status().call().isClean());
+ assertEquals(
+ "[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:bon giorno world, @version\n]",
+ indexState(CONTENT));
+ assertEquals("bon giorno world, V1\n", read("filterTest.txt"));
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
index 5dd8da57c2..5f10131750 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/EolRepositoryTest.java
@@ -51,6 +51,7 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.NoFilepatternException;
import org.eclipse.jgit.attributes.Attribute;
import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEditor;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.errors.RevisionSyntaxException;
@@ -61,9 +62,11 @@ import org.eclipse.jgit.lib.CoreConfig.AutoCRLF;
import org.eclipse.jgit.lib.CoreConfig.EOL;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.ObjectLoader;
+import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.util.FS;
import org.eclipse.jgit.util.IO;
import org.junit.Assert;
import org.junit.Test;
@@ -83,6 +86,14 @@ public class EolRepositoryTest extends RepositoryTestCase {
private static final FileMode F = FileMode.REGULAR_FILE;
@DataPoint
+ public static boolean doSmudgeEntries = true;
+
+ @DataPoint
+ public static boolean dontSmudgeEntries = false;
+
+ private boolean smudge;
+
+ @DataPoint
public static String smallContents[] = {
generateTestData(3, 1, true, false),
generateTestData(3, 1, false, true),
@@ -117,10 +128,11 @@ public class EolRepositoryTest extends RepositoryTestCase {
return sb.toString();
}
- public EolRepositoryTest(String[] testContent) {
+ public EolRepositoryTest(String[] testContent, boolean smudgeEntries) {
CONTENT_CRLF = testContent[0];
CONTENT_LF = testContent[1];
CONTENT_MIXED = testContent[2];
+ this.smudge = smudgeEntries;
}
protected String CONTENT_CRLF;
@@ -160,7 +172,7 @@ public class EolRepositoryTest extends RepositoryTestCase {
private ActualEntry entryMixed = new ActualEntry();
- private DirCache dc;
+ private DirCache dirCache;
@Test
public void testDefaultSetup() throws Exception {
@@ -177,7 +189,9 @@ public class EolRepositoryTest extends RepositoryTestCase {
String indexContent) {
assertEquals(fileContent, entry.file);
assertEquals(indexContent, entry.index);
- assertEquals(fileContent.length(), entry.indexContentLength);
+ if (entry.indexContentLength != 0) {
+ assertEquals(fileContent.length(), entry.indexContentLength);
+ }
}
@Test
@@ -584,6 +598,14 @@ public class EolRepositoryTest extends RepositoryTestCase {
dotGitattributes = null;
}
+ fileCRLF = createAndAddFile(git, "file1.txt", "a");
+
+ fileLF = createAndAddFile(git, "file2.txt", "a");
+
+ fileMixed = createAndAddFile(git, "file3.txt", "a");
+
+ RevCommit c = gitCommit(git, "create files");
+
fileCRLF = createAndAddFile(git, "file1.txt", CONTENT_CRLF);
fileLF = createAndAddFile(git, "file2.txt", CONTENT_LF);
@@ -593,6 +615,26 @@ public class EolRepositoryTest extends RepositoryTestCase {
gitCommit(git, "addFiles");
recreateWorktree(git);
+
+ if (smudge) {
+ DirCache dc = DirCache.lock(git.getRepository().getIndexFile(),
+ FS.detect());
+ DirCacheEditor editor = dc.editor();
+ for (int i = 0; i < dc.getEntryCount(); i++) {
+ editor.add(new DirCacheEditor.PathEdit(
+ dc.getEntry(i).getPathString()) {
+ public void apply(DirCacheEntry ent) {
+ ent.smudgeRacilyClean();
+ }
+ });
+ }
+ editor.commit();
+ }
+
+ // @TODO: find out why the following assertion would break the tests
+ // assertTrue(git.status().call().isClean());
+ git.checkout().setName(c.getName()).call();
+ git.checkout().setName("master").call();
}
private void recreateWorktree(Git git)
@@ -610,8 +652,8 @@ public class EolRepositoryTest extends RepositoryTestCase {
gitAdd(git, ".");
}
- protected void gitCommit(Git git, String msg) throws GitAPIException {
- git.commit().setMessage(msg).call();
+ protected RevCommit gitCommit(Git git, String msg) throws GitAPIException {
+ return git.commit().setMessage(msg).call();
}
protected void gitAdd(Git git, String path) throws GitAPIException {
@@ -644,7 +686,7 @@ public class EolRepositoryTest extends RepositoryTestCase {
}
private void collectRepositoryState() throws Exception {
- dc = db.readDirCache();
+ dirCache = db.readDirCache();
walk = beginWalk();
if (dotGitattributes != null)
collectEntryContentAndAttributes(F, ".gitattributes", null);
@@ -680,7 +722,7 @@ public class EolRepositoryTest extends RepositoryTestCase {
e.attrs = e.attrs.trim();
e.file = new String(
IO.readFully(new File(db.getWorkTree(), pathName)));
- DirCacheEntry dce = dc.getEntry(pathName);
+ DirCacheEntry dce = dirCache.getEntry(pathName);
ObjectLoader open = walk.getObjectReader().open(dce.getObjectId());
e.index = new String(open.getBytes());
e.indexContentLength = dce.getLength();