1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-24 02:05:34 +03:00
Stefan Haller 8af8f7754b Move types/enums/enums.go to working_tree_state.go
It looks like enums.go was supposed to be file that collects a bunch of enums,
but actually there's only one in there, and since it has methods, it deserves to
be in a file of its own, named after the type.
2025-04-20 15:53:17 +02:00

62 lines
1.6 KiB
Go

package git_commands
import (
"os"
"path/filepath"
"strings"
"github.com/jesseduffield/lazygit/pkg/commands/models"
)
type StatusCommands struct {
*GitCommon
}
func NewStatusCommands(
gitCommon *GitCommon,
) *StatusCommands {
return &StatusCommands{
GitCommon: gitCommon,
}
}
func (self *StatusCommands) WorkingTreeState() models.WorkingTreeState {
isInRebase, _ := self.IsInRebase()
if isInRebase {
return models.WORKING_TREE_STATE_REBASING
}
merging, _ := self.IsInMergeState()
if merging {
return models.WORKING_TREE_STATE_MERGING
}
return models.WORKING_TREE_STATE_NONE
}
func (self *StatusCommands) IsBareRepo() bool {
return self.repoPaths.isBareRepo
}
func (self *StatusCommands) IsInRebase() (bool, error) {
exists, err := self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-merge"))
if err == nil && exists {
return true, nil
}
return self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "rebase-apply"))
}
// IsInMergeState states whether we are still mid-merge
func (self *StatusCommands) IsInMergeState() (bool, error) {
return self.os.FileExists(filepath.Join(self.repoPaths.WorktreeGitDirPath(), "MERGE_HEAD"))
}
// Full ref (e.g. "refs/heads/mybranch") of the branch that is currently
// being rebased, or empty string when we're not in a rebase
func (self *StatusCommands) BranchBeingRebased() string {
for _, dir := range []string{"rebase-merge", "rebase-apply"} {
if bytesContent, err := os.ReadFile(filepath.Join(self.repoPaths.WorktreeGitDirPath(), dir, "head-name")); err == nil {
return strings.TrimSpace(string(bytesContent))
}
}
return ""
}