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 de35507..a81d363 100644 --- a/src/main/java/hudson/plugins/repo/RepoScm.java +++ b/src/main/java/hudson/plugins/repo/RepoScm.java @@ -84,9 +84,11 @@ 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; + private final boolean resetFirst; private final boolean quiet; /** @@ -114,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, @@ -127,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); @@ -190,6 +192,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. @@ -215,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. */ @@ -247,6 +261,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 @@ -261,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". @@ -269,18 +289,23 @@ 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) { + final boolean currentBranch, + final boolean resetFirst, + final boolean quiet) { this.manifestRepositoryUrl = manifestRepositoryUrl; this.manifestBranch = Util.fixEmptyAndTrim(manifestBranch); this.manifestGroup = Util.fixEmptyAndTrim(manifestGroup); 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; + this.resetFirst = resetFirst; this.quiet = quiet; this.repoUrl = Util.fixEmptyAndTrim(repoUrl); } @@ -395,6 +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) + .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"); @@ -444,6 +482,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..9c4e452 100644 --- a/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly +++ b/src/main/resources/hudson/plugins/repo/RepoScm/config.jelly @@ -40,10 +40,18 @@ + + + + + + + +

+ 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. +

+ diff --git a/src/main/webapp/help-resetFirst.html b/src/main/webapp/help-resetFirst.html new file mode 100644 index 0000000..2443d42 --- /dev/null +++ b/src/main/webapp/help-resetFirst.html @@ -0,0 +1,5 @@ +
+

+ When this is checked the first thing to do will be a

repo forall -c "git reset --hard"
+

+