forked from reposense/RepoSense
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGitBranch.java
More file actions
30 lines (24 loc) · 878 Bytes
/
GitBranch.java
File metadata and controls
30 lines (24 loc) · 878 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package reposense.git;
import static reposense.system.CommandRunner.runCommand;
import java.nio.file.Path;
import java.nio.file.Paths;
import reposense.git.exception.GitBranchException;
import reposense.util.StringsUtil;
/**
* Contains git branch related functionalities.
* Git branch is responsible for list, create, or delete branches.
*/
public class GitBranch {
/**
* Returns the current working branch of the repository at {@code root}.
*/
public static String getCurrentBranch(String root) throws GitBranchException {
Path rootPath = Paths.get(root);
String gitBranchCommand = "git branch";
try {
return StringsUtil.filterText(runCommand(rootPath, gitBranchCommand), "\\* (.*)").split("\\*")[1].trim();
} catch (RuntimeException rte) {
throw new GitBranchException(rte);
}
}
}