]> source.dussan.org Git - jgit.git/commitdiff
Use the working tree's .gitmodules in SubmoduleWalk.forIndex() 02/6502/4
authorDave Borowitz <dborowitz@google.com>
Mon, 25 Jun 2012 17:46:36 +0000 (10:46 -0700)
committerKevin Sawicki <kevin@github.com>
Mon, 25 Jun 2012 17:46:36 +0000 (10:46 -0700)
This was broken in fe1f1b8f8aba60fdd1ad6f0f72e9c9180978cc60, which
preferred the index over the working tree when both were present.

Change-Id: I97dcf9a088adcbd0187fa7eec9ef34445ce3a981
Signed-off-by: Kevin Sawicki <kevin@github.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleWalkTest.java
org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java

index 0669dd19937c942459d0978236536c23c5ef8c0b..cb3c7d88f0064a4bffa12beaf57456406d43cd3f 100644 (file)
@@ -299,13 +299,13 @@ public class SubmoduleWalkTest extends RepositoryTestCase {
                final Config gitmodules = new Config();
                gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_PATH,
                                "sub");
+               // Different config in the index should be overridden by the working tree.
                gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
-                               "git://example.com/sub");
+                               "git://example.com/bad");
                final RevBlob gitmodulesBlob = testDb.blob(gitmodules.toText());
 
-               // Different config in the working tree.
                gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
-                               "git://example.com/bad");
+                               "git://example.com/sub");
                writeTrashFile(DOT_GIT_MODULES, gitmodules.toText());
 
                DirCache cache = db.lockDirCache();
index 323965f7cc491f368842b5d9f14f2a01c4364b40..e8022b69de6ed600395470199516ce3b7d4b99bf 100644 (file)
@@ -94,8 +94,6 @@ public class SubmoduleWalk {
                try {
                        DirCache index = repository.readDirCache();
                        generator.setTree(new DirCacheIterator(index));
-                       generator.setRootTree(new DirCacheIterator(index));
-                       generator.useWorkingTree = true;
                } catch (IOException e) {
                        generator.release();
                        throw e;
@@ -304,8 +302,6 @@ public class SubmoduleWalk {
 
        private String path;
 
-       private boolean useWorkingTree;
-
        /**
         * Create submodule generator
         *
@@ -388,7 +384,14 @@ public class SubmoduleWalk {
         * @throws ConfigInvalidException
         */
        public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidException {
-               if (rootTree != null) {
+               if (rootTree == null) {
+                       File modulesFile = new File(repository.getWorkTree(),
+                                       Constants.DOT_GIT_MODULES);
+                       FileBasedConfig config = new FileBasedConfig(modulesFile,
+                                       repository.getFS());
+                       config.load();
+                       modulesConfig = config;
+               } else {
                        TreeWalk configWalk = new TreeWalk(repository);
                        try {
                                configWalk.addTree(rootTree);
@@ -411,10 +414,7 @@ public class SubmoduleWalk {
                                                        return this;
                                                }
                                        }
-                                       if (!useWorkingTree) {
-                                               modulesConfig = new Config();
-                                               return this;
-                                       }
+                                       modulesConfig = new Config();
                                } finally {
                                        if (idx > 0)
                                                rootTree.next(idx);
@@ -423,16 +423,6 @@ public class SubmoduleWalk {
                                configWalk.release();
                        }
                }
-               if (repository.isBare()) {
-                       modulesConfig = new Config();
-               } else {
-                       File modulesFile = new File(repository.getWorkTree(),
-                                       Constants.DOT_GIT_MODULES);
-                       FileBasedConfig config = new FileBasedConfig(modulesFile,
-                                       repository.getFS());
-                       config.load();
-                       modulesConfig = config;
-               }
                return this;
        }