diff options
author | nullishamy <amy.codes@null.net> | 2022-08-15 13:59:34 +0100 |
---|---|---|
committer | nullishamy <amy.codes@null.net> | 2022-08-15 13:59:34 +0100 |
commit | 154bd975a6361cd84e870d8128a2352505353aac (patch) | |
tree | bdc0293f99a053d0ff2897f06d27e3b663b5527d /pkg/commands/git_commands/status.go | |
parent | 3016469708e1f7af9c90d6d65f2c76db7d3195e2 (diff) |
Apply refactoring suggestions
Diffstat (limited to 'pkg/commands/git_commands/status.go')
-rw-r--r-- | pkg/commands/git_commands/status.go | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/pkg/commands/git_commands/status.go b/pkg/commands/git_commands/status.go index 50b1fab57..d660dd8b0 100644 --- a/pkg/commands/git_commands/status.go +++ b/pkg/commands/git_commands/status.go @@ -2,8 +2,10 @@ package git_commands import ( "path/filepath" + "strconv" + "strings" - gogit "github.com/jesseduffield/go-git/v5" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" ) @@ -49,13 +51,21 @@ func (self *StatusCommands) WorkingTreeState() enums.RebaseMode { return enums.REBASE_MODE_NONE } +func (self *StatusCommands) IsBareRepo() (bool, error) { + return IsBareRepo(self.os) +} + +func IsBareRepo(osCommand *oscommands.OSCommand) (bool, error) { + res, err := osCommand.Cmd.New("git rev-parse --is-bare-repository").DontLog().RunWithOutput() + if err != nil { + return false, err + } + + // The command returns output with a newline, so we need to strip + return strconv.ParseBool(strings.TrimSpace(res)) +} + // IsInMergeState states whether we are still mid-merge func (self *StatusCommands) IsInMergeState() (bool, error) { return self.os.FileExists(filepath.Join(self.dotGitDir, "MERGE_HEAD")) } - -func (self *StatusCommands) IsBareRepo() bool { - // note: could use `git rev-parse --is-bare-repository` if we wanna drop go-git - _, err := self.repo.Worktree() - return err == gogit.ErrIsBareRepository -} |