mirror of
https://github.com/go-gitea/gitea
synced 2025-07-03 17:17:19 +00:00
Monitor all git commands; move blame to git package and replace git as a variable (#6864)
* monitor all git commands; move blame to git package and replace git as a variable * use git command but not other commands * fix build * move exec.Command to git.NewCommand * fix fmt * remove unrelated changes * remove unrelated changes * refactor IsEmpty and add tests * fix tests * fix tests * fix tests * fix tests * remove gitLogger * fix fmt * fix isEmpty * fix lint * fix tests
This commit is contained in:
committed by
techknowlogick
parent
161e12e157
commit
edc94c7041
@ -107,6 +107,20 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
// IsEmpty Check if repository is empty.
|
||||
func (repo *Repository) IsEmpty() (bool, error) {
|
||||
var errbuf strings.Builder
|
||||
if err := NewCommand("log", "-1").RunInDirPipeline(repo.Path, nil, &errbuf); err != nil {
|
||||
if strings.Contains(errbuf.String(), "fatal: bad default revision 'HEAD'") ||
|
||||
strings.Contains(errbuf.String(), "fatal: your current branch 'master' does not have any commits yet") {
|
||||
return true, nil
|
||||
}
|
||||
return true, fmt.Errorf("check empty: %v - %s", err, errbuf.String())
|
||||
}
|
||||
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// CloneRepoOptions options when clone a repository
|
||||
type CloneRepoOptions struct {
|
||||
Timeout time.Duration
|
||||
|
Reference in New Issue
Block a user