Skip to content

Commit b039395

Browse files
authored
Fix untracked files counting as staged
1 parent 0363f2d commit b039395

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

lazycommit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (r *LazyRepo) NoStaged() (bool, error) {
3535
}
3636

3737
for _, file := range status {
38-
if file.Staging != git.Unmodified {
38+
if file.Staging != git.Unmodified && file.Staging != git.Untracked {
3939
return false, nil
4040
}
4141
}

lazycommit_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func TestOpenRepoError(t *testing.T) {
3434
}
3535

3636
// Tests that NoStaged returns true if there are no staged changes.
37-
func TestNoStaged(t *testing.T) {
37+
func TestNoStagedChanges(t *testing.T) {
3838
dir := tempRepo(t)
3939
// NOTE: Committing a file so that there's something in the worktree.
4040
f := commitFile(t, dir, "test.txt", "test")
@@ -57,6 +57,27 @@ func TestNoStaged(t *testing.T) {
5757
}
5858
}
5959

60+
// Tests that NoStaged returns true if there new files are not staged.
61+
func TestNoStagedNewFiles(t *testing.T) {
62+
dir := tempRepo(t)
63+
// NOTE: Committing a file so that there's something in the worktree.
64+
commitFile(t, dir, "test.txt", "test")
65+
writeFile(t, dir, "test2.txt", "test")
66+
67+
repo, err := OpenRepo(dir)
68+
if err != nil {
69+
t.Fatal(err)
70+
}
71+
noStaged, err := repo.NoStaged()
72+
if err != nil {
73+
t.Fatal(err)
74+
}
75+
if !noStaged {
76+
t.Logf("status: %v", getStatus(t, dir))
77+
t.Fatal("expected no staged changes")
78+
}
79+
}
80+
6081
// Tests that NoStaged returns false if there are staged changes.
6182
func TestNoStagedStaged(t *testing.T) {
6283
dir := tempRepo(t)

0 commit comments

Comments
 (0)