1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-26 05:37:18 +02:00

62 lines
1.6 KiB
Go
Raw Normal View History

2022-01-08 14:00:36 +11:00
package git_commands
2020-09-29 20:03:39 +10:00
import (
"path/filepath"
2020-10-06 20:50:54 +11:00
gogit "github.com/jesseduffield/go-git/v5"
2021-12-30 13:35:10 +11:00
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
2020-11-16 20:38:26 +11:00
)
2022-01-02 10:34:33 +11:00
type StatusCommands struct {
*GitCommon
2022-01-02 10:34:33 +11:00
}
func NewStatusCommands(
gitCommon *GitCommon,
2022-01-02 10:34:33 +11:00
) *StatusCommands {
return &StatusCommands{
GitCommon: gitCommon,
2022-01-02 10:34:33 +11:00
}
}
2020-09-29 20:03:39 +10:00
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
// and "interactive" for interactive rebase
2022-01-02 10:34:33 +11:00
func (self *StatusCommands) RebaseMode() (enums.RebaseMode, error) {
exists, err := self.os.FileExists(filepath.Join(self.dotGitDir, "rebase-apply"))
2020-09-29 20:03:39 +10:00
if err != nil {
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_NONE, err
2020-09-29 20:03:39 +10:00
}
if exists {
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_NORMAL, nil
2020-09-29 20:03:39 +10:00
}
exists, err = self.os.FileExists(filepath.Join(self.dotGitDir, "rebase-merge"))
2020-09-29 20:03:39 +10:00
if exists {
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_INTERACTIVE, err
2020-09-29 20:03:39 +10:00
} else {
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_NONE, err
2020-09-29 20:03:39 +10:00
}
}
2022-01-02 10:34:33 +11:00
func (self *StatusCommands) WorkingTreeState() enums.RebaseMode {
rebaseMode, _ := self.RebaseMode()
2021-12-30 13:35:10 +11:00
if rebaseMode != enums.REBASE_MODE_NONE {
return enums.REBASE_MODE_REBASING
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11:00
merging, _ := self.IsInMergeState()
2020-09-29 20:03:39 +10:00
if merging {
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_MERGING
2020-09-29 20:03:39 +10:00
}
2021-12-30 13:35:10 +11:00
return enums.REBASE_MODE_NONE
2020-09-29 20:03:39 +10:00
}
// IsInMergeState states whether we are still mid-merge
2022-01-02 10:34:33 +11:00
func (self *StatusCommands) IsInMergeState() (bool, error) {
return self.os.FileExists(filepath.Join(self.dotGitDir, "MERGE_HEAD"))
2020-09-29 20:03:39 +10:00
}
2022-01-02 10:34:33 +11:00
func (self *StatusCommands) IsBareRepo() bool {
2020-09-29 20:03:39 +10:00
// note: could use `git rev-parse --is-bare-repository` if we wanna drop go-git
2022-01-02 10:34:33 +11:00
_, err := self.repo.Worktree()
2020-09-29 20:03:39 +10:00
return err == gogit.ErrIsBareRepository
}