Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Explicitly look up the submodule path in .gitmodules rather than assu…
…ming that the path is the same as the module name. JENKINS-37495
  • Loading branch information
courtarro committed Dec 5, 2016
1 parent 140e8f0 commit a035c00
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -961,6 +961,10 @@ public SubmoduleUpdateCommand timeout(Integer timeout) {
* @throws InterruptedException if called methods throw same exception
*/
public void execute() throws GitException, InterruptedException {
// Initialize the submodules to ensure that the git config
// contains the URLs from .gitmodules.
submoduleInit();

ArgumentListBuilder args = new ArgumentListBuilder();
args.add("submodule", "update");
if (recursive) {
Expand Down Expand Up @@ -1008,16 +1012,18 @@ else if (!referencePath.isDirectory())
Matcher matcher = pattern.matcher(cfgOutput);
while (matcher.find()) {
ArgumentListBuilder perModuleArgs = args.clone();
String sUrl = matcher.group(1);
String sModuleName = matcher.group(1);

// Find the URL for this submodule
URIish urIish = null;
try {
urIish = new URIish(getSubmoduleUrl(sUrl));
urIish = new URIish(getSubmoduleUrl(sModuleName));
} catch (URISyntaxException e) {
listener.error("Invalid repository for " + sUrl);
throw new GitException("Invalid repository for " + sUrl);
listener.error("Invalid repository for " + sModuleName);
throw new GitException("Invalid repository for " + sModuleName);
}

// Find credentials for this URL
StandardCredentials cred = credentials.get(urIish.toPrivateString());
if (parentCredentials) {
String parentUrl = getRemoteUrl(getDefaultRemote());
Expand All @@ -1033,7 +1039,10 @@ else if (!referencePath.isDirectory())
}
if (cred == null) cred = defaultCredentials;

perModuleArgs.add(sUrl);
// Find the path for this submodule
String sModulePath = getSubmodulePath(sModuleName);

perModuleArgs.add(sModulePath);
launchCommandWithCredentials(perModuleArgs, workspace, cred, urIish, timeout);
}
}
Expand Down Expand Up @@ -1095,6 +1104,16 @@ public void setSubmoduleUrl(String name, String url) throws GitException, Interr
launchCommand( "config", "submodule."+name+".url", url );
}

/**
* {@inheritDoc}
*
* Get submodule path
*/
public @CheckForNull String getSubmodulePath(String name) throws GitException, InterruptedException {
String result = launchCommand( "config", "-f", ".gitmodules", "--get", "submodule."+name+".path" );
return StringUtils.trim(firstLine(result));
}

/** {@inheritDoc} */
public @CheckForNull String getRemoteUrl(String name) throws GitException, InterruptedException {
String result = launchCommand( "config", "--get", "remote."+name+".url" );
Expand Down

0 comments on commit a035c00

Please sign in to comment.