aboutsummaryrefslogtreecommitdiffstats
path: root/repository.go
diff options
context:
space:
mode:
Diffstat (limited to 'repository.go')
-rw-r--r--repository.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/repository.go b/repository.go
index 445e90c..fc871c7 100644
--- a/repository.go
+++ b/repository.go
@@ -12,8 +12,9 @@ import (
)
var (
- ErrObjectNotFound = errors.New("object not found")
- ErrInvalidReference = errors.New("invalid reference, should be a tag or a branch")
+ ErrObjectNotFound = errors.New("object not found")
+ ErrInvalidReference = errors.New("invalid reference, should be a tag or a branch")
+ ErrRepositoryNonEmpty = errors.New("repository non empty")
)
// Repository giturl string, auth common.AuthMethod repository struct
@@ -94,6 +95,15 @@ func (r *Repository) DeleteRemote(name string) error {
// Clone clones a remote repository
func (r *Repository) Clone(o *CloneOptions) error {
+ empty, err := r.IsEmpty()
+ if err != nil {
+ return err
+ }
+
+ if !empty {
+ return ErrRepositoryNonEmpty
+ }
+
if err := o.Validate(); err != nil {
return err
}
@@ -166,6 +176,15 @@ func (r *Repository) createReferences(ref *core.Reference) error {
return r.s.ReferenceStorage().Set(head)
}
+// IsEmpty returns true if the repository is empty
+func (r *Repository) IsEmpty() (bool, error) {
+ var count int
+ return count == 0, r.Refs().ForEach(func(r *core.Reference) error {
+ count++
+ return nil
+ })
+}
+
// Pull incorporates changes from a remote repository into the current branch
func (r *Repository) Pull(o *PullOptions) error {
if err := o.Validate(); err != nil {