Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 75fa41d

Browse files
author
kuba--
committed
Add Status.IsUntracked function
Signed-off-by: kuba-- <kuba@sourced.tech>
1 parent 0167dab commit 75fa41d

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

status.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package git
22

3-
import "fmt"
4-
import "bytes"
3+
import (
4+
"bytes"
5+
"fmt"
6+
"path/filepath"
7+
)
58

69
// Status represents the current status of a Worktree.
710
// The key of the map is the path of the file.
@@ -17,6 +20,12 @@ func (s Status) File(path string) *FileStatus {
1720
return s[path]
1821
}
1922

23+
// IsUntracked checks if file for given path is 'Untracked'
24+
func (s Status) IsUntracked(path string) bool {
25+
stat, ok := (s)[filepath.ToSlash(path)]
26+
return ok && stat.Worktree == Untracked
27+
}
28+
2029
// IsClean returns true if all the files aren't in Unmodified status.
2130
func (s Status) IsClean() bool {
2231
for _, status := range s {

worktree.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,7 @@ func (w *Worktree) doClean(status Status, opts *CleanOptions, dir string, files
750750
return err
751751
}
752752
} else {
753-
// check if file is 'Untracked'
754-
s, ok := (status)[filepath.ToSlash(path)]
755-
if ok && s.Worktree == Untracked {
753+
if status.IsUntracked(path) {
756754
if err := w.Filesystem.Remove(path); err != nil {
757755
return err
758756
}

0 commit comments

Comments
 (0)