我需要在 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/