jGit rev-parse groovy
jGit rev-parse with groovy
我正在尝试从 rev-parse 获取相同的值,但使用的是 jGit 库和 Groovy 脚本。我在文档 jGit 中发现 Link,但它直接来自 Java,如何为 groovy 重建代码?
感谢提示!
@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();
}
}
您显示的代码示例搜索上次提交。如果您想使用 Groovy 脚本实现相同的目的,您必须将此 Java main
方法的主体直接放入 Groovy 脚本 - 它不需要任何 class 用 main
方法来执行。您还必须修复 git.resolve(Constants.HEAD)
- 您正在尝试调用不存在的方法。此方法存在于 Repository
class.
您可以在下面找到一个 Groovy 脚本的示例,它执行与 Java 示例类似的操作:
@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()
}
我使用以下命令将此脚本保存到名为 jgit.groovy
和 运行 的文件中:
groovy jgit.groovy
此脚本的输出类似于:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Recent commit:
commit 8504bf656a945fe199bea60fd1296eef2b083a18 1500237139 ----sp
希望对您有所帮助。
我正在尝试从 rev-parse 获取相同的值,但使用的是 jGit 库和 Groovy 脚本。我在文档 jGit 中发现 Link,但它直接来自 Java,如何为 groovy 重建代码? 感谢提示!
@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();
}
}
您显示的代码示例搜索上次提交。如果您想使用 Groovy 脚本实现相同的目的,您必须将此 Java main
方法的主体直接放入 Groovy 脚本 - 它不需要任何 class 用 main
方法来执行。您还必须修复 git.resolve(Constants.HEAD)
- 您正在尝试调用不存在的方法。此方法存在于 Repository
class.
您可以在下面找到一个 Groovy 脚本的示例,它执行与 Java 示例类似的操作:
@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()
}
我使用以下命令将此脚本保存到名为 jgit.groovy
和 运行 的文件中:
groovy jgit.groovy
此脚本的输出类似于:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Recent commit:
commit 8504bf656a945fe199bea60fd1296eef2b083a18 1500237139 ----sp
希望对您有所帮助。