Skip to content

Commit

Permalink
[FIXED JENKINS-42278] SCMProbeImpl.stat was returning REGULAR_FILE bu…
Browse files Browse the repository at this point in the history
…t failing rather than return NONEXISTENT.
  • Loading branch information
jglick committed Aug 15, 2017
1 parent fd83e27 commit 4b49070
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/main/java/hudson/plugins/mercurial/MercurialSCMSource.java
Expand Up @@ -446,16 +446,8 @@ public SCMProbeImpl(HgExe hg, FilePath cache, TaskListener listener, MercurialRe
public @Nonnull
SCMProbeStat stat(@Nonnull String path) throws IOException {
try {
String files = hg.popen(cache, listener, true,
new ArgumentListBuilder("locate",
"-r",
revision.getHash(),
"-I",
"path:" + path));
if (StringUtils.isBlank(files)) {
return SCMProbeStat.fromType(SCMFile.Type.NONEXISTENT);
}
return SCMProbeStat.fromType(SCMFile.Type.REGULAR_FILE);
return SCMProbeStat.fromType(hg.run("locate", "-r", revision.getHash(), "-I", "path:" + path).
pwd(cache).join() == 0 ? SCMFile.Type.REGULAR_FILE : SCMFile.Type.NONEXISTENT);
} catch (InterruptedException e) {
throw new IOException(e);
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/hudson/plugins/mercurial/PipelineTest.java
Expand Up @@ -62,6 +62,7 @@
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.jvnet.hudson.test.BuildWatcher;
import org.jvnet.hudson.test.Issue;
import org.jvnet.hudson.test.JenkinsRule;

public class PipelineTest {
Expand Down Expand Up @@ -145,6 +146,7 @@ public class PipelineTest {
assertFalse(iterator.hasNext());
}

@Issue("JENKINS-42278")
@Test public void exactRevisionMercurial() throws Exception {
// TODO mostly pointless to use MercurialContainer here since multibranch requires a caching installation and thus for hg to be installed on master
FilePath sampleRepo = new FilePath(tmp.getRoot());
Expand All @@ -155,12 +157,18 @@ public class PipelineTest {
sampleRepo.child("Jenkinsfile").write("echo hudson.model.Items.XSTREAM2.toXML(scm); semaphore 'wait'; node {checkout scm; echo readFile('file')}", null);
sampleRepo.child("file").write("initial content", null);
m.hg(sampleRepo, "commit", "--addremove", "--message=flow");
m.hg(sampleRepo, "update", "null");
m.hg(sampleRepo, "branch", "docs");
sampleRepo.child("README").write("Just docs here!", null);
m.hg(sampleRepo, "commit", "--message=unrelated branch, not buildable");
m.hg(sampleRepo, "update", "default");
WorkflowMultiBranchProject mp = r.jenkins.createProject(WorkflowMultiBranchProject.class, "p");
String instName = "caching";
r.jenkins.getDescriptorByType(MercurialInstallation.DescriptorImpl.class).setInstallations(
new MercurialInstallation(instName, "", "hg", false, true, false, null, null));
mp.getSourcesList().add(new BranchSource(new MercurialSCMSource(null, instName, sampleRepo.toURI().toString(), null, null, null, null, null, true)));
WorkflowJob p = scheduleAndFindBranchProject(mp, "default");
assertEquals(1, mp.getItems().size());
SemaphoreStep.waitForStart("wait/1", null);
WorkflowRun b1 = p.getLastBuild();
assertNotNull(b1);
Expand Down

0 comments on commit 4b49070

Please sign in to comment.