summaryrefslogtreecommitdiffstats
path: root/modules/git/repo.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-06-27 02:15:26 +0800
committertechknowlogick <techknowlogick@gitea.io>2019-06-26 14:15:26 -0400
commitedc94c70413048107ea728ff330f32ca3de6df88 (patch)
treecf5bcc5ba8ee4b2e585dc14a6cf7440ce88bc073 /modules/git/repo.go
parent161e12e157a48f9bcd2de50c187c77444aa2a9a8 (diff)
downloadgitea-edc94c70413048107ea728ff330f32ca3de6df88.tar.gz
gitea-edc94c70413048107ea728ff330f32ca3de6df88.zip
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
Diffstat (limited to 'modules/git/repo.go')
-rw-r--r--modules/git/repo.go14
1 files changed, 14 insertions, 0 deletions
diff --git a/modules/git/repo.go b/modules/git/repo.go
index f5d7ee63bb..8a40fb1b91 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -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