diff options
author | David Turner <dturner@twosigma.com> | 2017-10-19 16:58:07 -0400 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-12-27 22:55:54 +0100 |
commit | 4bbc74ba407e95954bb444df456d37a21363ce6c (patch) | |
tree | 886bed2177a029dd83ff0dd2eebccc977f6f5e23 | |
parent | 658486386648f186ed8ce934e0abf4d999252a67 (diff) | |
download | jgit-4bbc74ba407e95954bb444df456d37a21363ce6c.tar.gz jgit-4bbc74ba407e95954bb444df456d37a21363ce6c.zip |
Use submodule name instead of path as key in config
When a submodule is moved, the "name" field remains the same, while
the "path" field changes. Git uses the "name" field in .git/config
when a submodule is initialized, so this patch makes JGit do so too.
Change-Id: I48d8e89f706447b860c0162822a8e68170aae42b
Signed-off-by: David Turner <dturner@twosigma.com>
4 files changed, 20 insertions, 12 deletions
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties index dacdd05428..f626724c4e 100644 --- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties +++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties @@ -457,6 +457,7 @@ noMergeBase=No merge base could be determined. Reason={0}. {1} noMergeHeadSpecified=No merge head specified nonBareLinkFilesNotSupported=Link files are not supported with nonbare repos noSuchRef=no such ref +noSuchSubmodule=no such submodule {0} notABoolean=Not a boolean: {0} notABundle=not a bundle notADIRCFile=Not a DIRC file. diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java index acca029835..6af27d704c 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/SubmoduleInitCommand.java @@ -110,16 +110,17 @@ public class SubmoduleInitCommand extends GitCommand<Collection<String>> { continue; String path = generator.getPath(); + String name = generator.getModuleName(); // Copy 'url' and 'update' fields from .gitmodules to config // file String url = generator.getRemoteUrl(); String update = generator.getModulesUpdate(); if (url != null) config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - path, ConfigConstants.CONFIG_KEY_URL, url); + name, ConfigConstants.CONFIG_KEY_URL, url); if (update != null) config.setString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - path, ConfigConstants.CONFIG_KEY_UPDATE, update); + name, ConfigConstants.CONFIG_KEY_UPDATE, update); if (url != null || update != null) initialized.add(path); } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java index 8363122765..5241ea2328 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java @@ -518,6 +518,7 @@ public class JGitText extends TranslationBundle { /***/ public String noMergeHeadSpecified; /***/ public String nonBareLinkFilesNotSupported; /***/ public String noSuchRef; + /***/ public String noSuchSubmodule; /***/ public String notABoolean; /***/ public String notABundle; /***/ public String notADIRCFile; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java index 1d970db948..0e4cd904cd 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/submodule/SubmoduleWalk.java @@ -617,6 +617,15 @@ public class SubmoduleWalk implements AutoCloseable { } /** + * The module name for the current submodule entry (used for the section name of .git/config) + * @since 4.10 + * @return name + */ + public String getModuleName() { + return getModuleName(path); + } + + /** * Get object id of current submodule entry * * @return object id @@ -636,7 +645,7 @@ public class SubmoduleWalk implements AutoCloseable { public String getModulesPath() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - getModuleName(path), ConfigConstants.CONFIG_KEY_PATH); + getModuleName(), ConfigConstants.CONFIG_KEY_PATH); } /** @@ -648,12 +657,8 @@ public class SubmoduleWalk implements AutoCloseable { * @throws java.io.IOException */ public String getConfigUrl() throws IOException, ConfigInvalidException { - // SubmoduleInitCommand copies the submodules.*.url and - // submodules.*.update values from .gitmodules to the config, and - // does so using the path defined in .gitmodules as the subsection - // name. So no path-to-name translation is necessary here. return repoConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - path, ConfigConstants.CONFIG_KEY_URL); + getModuleName(), ConfigConstants.CONFIG_KEY_URL); } /** @@ -667,7 +672,7 @@ public class SubmoduleWalk implements AutoCloseable { public String getModulesUrl() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - getModuleName(path), ConfigConstants.CONFIG_KEY_URL); + getModuleName(), ConfigConstants.CONFIG_KEY_URL); } /** @@ -680,7 +685,7 @@ public class SubmoduleWalk implements AutoCloseable { */ public String getConfigUpdate() throws IOException, ConfigInvalidException { return repoConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - path, ConfigConstants.CONFIG_KEY_UPDATE); + getModuleName(), ConfigConstants.CONFIG_KEY_UPDATE); } /** @@ -694,7 +699,7 @@ public class SubmoduleWalk implements AutoCloseable { public String getModulesUpdate() throws IOException, ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getString(ConfigConstants.CONFIG_SUBMODULE_SECTION, - getModuleName(path), ConfigConstants.CONFIG_KEY_UPDATE); + getModuleName(), ConfigConstants.CONFIG_KEY_UPDATE); } /** @@ -710,7 +715,7 @@ public class SubmoduleWalk implements AutoCloseable { ConfigInvalidException { lazyLoadModulesConfig(); return modulesConfig.getEnum(IgnoreSubmoduleMode.values(), - ConfigConstants.CONFIG_SUBMODULE_SECTION, getModuleName(path), + ConfigConstants.CONFIG_SUBMODULE_SECTION, getModuleName(), ConfigConstants.CONFIG_KEY_IGNORE, IgnoreSubmoduleMode.NONE); } |