Skip to content

Commit

Permalink
Add Status.IsUntracked function
Browse files Browse the repository at this point in the history
Signed-off-by: kuba-- <[email protected]>
  • Loading branch information
kuba-- committed Aug 29, 2018
1 parent 0167dab commit 75fa41d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 11 additions & 2 deletions status.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package git

import "fmt"
import "bytes"
import (
"bytes"
"fmt"
"path/filepath"
)

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

// IsUntracked checks if file for given path is 'Untracked'
func (s Status) IsUntracked(path string) bool {
stat, ok := (s)[filepath.ToSlash(path)]
return ok && stat.Worktree == Untracked
}

// IsClean returns true if all the files aren't in Unmodified status.
func (s Status) IsClean() bool {
for _, status := range s {
Expand Down
4 changes: 1 addition & 3 deletions worktree.go
Original file line number Diff line number Diff line change
Expand Up @@ -750,9 +750,7 @@ func (w *Worktree) doClean(status Status, opts *CleanOptions, dir string, files
return err
}
} else {
// check if file is 'Untracked'
s, ok := (status)[filepath.ToSlash(path)]
if ok && s.Worktree == Untracked {
if status.IsUntracked(path) {
if err := w.Filesystem.Remove(path); err != nil {
return err
}
Expand Down

0 comments on commit 75fa41d

Please sign in to comment.