1414import hudson .scm .SCM ;
1515import hudson .scm .SCMDescriptor ;
1616import hudson .util .FormValidation ;
17+ import hudson .Util ;
1718
1819import java .io .ByteArrayOutputStream ;
1920import 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 );
0 commit comments