Skip to content

Commit 866b22e

Browse files
authored
Fix unstaged files affecting the commit message
Can be recreated with the following steps: ```bash touch file1.txt echo hi > file2.txt git add file2.txt ``` file1.txt would be included in the commit message, even though it was not staged. This removes the unstaged files from the commit message.
1 parent b039395 commit 866b22e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

commit.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ func (r *LazyRepo) CommitMsg() (string, error) {
3030
if err != nil {
3131
return "", err
3232
}
33+
for filename, fileStatus := range status {
34+
if fileStatus.Staging == git.Unmodified || fileStatus.Staging == git.Untracked {
35+
delete(status, filename)
36+
}
37+
}
3338

3439
if len(status) == 0 {
3540
return "", errors.New("no tracked files")

0 commit comments

Comments
 (0)