Skip to content

Commit 57ed0a2

Browse files
author
Andrew Bayer
committed
Added option to delete workspace before building so we get a fresh clone - hacky, since this breaks other stuff, but I need it for tests right now
1 parent 0129be5 commit 57ed0a2

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/main/java/hudson/plugins/git/GitSCM.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import hudson.scm.SCM;
1515
import hudson.scm.SCMDescriptor;
1616
import hudson.util.FormValidation;
17+
import hudson.Util;
1718

1819
import java.io.ByteArrayOutputStream;
1920
import java.io.File;
@@ -74,6 +75,8 @@ public class GitSCM extends SCM implements Serializable {
7475

7576
private boolean clean;
7677

78+
private boolean wipeOutWorkspace;
79+
7780
private String choosingStrategy = DEFAULT;
7881
public static final String DEFAULT = "Default";
7982
public static final String GERRIT = "Gerrit";
@@ -103,6 +106,7 @@ public GitSCM(
103106
boolean doGenerateSubmoduleConfigurations,
104107
Collection<SubmoduleConfig> submoduleCfg,
105108
boolean clean,
109+
boolean wipeOutWorkspace,
106110
String choosingStrategy, GitWeb browser,
107111
String gitTool) {
108112

@@ -119,6 +123,7 @@ public GitSCM(
119123
this.submoduleCfg = submoduleCfg;
120124

121125
this.clean = clean;
126+
this.wipeOutWorkspace = wipeOutWorkspace;
122127
this.choosingStrategy = choosingStrategy;
123128
this.configVersion = 1L;
124129
this.gitTool = gitTool;
@@ -172,6 +177,10 @@ public GitWeb getBrowser() {
172177
return browser;
173178
}
174179

180+
public boolean getWipeOutWorkspace() {
181+
return this.wipeOutWorkspace;
182+
}
183+
175184
public boolean getClean() {
176185
return this.clean;
177186
}
@@ -489,6 +498,16 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
489498
listener.getLogger().println("Checkout:" + ws.getName() + " / " + ws.getRemote() + " - " + ws.getChannel());
490499
IGitAPI git = new GitAPI(gitExe, ws, listener, environment);
491500

501+
if (wipeOutWorkspace) {
502+
listener.getLogger().println("Wiping out workspace first");
503+
try {
504+
ws.deleteContents();
505+
} catch (InterruptedException e) {
506+
// I don't really care if this fails.
507+
}
508+
509+
}
510+
492511
if (git.hasGitRepo()) {
493512
// It's an update
494513

@@ -499,6 +518,7 @@ public Revision invoke(File localWorkspace, VirtualChannel channel)
499518
}
500519

501520
} else {
521+
502522
listener.getLogger().println("Cloning the remote Git repository");
503523

504524
// Go through the repositories, trying to clone from one
@@ -852,6 +872,7 @@ public SCM newInstance(StaplerRequest req, JSONObject formData) throws FormExcep
852872
req.getParameter("git.generate") != null,
853873
submoduleCfg,
854874
req.getParameter("git.clean") != null,
875+
req.getParameter("git.wipeOutWorkspace") != null,
855876
req.getParameter("git.choosing_strategy"),
856877
gitWeb,
857878
gitTool);

src/main/resources/hudson/plugins/git/GitSCM/config.jelly

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@
119119
<f:entry title="Clean after checkout" help="/plugin/git/clean.html">
120120
<f:checkbox name="git.clean" checked="${scm.clean}" />
121121
</f:entry>
122+
<f:entry title="Wipe out workspace" help="/plugin/git/wipeOutWorkspace.html">
123+
<f:checkbox name="git.wipeOutWorkspace" checked="${scm.wipeOutWorkspace}" />
124+
</f:entry>
125+
122126
<f:entry title="Choosing strategy" help="/plugin/git/choosingStrategy.html" field="git.choosing_strategy">
123127
<select name="git.choosing_strategy">
124128
<j:choose>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<div>
2+
Delete the contents of the workspace before building, ensuring a fully fresh workspace.
3+
</div>

0 commit comments

Comments
 (0)