jGit rev-parse with groovy -
i'm trying same value rev-parse using jgit library , groovy script. found in documentation jgit link, straight java, how rebuild code groovy ? tips !
@grapes( @grab(group='org.eclipse.jgit', module='org.eclipse.jgit', version='4.8.0.201706111038-r') ) import org.eclipse.jgit.api.*; import org.eclipse.jgit.lib.*; import java.io.ioexception; class revcommit { static void main(string[] args) { git git = git.open( new file( ".git" ) ); objectid head = git.resolve(constants.head); iterable<revcommit> commits = git.log().add(head).setmaxcount(1).call(); } }
the code sample have shown searches last commit. if want achieve same thing using groovy script have put body of java main
method directly groovy script - not need class main
method executed. have fix git.resolve(constants.head)
- trying call method not exist. method exists in repository
class.
below can find example of groovy script similar things java example:
@grab(group='org.eclipse.jgit', module='org.eclipse.jgit', version='4.8.0.201706111038-r') import org.eclipse.jgit.api.* import org.eclipse.jgit.lib.constants import org.eclipse.jgit.lib.objectid import org.eclipse.jgit.revwalk.revcommit git git = git.open(new file(".")) objectid head = git.repository.resolve(constants.head) iterable<revcommit> commits = git.log().add(head).setmaxcount(1).call() println "recent commit:" commits.each { println it.tostring() }
i saved script file called jgit.groovy
, run following command:
groovy jgit.groovy
the output script similar to:
slf4j: failed load class "org.slf4j.impl.staticloggerbinder". slf4j: defaulting no-operation (nop) logger implementation slf4j: see http://www.slf4j.org/codes.html#staticloggerbinder further details. recent commit: commit 8504bf656a945fe199bea60fd1296eef2b083a18 1500237139 ----sp
i hope helps.
wiki
Comments
Post a Comment