Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Depth and reset #20

Merged
merged 3 commits into from
Oct 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Checkstyle configuration that checks coding conventions.
<module name="UnusedImports"/>
<module name="MethodLength"/>
<module name="ParameterNumber">
<property name="max" value="12"/>
<property name="max" value="13"/>
</module>
<module name="LineLength">
<property name="tabWidth" value="4"/>
Expand Down
51 changes: 46 additions & 5 deletions src/main/java/hudson/plugins/repo/RepoScm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -114,7 +116,7 @@ private String getManifestBranch(final EnvVars env) {
* Same as {@link #getManifestBranch()} but with <em>default</em>
* 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,
Expand All @@ -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);
Expand Down Expand Up @@ -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.
Expand All @@ -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.
*/
Expand Down Expand Up @@ -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
Expand All @@ -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".
Expand All @@ -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);
}
Expand Down Expand Up @@ -395,6 +420,19 @@ private int doSync(final Launcher launcher, final FilePath workspace,
final List<String> commands = new ArrayList<String>(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");
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions src/main/resources/hudson/plugins/repo/RepoScm/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@
<f:textbox name="repo.jobs" value="${scm.jobs}" clazz="number"/>
</f:entry>

<f:entry title="Depth" help="/plugin/repo/help-depth.html">
<f:textbox name="repo.depth" value="${scm.depth}" clazz="number"/>
</f:entry>

<f:entry title="Current Branch" help="/plugin/repo/help-currentBranch.html">
<f:checkbox name="repo.currentBranch"
checked="${h.defaultToTrue(scm.currentBranch)}" />
</f:entry>
<f:entry title="Reset first" help="/plugin/repo/help-resetFirst.html">
<f:checkbox name="repo.resetFirst"
checked="${h.defaultToFalse(scm.resetFirst)}" />
</f:entry>

<f:entry title="Quiet" help="/plugin/repo/help-quiet.html">
<f:checkbox name="repo.quiet"
Expand Down
7 changes: 7 additions & 0 deletions src/main/webapp/help-depth.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div>
<p>
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 <code>repo init --depth=<i>n</i></code>.
</p>
</div>
5 changes: 5 additions & 0 deletions src/main/webapp/help-resetFirst.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>
When this is checked the first thing to do will be a <pre>repo forall -c "git reset --hard"</pre>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't repo sync -d accomplish the same?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, not quite the same. both "repo sync" and "repo sync -d" will report an error if local uncommitted changes would be lost in the sync.

</p>
</div>