Skip to content

Commit abee927

Browse files
committed
Fix broken when no commits and default branch is not master
1 parent 668718c commit abee927

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

modules/git/repo.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,12 @@ func InitRepository(ctx context.Context, repoPath string, bare bool) error {
8181
func (repo *Repository) IsEmpty() (bool, error) {
8282
var errbuf strings.Builder
8383
if err := NewCommandContext(repo.Ctx, "log", "-1").RunInDirPipeline(repo.Path, nil, &errbuf); err != nil {
84+
defaultBranch, err := repo.GetDefaultBranch()
85+
if err != nil {
86+
return false, err
87+
}
8488
if strings.Contains(errbuf.String(), "fatal: bad default revision 'HEAD'") ||
85-
strings.Contains(errbuf.String(), "fatal: your current branch 'master' does not have any commits yet") {
89+
strings.Contains(errbuf.String(), fmt.Sprintf("fatal: your current branch '%s' does not have any commits yet", defaultBranch)) {
8690
return true, nil
8791
}
8892
return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String())

0 commit comments

Comments
 (0)