From c158d5659ede22d8894eb0f1d36335cbbfae9270 Mon Sep 17 00:00:00 2001
From: David
Date: Tue, 5 Aug 2014 11:00:51 -0400
Subject: [PATCH 1/3] Support for a depth parameter in the repo plugin
---
src/main/java/hudson/plugins/repo/RepoScm.java | 17 +++++++++++++++++
.../hudson/plugins/repo/RepoScm/config.jelly | 4 ++++
src/main/webapp/help-depth.html | 7 +++++++
3 files changed, 28 insertions(+)
create mode 100644 src/main/webapp/help-depth.html
diff --git a/src/main/java/hudson/plugins/repo/RepoScm.java b/src/main/java/hudson/plugins/repo/RepoScm.java
index de35507..5dfe892 100644
--- a/src/main/java/hudson/plugins/repo/RepoScm.java
+++ b/src/main/java/hudson/plugins/repo/RepoScm.java
@@ -84,6 +84,7 @@ public class RepoScm extends SCM implements Serializable {
private final String repoUrl;
private final String mirrorDir;
private final int jobs;
+ private final int depth;
private final String localManifest;
private final String destinationDir;
private final boolean currentBranch;
@@ -190,6 +191,14 @@ public int getJobs() {
return jobs;
}
+ /**
+ * Returns the depth used for sync. By default, this is null and repo
+ * will sync the entire history.
+ */
+ @Exported
+ public int getDepth() {
+ return depth;
+ }
/**
* Returns the contents of the local_manifest.xml. By default, this is null
* and a local_manifest.xml is neither created nor modified.
@@ -247,6 +256,9 @@ public boolean isQuiet() {
* @param jobs
* The number of concurrent jobs to use for the sync command. If
* this is 0 or negative the jobs parameter is not specified.
+ * @param depth
+ * This is the depth to use when syncing. By default this is 0
+ * and the full history is synced.
* @param localManifest
* May be null, a string containing XML, or an URL.
* If XML, this string is written to .repo/local_manifest.xml
@@ -269,6 +281,7 @@ public boolean isQuiet() {
public RepoScm(final String manifestRepositoryUrl,
final String manifestBranch, final String manifestFile,
final String manifestGroup, final String mirrorDir, final int jobs,
+ final int depth,
final String localManifest, final String destinationDir,
final String repoUrl,
final boolean currentBranch, final boolean quiet) {
@@ -278,6 +291,7 @@ public RepoScm(final String manifestRepositoryUrl,
this.manifestFile = Util.fixEmptyAndTrim(manifestFile);
this.mirrorDir = Util.fixEmptyAndTrim(mirrorDir);
this.jobs = jobs;
+ this.depth = depth;
this.localManifest = Util.fixEmptyAndTrim(localManifest);
this.destinationDir = Util.fixEmptyAndTrim(destinationDir);
this.currentBranch = currentBranch;
@@ -444,6 +458,9 @@ private boolean checkoutCode(final Launcher launcher,
commands.add("-g");
commands.add(manifestGroup);
}
+ if (depth != 0) {
+ commands.add("--depth=" + depth);
+ }
int returnCode =
launcher.launch().stdout(logger).pwd(workspace)
.cmds(commands).join();
diff --git a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
index de327d1..182bfd1 100644
--- a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
+++ b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
@@ -40,6 +40,10 @@
+
+
+
+
diff --git a/src/main/webapp/help-depth.html b/src/main/webapp/help-depth.html
new file mode 100644
index 0000000..1fed342
--- /dev/null
+++ b/src/main/webapp/help-depth.html
@@ -0,0 +1,7 @@
+
+
+ Specify the depth in history to sync from the source. The default is to sync all of the history.
+ Use 1 to just sync the most recent commit.
+ This is passed to repo as repo init --depth=n
.
+
+
From 4888a6ef1dd7aa730c568c043c16e7e7d47e1e91 Mon Sep 17 00:00:00 2001
From: David
Date: Mon, 11 Aug 2014 10:44:06 -0400
Subject: [PATCH 2/3] option to reset first
---
checkstyle.xml | 2 +-
.../java/hudson/plugins/repo/RepoScm.java | 24 +++++++++++++++++--
.../hudson/plugins/repo/RepoScm/config.jelly | 4 ++++
src/main/webapp/help-resetFirst.html | 5 ++++
4 files changed, 32 insertions(+), 3 deletions(-)
create mode 100644 src/main/webapp/help-resetFirst.html
diff --git a/checkstyle.xml b/checkstyle.xml
index 7da48d6..5285edb 100644
--- a/checkstyle.xml
+++ b/checkstyle.xml
@@ -43,7 +43,7 @@ Checkstyle configuration that checks coding conventions.
-
+
diff --git a/src/main/java/hudson/plugins/repo/RepoScm.java b/src/main/java/hudson/plugins/repo/RepoScm.java
index 5dfe892..8257778 100644
--- a/src/main/java/hudson/plugins/repo/RepoScm.java
+++ b/src/main/java/hudson/plugins/repo/RepoScm.java
@@ -88,6 +88,7 @@ public class RepoScm extends SCM implements Serializable {
private final String localManifest;
private final String destinationDir;
private final boolean currentBranch;
+ private final boolean resetFirst;
private final boolean quiet;
/**
@@ -224,7 +225,11 @@ public String getDestinationDir() {
public boolean isCurrentBranch() {
return currentBranch;
}
-
+ /**
+ * Returns the value of resetFirst.
+ */
+ @Exported
+ public boolean resetFirst() { return resetFirst; }
/**
* Returns the value of quiet.
*/
@@ -273,6 +278,9 @@ public boolean isQuiet() {
* @param currentBranch
* if this value is true,
* add "-c" options when excute "repo sync".
+ * @param resetFirst
+ * if this value is true, do
+ * "repo forall -c 'git reset --hard'" first.
* @param quiet
* if this value is true,
* add "-q" options when excute "repo sync".
@@ -284,7 +292,9 @@ public RepoScm(final String manifestRepositoryUrl,
final int depth,
final String localManifest, final String destinationDir,
final String repoUrl,
- final boolean currentBranch, final boolean quiet) {
+ final boolean currentBranch,
+ final boolean resetFirst,
+ final boolean quiet) {
this.manifestRepositoryUrl = manifestRepositoryUrl;
this.manifestBranch = Util.fixEmptyAndTrim(manifestBranch);
this.manifestGroup = Util.fixEmptyAndTrim(manifestGroup);
@@ -295,6 +305,7 @@ public RepoScm(final String manifestRepositoryUrl,
this.localManifest = Util.fixEmptyAndTrim(localManifest);
this.destinationDir = Util.fixEmptyAndTrim(destinationDir);
this.currentBranch = currentBranch;
+ this.resetFirst = resetFirst;
this.quiet = quiet;
this.repoUrl = Util.fixEmptyAndTrim(repoUrl);
}
@@ -409,6 +420,15 @@ private int doSync(final Launcher launcher, final FilePath workspace,
final List commands = new ArrayList(4);
debug.log(Level.FINE, "Syncing out code in: " + workspace.getName());
commands.clear();
+ if (resetFirst) {
+ commands.add(getDescriptor().getExecutable());
+ commands.add("forall");
+ commands.add("-c");
+ commands.add("git reset --hard");
+ int syncCode = launcher.launch().stdout(logger).pwd(workspace)
+ .cmds(commands).join();
+ commands.clear();
+ }
commands.add(getDescriptor().getExecutable());
commands.add("sync");
commands.add("-d");
diff --git a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
index 182bfd1..9c4e452 100644
--- a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
+++ b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
@@ -48,6 +48,10 @@
+
+
+
+
+ When this is checked the first thing to do will be a
repo forall -c "git reset --hard"
+
+
From 15b9c85527c7e53bdb0cb0bb637b17ffc283abad Mon Sep 17 00:00:00 2001
From: David Warburton
Date: Mon, 29 Sep 2014 12:14:01 -0400
Subject: [PATCH 3/3] Acknowledge failures of repo resetFirst option
---
.../java/hudson/plugins/repo/RepoScm.java | 52 ++++++++++---------
1 file changed, 28 insertions(+), 24 deletions(-)
diff --git a/src/main/java/hudson/plugins/repo/RepoScm.java b/src/main/java/hudson/plugins/repo/RepoScm.java
index 8257778..a81d363 100644
--- a/src/main/java/hudson/plugins/repo/RepoScm.java
+++ b/src/main/java/hudson/plugins/repo/RepoScm.java
@@ -88,7 +88,7 @@ public class RepoScm extends SCM implements Serializable {
private final String localManifest;
private final String destinationDir;
private final boolean currentBranch;
- private final boolean resetFirst;
+ private final boolean resetFirst;
private final boolean quiet;
/**
@@ -116,7 +116,7 @@ private String getManifestBranch(final EnvVars env) {
* Same as {@link #getManifestBranch()} but with default
* values of parameters expanded.
* @param environment an existing environment, which contains already
- * properties from the current build
+ * properties from the current build
* @param project the project that is being built
*/
private String getManifestBranchExpanded(final EnvVars environment,
@@ -129,8 +129,8 @@ private String getManifestBranchExpanded(final EnvVars environment,
for (ParameterDefinition param
: params.getParameterDefinitions()) {
if (param instanceof StringParameterDefinition) {
- final StringParameterDefinition stpd =
- (StringParameterDefinition) param;
+ final StringParameterDefinition stpd =
+ (StringParameterDefinition) param;
final String dflt = stpd.getDefaultValue();
if (dflt != null) {
finalEnv.put(param.getName(), dflt);
@@ -225,11 +225,11 @@ public String getDestinationDir() {
public boolean isCurrentBranch() {
return currentBranch;
}
- /**
- * Returns the value of resetFirst.
- */
- @Exported
- public boolean resetFirst() { return resetFirst; }
+ /**
+ * Returns the value of resetFirst.
+ */
+ @Exported
+ public boolean resetFirst() { return resetFirst; }
/**
* Returns the value of quiet.
*/
@@ -278,9 +278,9 @@ public boolean isQuiet() {
* @param currentBranch
* if this value is true,
* add "-c" options when excute "repo sync".
- * @param resetFirst
- * if this value is true, do
- * "repo forall -c 'git reset --hard'" first.
+ * @param resetFirst
+ * if this value is true, do
+ * "repo forall -c 'git reset --hard'" first.
* @param quiet
* if this value is true,
* add "-q" options when excute "repo sync".
@@ -293,8 +293,8 @@ public RepoScm(final String manifestRepositoryUrl,
final String localManifest, final String destinationDir,
final String repoUrl,
final boolean currentBranch,
- final boolean resetFirst,
- final boolean quiet) {
+ final boolean resetFirst,
+ final boolean quiet) {
this.manifestRepositoryUrl = manifestRepositoryUrl;
this.manifestBranch = Util.fixEmptyAndTrim(manifestBranch);
this.manifestGroup = Util.fixEmptyAndTrim(manifestGroup);
@@ -305,7 +305,7 @@ public RepoScm(final String manifestRepositoryUrl,
this.localManifest = Util.fixEmptyAndTrim(localManifest);
this.destinationDir = Util.fixEmptyAndTrim(destinationDir);
this.currentBranch = currentBranch;
- this.resetFirst = resetFirst;
+ this.resetFirst = resetFirst;
this.quiet = quiet;
this.repoUrl = Util.fixEmptyAndTrim(repoUrl);
}
@@ -420,15 +420,19 @@ private int doSync(final Launcher launcher, final FilePath workspace,
final List commands = new ArrayList(4);
debug.log(Level.FINE, "Syncing out code in: " + workspace.getName());
commands.clear();
- if (resetFirst) {
- commands.add(getDescriptor().getExecutable());
- commands.add("forall");
- commands.add("-c");
- commands.add("git reset --hard");
- int syncCode = launcher.launch().stdout(logger).pwd(workspace)
- .cmds(commands).join();
- commands.clear();
- }
+ if (resetFirst) {
+ commands.add(getDescriptor().getExecutable());
+ commands.add("forall");
+ commands.add("-c");
+ commands.add("git reset --hard");
+ int syncCode = launcher.launch().stdout(logger)
+ .stderr(logger).pwd(workspace).cmds(commands).join();
+
+ if (syncCode != 0) {
+ debug.log(Level.WARNING, "Failed to reset first.");
+ }
+ commands.clear();
+ }
commands.add(getDescriptor().getExecutable());
commands.add("sync");
commands.add("-d");