Skip to content

Commit

Permalink
Merge pull request #151 from pauxus/jgit-references
Browse files Browse the repository at this point in the history
[JENKINS-25387] Allow reference repositories for JGit as well.
  • Loading branch information
MarkEWaite committed Nov 7, 2014
2 parents 6296a9a + 40ff981 commit f330cd9
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 145 deletions.
10 changes: 5 additions & 5 deletions src/main/java/hudson/plugins/git/Branch.java
@@ -1,25 +1,25 @@
package hudson.plugins.git;

import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;

public class Branch extends GitObject {
private static final long serialVersionUID = 1L;

public Branch(String name, ObjectId sha1) {
super(name, sha1);
}

public Branch(Ref candidate) {
super(strip(candidate.getName()), candidate.getObjectId());
}

private static String strip(String name) {
return name.substring(name.indexOf('/', 5) + 1);
}

public @Override String toString() {
return "Branch " + name + "(" + sha1 + ")";
}

}
15 changes: 11 additions & 4 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -400,6 +400,16 @@ public void execute() throws GitException, InterruptedException {
// this allows launchCommandWithCredentials() to pass credentials via a local gitconfig

init_().workspace(workspace.getAbsolutePath()).execute();

if (shared) {
if (reference == null || reference.isEmpty()) {
// we use origin as reference
reference = url;
} else {
listener.getLogger().println("[WARNING] Both shared and reference is used, shared is ignored.");
}
}

if (reference != null && !reference.isEmpty()) {
File referencePath = new File(reference);
if (!referencePath.exists())
Expand Down Expand Up @@ -429,9 +439,6 @@ else if (!referencePath.isDirectory())
}
}

if (shared)
throw new UnsupportedOperationException("shared is unsupported, and considered dangerous");

RefSpec refSpec = new RefSpec("+refs/heads/*:refs/remotes/"+origin+"/*");
fetch_().from(urIish, Collections.singletonList(refSpec))
.shallow(shallow)
Expand Down Expand Up @@ -1324,7 +1331,7 @@ private File getFileFromEnv(String envVar, String suffix) {
if (envValue == null) {
return null;
}
return new File(envValue + suffix);
return new File(envValue + suffix);
}

private File getSSHExeFromGitExeParentDir(String userGitExe) {
Expand Down
@@ -1,6 +1,9 @@
package org.jenkinsci.plugins.gitclient;

/**
* Command to clone a repository. This command behaves differently from CLI clone command, it never actually checks out
* into the workspace.
*
* @author Kohsuke Kawaguchi
*/
public interface CloneCommand extends GitCommand {
Expand All @@ -20,11 +23,13 @@ public interface CloneCommand extends GitCommand {
CloneCommand shared();

CloneCommand reference(String reference);

CloneCommand timeout(Integer timeout);

/**
* When we just need to clone repository without populating the workspace (for instance when sparse checkouts are used)
* When we just need to clone repository without populating the workspace (for instance when sparse checkouts are used).
* This parameter does not do anything, a checkout will never be performed.
*/
@Deprecated
CloneCommand noCheckout();
}

0 comments on commit f330cd9

Please sign in to comment.