File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44 "bytes"
55 "errors"
66 "fmt"
7+ "io/fs"
78 "os"
89 "os/exec"
910 "path/filepath"
@@ -71,17 +72,36 @@ func NewRepository(path string) (*Repository, error) {
7172 gitBin : gitBin ,
7273 }
7374
75+ full , err := repo .IsFull ()
76+ if err != nil {
77+ return nil , fmt .Errorf ("determining whether the repository is a full clone: %w" , err )
78+ }
79+ if ! full {
80+ return nil , errors .New ("this appears to be a shallow clone; full clone required" )
81+ }
82+
83+ return & repo , nil
84+ }
85+
86+ // IsFull returns `true` iff `repo` appears to be a full clone.
87+ func (repo * Repository ) IsFull () (bool , error ) {
7488 shallow , err := repo .GitPath ("shallow" )
7589 if err != nil {
76- return nil , err
90+ return false , err
7791 }
7892
7993 _ , err = os .Lstat (shallow )
8094 if err == nil {
81- return nil , errors . New ( "this appears to be a shallow clone; full clone required" )
95+ return false , nil
8296 }
8397
84- return & repo , nil
98+ if ! errors .Is (err , fs .ErrNotExist ) {
99+ return false , err
100+ }
101+
102+ // The `shallow` file is absent, which is what we expect
103+ // for a full clone.
104+ return true , nil
85105}
86106
87107func (repo * Repository ) GitCommand (callerArgs ... string ) * exec.Cmd {
You can’t perform that action at this time.
0 commit comments