feat: branch 列表属性添加 'default',表示是否为默认分支

This commit is contained in:
shizhendong
2024-10-18 15:11:56 +08:00
parent cc5788cf0b
commit d09ab8483c

View File

@@ -126,11 +126,17 @@ public class GitServiceImpl implements IGitService {
File repoDir = this.getRepoDirPath(workspaceId);
try (Git git = this.getGitInstance(repoDir)) {
// List<Ref> call = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
Repository repository = git.getRepository();
String fullBranch = repository.getFullBranch();
String defaultBranch = "main";
if (fullBranch != null && fullBranch.startsWith(LOCAL_BRANCH_PREFIX)) {
defaultBranch = fullBranch.substring(LOCAL_BRANCH_PREFIX.length());
}
// 默认行为,进查询本地分支
List<Ref> call = git.branchList().call();
RevWalk revCommits = new RevWalk(git.getRepository());
RevWalk revCommits = new RevWalk(repository);
for (Ref ref : call) {
String branchName = ref.getName();
@@ -144,6 +150,7 @@ public class GitServiceImpl implements IGitService {
Map<Object, Object> m = T.MapUtil.builder()
.put("name", branchName)
.put("default", T.StrUtil.equals(defaultBranch, branchName))
.build();
RevCommit commit = revCommits.parseCommit(ref.getObjectId());