From 75fa41d21c8d27ee0d5d7c7cb7ceeb2b765be330 Mon Sep 17 00:00:00 2001 From: kuba-- Date: Wed, 29 Aug 2018 14:56:25 +0200 Subject: Add Status.IsUntracked function Signed-off-by: kuba-- --- status.go | 13 +++++++++++-- worktree.go | 4 +--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/status.go b/status.go index ef8a500..ecbf793 100644 --- a/status.go +++ b/status.go @@ -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. @@ -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 { diff --git a/worktree.go b/worktree.go index 921e600..e45d815 100644 --- a/worktree.go +++ b/worktree.go @@ -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 } -- cgit