Mercurial > hg > mercurial
changeset 370:64cb622b3e89
TW-15591 run hg update with auth params
This solves the problem of updating repository which has hg subrepos
when tracked subrepo revision is changed and subrepo requires
authentication. Svn subrepos still not updated correctly, because
they don't get authentication parameters from hg.
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Wed, 08 Feb 2012 11:32:49 +0400 |
parents | 0b2e9154d26e |
children | 24d926f22e85 |
files | mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java |
diffstat | 2 files changed, 32 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Wed Feb 08 10:43:17 2012 +0400 +++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Wed Feb 08 11:32:49 2012 +0400 @@ -283,14 +283,26 @@ private void doUpdateWorkingDir(@NotNull final File workingDir) throws VcsException { myLogger.message("Updating folder " + workingDir.getAbsolutePath() + " to revision " + myToVersion); - UpdateCommand uc = new UpdateCommand(mySettings, workingDir); - ChangeSet cs = new ChangeSet(myToVersion); - uc.setToId(cs.getId()); - uc.execute(); + UpdateCommand update = new UpdateCommand(mySettings, workingDir); + addUpdateAuthConfigParams(update); + update.setToId(new ChangeSet(myToVersion).getId()); + update.execute(); myLogger.message("Folder successfully updated"); } + private void addUpdateAuthConfigParams(@NotNull UpdateCommand update) { + String username = mySettings.getUsername(); + String password = mySettings.getPassword(); + if (username == null || password == null) + return; + update.withConfig("auth.tc.prefix", "*") + .withConfig("auth.tc.username", username) + .withConfig("auth.tc.password", password) + .withConfig("auth.tc.schemes", "http https"); + } + + private String getDefaultPullUrl(Settings settings, boolean useLocalMirror) throws IOException { if (useLocalMirror) { File mirrorDir = myMirrorManager.getMirrorDir(settings.getRepositoryUrlWithCredentials());
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java Wed Feb 08 10:43:17 2012 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateCommand.java Wed Feb 08 11:32:49 2012 +0400 @@ -20,6 +20,8 @@ import org.jetbrains.annotations.NotNull; import java.io.File; +import java.util.HashMap; +import java.util.Map; import static com.intellij.openapi.util.io.FileUtil.delete; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.command.CommandExecutionSettingsBuilder.with; @@ -29,6 +31,7 @@ private static final int UPDATE_TIMEOUT_SECONDS = 8 * 3600;//8 hours private String myToId; + private final Map<String, String> myConfigParams = new HashMap<String, String>(); public UpdateCommand(@NotNull Settings settings, @NotNull File workingDir) { super(settings, workingDir); @@ -38,10 +41,16 @@ myToId = toId; } + public UpdateCommand withConfig(@NotNull String paramName, @NotNull String paramValue) { + myConfigParams.put(paramName, paramValue); + return this; + } + public void execute() throws VcsException { ensureWorkingDirIsNotLocked(); GeneralCommandLine cli = createCommandLine(); cli.addParameter("update"); + addConfigParams(cli); cli.addParameter("-C"); cli.addParameter("-r"); if (myToId != null) { @@ -58,6 +67,13 @@ delete(lock); } + private void addConfigParams(GeneralCommandLine cmd) { + for (Map.Entry<String, String> entry : myConfigParams.entrySet()) { + cmd.addParameter("--config"); + cmd.addParameter(entry.getKey() + "=" + entry.getValue()); + } + } + @NotNull private File getWorkingDirLock() { return new File(getWorkDirectory(), ".hg" + File.separator + "wlock");