Mercurial > hg > mercurial
changeset 601:d2d9e06ec5d7
TW-28974 use canonical path of repository clone dir
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 03 Jun 2013 15:12:12 +0400 |
parents | 6c480513e5c2 |
children | 18fb51e85f82 |
files | mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java |
diffstat | 2 files changed, 44 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Thu May 30 15:09:10 2013 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactory.java Mon Jun 03 15:12:12 2013 +0400 @@ -7,6 +7,7 @@ import org.jetbrains.annotations.NotNull; import java.io.File; +import java.io.IOException; /** * @author dmitry.neverov @@ -23,21 +24,34 @@ public HgVcsRoot createHgRoot(@NotNull VcsRoot root) throws VcsException { HgVcsRoot hgRoot = new HgVcsRoot(root); String customClonePath = hgRoot.getCustomClonePath(); - if (!StringUtil.isEmptyOrSpaces(customClonePath) && !myDefaultWorkFolderParent.equals(new File(customClonePath).getAbsoluteFile())) { - File parentDir = new File(customClonePath); - createClonedRepositoryParentDir(parentDir); + if (StringUtil.isEmptyOrSpaces(customClonePath)) + return hgRoot; + + File canonicalCustomCloneDir = getCanonicalCustomCloneDir(customClonePath); + if (myDefaultWorkFolderParent.equals(canonicalCustomCloneDir)) + return hgRoot; + + createClonedRepositoryParentDir(canonicalCustomCloneDir); - // take last part of repository path - String repPath = hgRoot.getRepository(); - String[] splitted = repPath.split("[/\\\\]"); - if (splitted.length > 0) { - repPath = splitted[splitted.length-1]; - } + // take last part of repository path + String repPath = hgRoot.getRepository(); + String[] splitted = repPath.split("[/\\\\]"); + if (splitted.length > 0) { + repPath = splitted[splitted.length-1]; + } + + File customWorkingDir = new File(canonicalCustomCloneDir, repPath); + hgRoot.setCustomWorkingDir(customWorkingDir); - File customWorkingDir = new File(parentDir, repPath); - hgRoot.setCustomWorkingDir(customWorkingDir); + return hgRoot; + } + + private File getCanonicalCustomCloneDir(@NotNull String customClonePath) throws VcsException { + try { + return new File(customClonePath).getCanonicalFile(); + } catch (IOException e) { + throw new VcsException("Cannot resolve custom clone path", e); } - return hgRoot; } private void createClonedRepositoryParentDir(final File parentDir) throws VcsException {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Thu May 30 15:09:10 2013 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootFactoryTest.java Mon Jun 03 15:12:12 2013 +0400 @@ -8,9 +8,12 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; +import java.io.File; + import static jetbrains.buildServer.buildTriggers.vcs.mercurial.ServerPluginConfigBuilder.serverPluginConfig; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; import static org.testng.AssertJUnit.assertFalse; +import static org.testng.AssertJUnit.assertNull; @Test public class HgVcsRootFactoryTest { @@ -43,4 +46,19 @@ assertFalse("Custom clone dir contains password", hgRoot.getCustomWorkingDir().getName().contains(password)); } + + @TestFor(issues = "TW-28974") + public void should_use_default_dirs() throws Exception { + TempFiles tmp = new TempFiles(); + File cachesDir = tmp.createTempDir(); + File nonCanonicalCachesDir = new File(cachesDir.getCanonicalPath() + "/../" + cachesDir.getName()); + ServerPluginConfig pluginConfig = serverPluginConfig().cachesDir(cachesDir).build(); + VcsRoot root = vcsRoot() + .withUrl("http://acme.com/repo") + .withCloneRepositoryTo(nonCanonicalCachesDir) + .build(); + HgVcsRoot hgRoot = new HgVcsRootFactory(pluginConfig).createHgRoot(root); + assertNull("Custom working dir is used instead of default one", hgRoot.getCustomWorkingDir()); + } + }