forked from Praqma/config-rotator-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fixed JENKINS-17604] Added remote checkout class for Git
- Loading branch information
1 parent
cd3e805
commit 3612e72
Showing
7 changed files
with
78 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/net/praqma/jenkins/configrotator/scm/git/Checkout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package net.praqma.jenkins.configrotator.scm.git; | ||
|
||
import hudson.FilePath; | ||
import hudson.remoting.VirtualChannel; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.lib.Repository; | ||
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
/** | ||
* @author cwolfgang | ||
*/ | ||
public class Checkout implements FilePath.FileCallable< Boolean> { | ||
|
||
private String commitId; | ||
private String name; | ||
private String branch; | ||
|
||
public Checkout( String name, String branch, String commitId ) { | ||
this.commitId = commitId; | ||
this.name = name; | ||
this.branch = branch; | ||
} | ||
|
||
@Override | ||
public Boolean invoke( File workspace, VirtualChannel channel ) throws IOException, InterruptedException { | ||
|
||
File local = new File( workspace, name ); | ||
|
||
FileRepositoryBuilder builder = new FileRepositoryBuilder(); | ||
Repository repo = builder.setGitDir( new File( local, ".git" ) ).readEnvironment().findGitDir().build(); | ||
org.eclipse.jgit.api.Git git = new org.eclipse.jgit.api.Git( repo ); | ||
|
||
try { | ||
git.checkout().setName( branch ).setAllPaths( true ).setForce( true ).setStartPoint( commitId ).call(); | ||
} catch( GitAPIException e ) { | ||
throw new IOException( e ); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters