summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-10-21 22:28:50 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2019-11-15 14:48:44 -0800
commit7a3b93cbedc9c4070c19ee8878adeb8455b61c21 (patch)
treebc381ecba53594b318d1d072d4c59b4f081121d6 /org.eclipse.jgit.test
parent83b9b84e4a09e7c10d4b35cca7987e140cbf68bd (diff)
downloadjgit-7a3b93cbedc9c4070c19ee8878adeb8455b61c21.tar.gz
jgit-7a3b93cbedc9c4070c19ee8878adeb8455b61c21.zip
IndexDiff/SubmoduleWalk: handle submodule.<name>.ignore correctly
IndexDiff would apply ignore mode ALL from .gitmodules to all remaining submodules, and would ignore other settings from .gitignore and always apply the setting defined on the IndexDiff instead. Correct that. In canonical git the ignore setting from .gitmodules can also be overridden by .git/config.[1] Implement that override in SubmoduleWalk. [1] https://git-scm.com/docs/gitmodules#Documentation/gitmodules.txt-submoduleltnamegtignore Bug: 521613 Change-Id: I9199fd447e41c7838924856dce40678370b66395 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
index fa7f5ab522..014a587723 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffSubmoduleTest.java
@@ -60,9 +60,11 @@ import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.internal.storage.file.FileRepository;
import org.eclipse.jgit.junit.JGitTestUtil;
import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.storage.file.FileBasedConfig;
import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.junit.Before;
+import org.junit.Test;
import org.junit.experimental.theories.DataPoints;
import org.junit.experimental.theories.Theories;
import org.junit.experimental.theories.Theory;
@@ -295,4 +297,79 @@ public class IndexDiffSubmoduleTest extends RepositoryTestCase {
indexDiff.getAdded().toString());
}
+ @Test
+ public void testIndexDiffTwoSubmodules() throws Exception {
+ // Create a second submodule
+ try (Repository submodule2 = createWorkRepository()) {
+ JGitTestUtil.writeTrashFile(submodule2, "fileInSubmodule2",
+ "submodule2");
+ Git subGit = Git.wrap(submodule2);
+ subGit.add().addFilepattern("fileInSubmodule2").call();
+ subGit.commit().setMessage("add file to submodule2").call();
+
+ try (Repository sub2 = Git.wrap(db)
+ .submoduleAdd().setPath("modules/submodule2")
+ .setURI(submodule2.getDirectory().toURI().toString())
+ .call()) {
+ writeTrashFile("fileInRoot", "root+");
+ Git rootGit = Git.wrap(db);
+ rootGit.add().addFilepattern("fileInRoot").call();
+ rootGit.commit().setMessage("add submodule2 and root file")
+ .call();
+ // Now change files in both submodules
+ JGitTestUtil.writeTrashFile(submodule_db, "fileInSubmodule",
+ "submodule changed");
+ JGitTestUtil.writeTrashFile(sub2, "fileInSubmodule2",
+ "submodule2 changed");
+ // Set up .gitmodules
+ FileBasedConfig gitmodules = new FileBasedConfig(
+ new File(db.getWorkTree(), Constants.DOT_GIT_MODULES),
+ db.getFS());
+ gitmodules.load();
+ gitmodules.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
+ "modules/submodule", ConfigConstants.CONFIG_KEY_IGNORE,
+ "all");
+ gitmodules.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
+ "modules/submodule2", ConfigConstants.CONFIG_KEY_IGNORE,
+ "none");
+ gitmodules.save();
+ IndexDiff indexDiff = new IndexDiff(db, Constants.HEAD,
+ new FileTreeIterator(db));
+ assertTrue(indexDiff.diff());
+ String[] modified = indexDiff.getModified()
+ .toArray(new String[0]);
+ Arrays.sort(modified);
+ assertEquals("[.gitmodules, modules/submodule2]",
+ Arrays.toString(modified));
+ // Try again with "dirty"
+ gitmodules.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
+ "modules/submodule", ConfigConstants.CONFIG_KEY_IGNORE,
+ "dirty");
+ gitmodules.save();
+ indexDiff = new IndexDiff(db, Constants.HEAD,
+ new FileTreeIterator(db));
+ assertTrue(indexDiff.diff());
+ modified = indexDiff.getModified().toArray(new String[0]);
+ Arrays.sort(modified);
+ assertEquals("[.gitmodules, modules/submodule2]",
+ Arrays.toString(modified));
+ // Test the config override
+ StoredConfig cfg = db.getConfig();
+ cfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
+ "modules/submodule", ConfigConstants.CONFIG_KEY_IGNORE,
+ "none");
+ cfg.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION,
+ "modules/submodule2", ConfigConstants.CONFIG_KEY_IGNORE,
+ "all");
+ cfg.save();
+ indexDiff = new IndexDiff(db, Constants.HEAD,
+ new FileTreeIterator(db));
+ assertTrue(indexDiff.diff());
+ modified = indexDiff.getModified().toArray(new String[0]);
+ Arrays.sort(modified);
+ assertEquals("[.gitmodules, modules/submodule]",
+ Arrays.toString(modified));
+ }
+ }
+ }
}