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 4, 2017
1 parent 6e13431 commit a809052
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/main/java/hudson/plugins/git/extensions/impl/GitLFSPull.java
@@ -0,0 +1,53 @@
package hudson.plugins.git.extensions.impl;

import hudson.Extension;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.plugins.git.GitException;
import hudson.plugins.git.GitSCM;
import hudson.plugins.git.extensions.GitSCMExtension;
import hudson.plugins.git.extensions.GitSCMExtensionDescriptor;

import org.eclipse.jgit.transport.RemoteConfig;
import org.jenkinsci.plugins.gitclient.CheckoutCommand;
import org.jenkinsci.plugins.gitclient.GitClient;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.List;

/**
* git-lfs-pull after the checkout.
*
* @author Matt Hauck
*/
public class GitLFSPull extends GitSCMExtension {
@DataBoundConstructor
public GitLFSPull() {
}

@Override
public void decorateCheckoutCommand(GitSCM scm, Run<?, ?> build, GitClient git, TaskListener listener, CheckoutCommand cmd) throws IOException, InterruptedException, GitException {
listener.getLogger().println("Enabling Git LFS pull");
List<RemoteConfig> repos = scm.getParamExpandedRepos(build, listener);
// repos should never be empty, but check anyway
if (!repos.isEmpty()) {
// Pull LFS files from the first configured repository.
// Same technique is used in GitSCM and CLoneOption.
// Assumes the passed in scm represents a single repository, or if
// multiple repositories are in use, the first repository in the
// configuration is treated as authoritative.
// Git plugin does not support multiple independent repositories
// in a single job definition.
cmd.lfsRemote(repos.get(0).getName());
}
}

@Extension
public static class DescriptorImpl extends GitSCMExtensionDescriptor {
@Override
public String getDisplayName() {
return "Git LFS pull after checkout";
}
}
}
Expand Up @@ -95,6 +95,11 @@ public CheckoutCommand sparseCheckoutPaths(List<String> sparseCheckoutPaths) {
throw new UnsupportedOperationException("Don't call me");
}

@Override
public CheckoutCommand lfsRemote(String lfsRemote) {
throw new UnsupportedOperationException("Don't call me");
}

@Override
public void execute() throws GitException, InterruptedException {
throw new UnsupportedOperationException("Don't call me");
Expand Down

0 comments on commit a809052

Please sign in to comment.