Skip to content

Commit cb3c1c7

Browse files
committed
If in a shallow clone, refuse to run
`git-sizer` must be run in a full Git clone. Check whether the current repository is shallow. If so, emit an error and refuse to run. Also document this requirement in the README.
1 parent 24b5d5e commit cb3c1c7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Is your Git repository bursting at the seams?
7878

7979
b. Build and install from source. See the instructions in [`docs/BUILDING.md`](docs/BUILDING.md).
8080

81-
3. Change to the directory containing the Git repository that you'd like to analyze, then run
81+
3. Change to the directory containing a full, non-shallow clone of the Git repository that you'd like to analyze. Then run
8282

8383
git sizer [<option>...]
8484

git/git.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,24 @@ func NewRepository(path string) (*Repository, error) {
9999
}
100100
}
101101
gitDir := smartJoin(path, string(bytes.TrimSpace(out)))
102-
repo := &Repository{
103-
path: gitDir,
102+
103+
cmd = exec.Command("git", "rev-parse", "--git-path", "shallow")
104+
cmd.Dir = gitDir
105+
out, err = cmd.Output()
106+
if err != nil {
107+
return nil, errors.New(
108+
fmt.Sprintf(
109+
"could not run 'git rev-parse --git-path shallow': %s", err,
110+
),
111+
)
112+
}
113+
shallow := smartJoin(gitDir, string(bytes.TrimSpace(out)))
114+
_, err = os.Lstat(shallow)
115+
if err == nil {
116+
return nil, errors.New("this appears to be a shallow clone; full clone required")
104117
}
105-
return repo, nil
118+
119+
return &Repository{path: gitDir}, nil
106120
}
107121

108122
func (repo *Repository) gitCommand(callerArgs ...string) *exec.Cmd {

0 commit comments

Comments
 (0)