Skip to content

Commit

Permalink
[FIXED JENKINS-13329] --debug triggered fresh clones rather than upda…
Browse files Browse the repository at this point in the history
…tes.
  • Loading branch information
Jesse Glick committed May 1, 2012
1 parent 7728f3b commit 2dadbc8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 11 additions & 8 deletions src/main/java/hudson/plugins/mercurial/HgExe.java
Expand Up @@ -62,6 +62,7 @@
*/
public class HgExe {
private final ArgumentListBuilder base;
private final ArgumentListBuilder baseNoDebug;
/**
* Environment variables to invoke hg with.
*/
Expand All @@ -77,6 +78,8 @@ public HgExe(MercurialSCM scm, Launcher launcher, AbstractBuild build, TaskListe

public HgExe(MercurialSCM scm, Launcher launcher, Node node, TaskListener listener, EnvVars env) throws IOException, InterruptedException {
base = scm.findHgExe(node, listener, true);
// XXX might be more efficient to have a single call returning ArgumentListBuilder[2]?
baseNoDebug = scm.findHgExe(node, listener, false);
this.node = node;
this.env = env;
this.launcher = launcher;
Expand All @@ -89,24 +92,24 @@ private ProcStarter l(ArgumentListBuilder args) {
return MercurialSCM.launch(launcher).cmds(args).stdout(listener).envs(env);
}

private ArgumentListBuilder seed() {
return base.clone();
private ArgumentListBuilder seed(boolean allowDebug) {
return (allowDebug ? base : baseNoDebug).clone();
}

public ProcStarter pull() {
return run("pull");
}

public ProcStarter clone(String... args) {
return l(seed().add("clone").add(args));
return l(seed(true).add("clone").add(args));
}

public ProcStarter bundleAll(String file) {
return run("bundle","--all",file);
}

public ProcStarter bundle(Collection<String> bases, String file) {
ArgumentListBuilder args = seed().add("bundle");
ArgumentListBuilder args = seed(true).add("bundle");
for (String head : bases) {
args.add("--base", head);
}
Expand All @@ -130,11 +133,11 @@ public ProcStarter cleanAll() {
* Runs arbitrary command.
*/
public ProcStarter run(String... args) {
return l(seed().add(args));
return l(seed(true).add(args));
}

public ProcStarter run(ArgumentListBuilder args) {
return l(seed().add(args.toCommandArray()));
return l(seed(true).add(args.toCommandArray()));
}

/**
Expand Down Expand Up @@ -207,7 +210,7 @@ public String config(FilePath repository, String name) throws IOException, Inter
*/
public String popen(FilePath repository, TaskListener listener, boolean useTimeout, ArgumentListBuilder args)
throws IOException, InterruptedException {
args = seed().add(args.toCommandArray());
args = seed(false).add(args.toCommandArray());

ByteArrayOutputStream rev = new ByteArrayOutputStream();
if (MercurialSCM.joinWithPossibleTimeout(l(args).pwd(repository).stdout(rev), useTimeout, listener) == 0) {
Expand Down Expand Up @@ -237,7 +240,7 @@ synchronized static Capability get(HgExe hg) {
MAP.put(hg.node, m);
}

List<String> hgConfig = hg.base.toList();
List<String> hgConfig = hg.seed(false).toList();
Capability cap = m.get(hgConfig);
if (cap==null)
m.put(hgConfig,cap = new Capability());
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/hudson/plugins/mercurial/MercurialSCMTest.java
Expand Up @@ -41,16 +41,20 @@ void setUp() throws Exception {
repo = createTmpDir();
}

@Bug(13329)
public void testBasicOps() throws Exception {
FreeStyleProject p = createFreeStyleProject();
p.setScm(new MercurialSCM(hgInstallation, repo.getPath(), null, null,
null, null, false));

hg(repo, "init");
touchAndCommit(repo, "a");
buildAndCheck(p, "a"); // this tests the clone op
String log = buildAndCheck(p, "a");
assertTrue(log, log.contains(" clone --"));
touchAndCommit(repo, "b");
buildAndCheck(p, "b"); // this tests the update op
log = buildAndCheck(p, "b");
assertTrue(log, log.contains(" update --"));
assertFalse(log, log.contains(" clone --"));
}

@Bug(4281)
Expand Down

0 comments on commit 2dadbc8

Please sign in to comment.