From 2574ec733a812a747b3e4075f8affc862453034f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 13 Dec 2024 16:18:25 -0600 Subject: IsLocalBranch() --- shell.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'shell.go') diff --git a/shell.go b/shell.go index 8215d46..efb682d 100644 --- a/shell.go +++ b/shell.go @@ -79,12 +79,29 @@ func (repo *Repo) Exists(filename string) bool { } func (repo *Repo) IsValid() bool { - if !repo.IsDirectory() { + if repo == nil { + return false + } + if !repo.IsGitDirectory() { return false } return true } +func (repo *Repo) ReadFile(fname string) ([]byte, error) { + fullname := filepath.Join(repo.FullPath, fname) + return os.ReadFile(fullname) +} + +func (repo *Repo) IsGitDirectory() bool { + gitdir := filepath.Join(repo.FullPath, ".git") + info, err := os.Stat(gitdir) + if err != nil { + return false + } + return info.IsDir() +} + func (repo *Repo) IsDirectory() bool { info, err := os.Stat(repo.FullPath) if err != nil { -- cgit v1.2.3