Use the working tree's .gitmodules in SubmoduleWalk.forIndex()
This was broken in fe1f1b8f8a
, which
preferred the index over the working tree when both were present.
Change-Id: I97dcf9a088adcbd0187fa7eec9ef34445ce3a981
Signed-off-by: Kevin Sawicki <kevin@github.com>
This commit is contained in:
parent
1bf5b9c7a8
commit
2444aa231a
|
@ -299,13 +299,13 @@ public void indexWithGitmodules() throws Exception {
|
||||||
final Config gitmodules = new Config();
|
final Config gitmodules = new Config();
|
||||||
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_PATH,
|
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_PATH,
|
||||||
"sub");
|
"sub");
|
||||||
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
|
// Different config in the index should be overridden by the working tree.
|
||||||
"git://example.com/sub");
|
|
||||||
final RevBlob gitmodulesBlob = testDb.blob(gitmodules.toText());
|
|
||||||
|
|
||||||
// Different config in the working tree.
|
|
||||||
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
|
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
|
||||||
"git://example.com/bad");
|
"git://example.com/bad");
|
||||||
|
final RevBlob gitmodulesBlob = testDb.blob(gitmodules.toText());
|
||||||
|
|
||||||
|
gitmodules.setString(CONFIG_SUBMODULE_SECTION, path, CONFIG_KEY_URL,
|
||||||
|
"git://example.com/sub");
|
||||||
writeTrashFile(DOT_GIT_MODULES, gitmodules.toText());
|
writeTrashFile(DOT_GIT_MODULES, gitmodules.toText());
|
||||||
|
|
||||||
DirCache cache = db.lockDirCache();
|
DirCache cache = db.lockDirCache();
|
||||||
|
|
|
@ -94,8 +94,6 @@ public static SubmoduleWalk forIndex(Repository repository)
|
||||||
try {
|
try {
|
||||||
DirCache index = repository.readDirCache();
|
DirCache index = repository.readDirCache();
|
||||||
generator.setTree(new DirCacheIterator(index));
|
generator.setTree(new DirCacheIterator(index));
|
||||||
generator.setRootTree(new DirCacheIterator(index));
|
|
||||||
generator.useWorkingTree = true;
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
generator.release();
|
generator.release();
|
||||||
throw e;
|
throw e;
|
||||||
|
@ -304,8 +302,6 @@ else if (submoduleUrl.startsWith("../")) {
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
|
|
||||||
private boolean useWorkingTree;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create submodule generator
|
* Create submodule generator
|
||||||
*
|
*
|
||||||
|
@ -388,7 +384,14 @@ public SubmoduleWalk setRootTree(final AnyObjectId id) throws IOException {
|
||||||
* @throws ConfigInvalidException
|
* @throws ConfigInvalidException
|
||||||
*/
|
*/
|
||||||
public SubmoduleWalk loadModulesConfig() throws IOException, 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);
|
TreeWalk configWalk = new TreeWalk(repository);
|
||||||
try {
|
try {
|
||||||
configWalk.addTree(rootTree);
|
configWalk.addTree(rootTree);
|
||||||
|
@ -411,10 +414,7 @@ public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidExcept
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!useWorkingTree) {
|
|
||||||
modulesConfig = new Config();
|
modulesConfig = new Config();
|
||||||
return this;
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
if (idx > 0)
|
if (idx > 0)
|
||||||
rootTree.next(idx);
|
rootTree.next(idx);
|
||||||
|
@ -423,16 +423,6 @@ public SubmoduleWalk loadModulesConfig() throws IOException, ConfigInvalidExcept
|
||||||
configWalk.release();
|
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;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue