1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-14 11:23:09 +02:00
lazygit/pkg/commands/status.go

56 lines
1.4 KiB
Go
Raw Normal View History

2020-09-29 12:03:39 +02:00
package commands
import (
"path/filepath"
2020-10-06 11:50:54 +02:00
gogit "github.com/jesseduffield/go-git/v5"
2020-09-29 12:03:39 +02:00
)
2020-11-16 11:38:26 +02:00
const (
REBASE_MODE_NORMAL = "normal"
REBASE_MODE_INTERACTIVE = "interactive"
REBASE_MODE_REBASING = "rebasing"
REBASE_MODE_MERGING = "merging"
)
2020-09-29 12:03:39 +02:00
// RebaseMode returns "" for non-rebase mode, "normal" for normal rebase
// and "interactive" for interactive rebase
func (c *GitCommand) RebaseMode() (string, error) {
exists, err := c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-apply"))
if err != nil {
return "", err
}
if exists {
2020-11-16 11:38:26 +02:00
return REBASE_MODE_NORMAL, nil
2020-09-29 12:03:39 +02:00
}
exists, err = c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "rebase-merge"))
if exists {
2020-11-16 11:38:26 +02:00
return REBASE_MODE_INTERACTIVE, err
2020-09-29 12:03:39 +02:00
} else {
return "", err
}
}
func (c *GitCommand) WorkingTreeState() string {
rebaseMode, _ := c.RebaseMode()
if rebaseMode != "" {
2020-11-16 11:38:26 +02:00
return REBASE_MODE_REBASING
2020-09-29 12:03:39 +02:00
}
merging, _ := c.IsInMergeState()
if merging {
2020-11-16 11:38:26 +02:00
return REBASE_MODE_MERGING
2020-09-29 12:03:39 +02:00
}
2020-11-16 11:38:26 +02:00
return REBASE_MODE_NORMAL
2020-09-29 12:03:39 +02:00
}
// IsInMergeState states whether we are still mid-merge
func (c *GitCommand) IsInMergeState() (bool, error) {
return c.OSCommand.FileExists(filepath.Join(c.DotGitDir, "MERGE_HEAD"))
}
func (c *GitCommand) IsBareRepo() bool {
// note: could use `git rev-parse --is-bare-repository` if we wanna drop go-git
_, err := c.Repo.Worktree()
return err == gogit.ErrIsBareRepository
}