diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2022-02-14 00:01:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-14 00:01:23 +0800 |
commit | 1b1658d8875e42f0c5130ddfe9c7339e10bf5c20 (patch) | |
tree | f1120f1ba76e7b5744a023d33d6473f14ecae1cd /modules | |
parent | f1d8030310d27ae3a7d27067c48bb9a8392f3d5c (diff) | |
download | gitea-1b1658d8875e42f0c5130ddfe9c7339e10bf5c20.tar.gz gitea-1b1658d8875e42f0c5130ddfe9c7339e10bf5c20.zip |
Fix isempty detection of git repository (#18746)
* Fix isempty detection of git repository
* Fix IsEmpty check
Diffstat (limited to 'modules')
-rw-r--r-- | modules/git/repo.go | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go index 79a540209c..8217521b06 100644 --- a/modules/git/repo.go +++ b/modules/git/repo.go @@ -80,21 +80,20 @@ func InitRepository(ctx context.Context, repoPath string, bare bool) error { // IsEmpty Check if repository is empty. func (repo *Repository) IsEmpty() (bool, error) { var errbuf, output strings.Builder - if err := NewCommand(repo.Ctx, "rev-list", "--all", "--count", "--max-count=1"). + if err := NewCommand(repo.Ctx, "show-ref", "--head", "^HEAD$"). RunWithContext(&RunContext{ Timeout: -1, Dir: repo.Path, Stdout: &output, Stderr: &errbuf, }); err != nil { + if err.Error() == "exit status 1" && errbuf.String() == "" { + return true, nil + } return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String()) } - c, err := strconv.Atoi(strings.TrimSpace(output.String())) - if err != nil { - return true, fmt.Errorf("check empty: convert %s to count failed: %v", output.String(), err) - } - return c == 0, nil + return strings.TrimSpace(output.String()) == "", nil } // CloneRepoOptions options when clone a repository |