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 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'status.go') 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 { -- cgit From da56abd1530ce85640479a6b6cf292009891a0f5 Mon Sep 17 00:00:00 2001 From: David Url Date: Sat, 6 Oct 2018 13:00:11 +0200 Subject: git: Fix Status.IsClean() documentation The documentation of the IsClean Method contained a negation, so it was describing the opposite of its actual behavior. Fixes #838 Signed-off-by: David Url --- status.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'status.go') diff --git a/status.go b/status.go index ecbf793..7f18e02 100644 --- a/status.go +++ b/status.go @@ -26,7 +26,7 @@ func (s Status) IsUntracked(path string) bool { return ok && stat.Worktree == Untracked } -// IsClean returns true if all the files aren't in Unmodified status. +// IsClean returns true if all the files are in Unmodified status. func (s Status) IsClean() bool { for _, status := range s { if status.Worktree != Unmodified || status.Staging != Unmodified { -- cgit