Skip to content
Permalink
Browse files

[JENKINS-35687] Add simple git lfs support

  • Loading branch information...
matthauck authored and creste committed Jun 14, 2016
1 parent 1bc9791 commit e7ddf98e290de8c38b05807c579359dd1782f7de
@@ -49,4 +49,11 @@
* @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();
}
@@ -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;
@@ -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 {
@@ -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);
@@ -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()) {

0 comments on commit e7ddf98

Please sign in to comment.
You can’t perform that action at this time.