Skip to content

Commit

Permalink
[JENKINS-35687] Add simple git lfs support
Browse files Browse the repository at this point in the history
  • Loading branch information
matthauck authored and creste committed Jan 3, 2017
1 parent 1bc9791 commit e7ddf98
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Expand Up @@ -49,4 +49,11 @@ public interface CheckoutCommand extends GitCommand {
* @return a {@link org.jenkinsci.plugins.gitclient.CheckoutCommand} object.
*/
CheckoutCommand timeout(Integer timeout);

/**
* Enable LFS checkout.
*
* @return a {@link org.jenkinsci.plugins.gitclient.CheckoutCommand} object.
*/
CheckoutCommand withLFS();
}
22 changes: 22 additions & 0 deletions src/main/java/org/jenkinsci/plugins/gitclient/CliGitAPIImpl.java
Expand Up @@ -1962,6 +1962,7 @@ public CheckoutCommand checkout() {
public boolean deleteBranch;
public List<String> sparseCheckoutPaths = Collections.emptyList();
public Integer timeout;
public boolean withLFS;

public CheckoutCommand ref(String ref) {
this.ref = ref;
Expand All @@ -1987,6 +1988,11 @@ public CheckoutCommand timeout(Integer timeout) {
this.timeout = timeout;
return this;
}

public CheckoutCommand withLFS() {
this.withLFS = true;
return this;
}

/* Allow test of index.lock cleanup when checkout is interrupted */
private void interruptThisCheckout() throws InterruptedException {
Expand Down Expand Up @@ -2041,6 +2047,22 @@ public void execute() throws GitException, InterruptedException {
}
args.add(ref);
launchCommandIn(args, workspace, environment, timeout);

if (withLFS) {
final String remote = getDefaultRemote();
final String url = getRemoteUrl(remote);
StandardCredentials cred = credentials.get(url);
if (cred == null) cred = defaultCredentials;
ArgumentListBuilder lfsArgs = new ArgumentListBuilder();
lfsArgs.add("lfs");
lfsArgs.add("pull");
lfsArgs.add(remote);
try {
launchCommandWithCredentials(lfsArgs, workspace, cred, new URIish(url), timeout);
} catch (URISyntaxException e) {
throw new GitException("Invalid URL " + url, e);
}
}
} catch (GitException e) {
if (Pattern.compile("index\\.lock").matcher(e.getMessage()).find()) {
throw new GitLockFailedException("Could not lock repository. Please try again", e);
Expand Down
Expand Up @@ -275,6 +275,12 @@ public CheckoutCommand timeout(Integer timeout) {
return this;
}

@Override
public CheckoutCommand withLFS() {
listener.getLogger().println("[WARNING] JGit doesn't support LFS checkout. This flag is ignored.");
return this;
}

public void execute() throws GitException, InterruptedException {

if(! sparseCheckoutPaths.isEmpty()) {
Expand Down

0 comments on commit e7ddf98

Please sign in to comment.