java - 在 java 测试中获取当前的 git 分支

标签 java git

我需要在 Java 测试中获取当前 Git 分支的名称。可能我可以解析 git status 结果。是否有任何其他方法或现成的代码片段可用?

最佳答案

对我来说很好。

public static String getCurrentGitBranch() throws IOException, InterruptedException {
    Process process = Runtime.getRuntime().exec( "git rev-parse --abbrev-ref HEAD" );
    process.waitFor();

    BufferedReader reader = new BufferedReader(
            new InputStreamReader( process.getInputStream() ) );

    return reader.readLine();
}

关于java - 在 java 测试中获取当前的 git 分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49106104/

相关文章:

java - 访问现有 SQS 队列时抛出 AWS.SimpleQueueService.NonExistentQueue 异常

java - 如何在java中不解析xml获取特定值

git - 使用 git 签名时没有 key

git - 当我 git stash 然后 git stash pop 时,我的更改总是未暂存

git - 使用 capistrano3 部署时写入身份验证套接字时出错

git - 进行一些 git 操作后,我的查找器上出现多个文件重复项

java - Android 从 BaseAdapter 刷新 ListActivity

java - 关于 Spring MVC 与 bootstrap 的问题

java - 如何将Java项目从jar导入到eclipse中?

Git (LFS) : what is locking support? 我应该启用它吗?