mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-28 16:02:01 +03:00
Apply refactoring suggestions
This commit is contained in:
@ -15,6 +15,7 @@ import (
|
|||||||
|
|
||||||
"github.com/jesseduffield/generics/slices"
|
"github.com/jesseduffield/generics/slices"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands"
|
"github.com/jesseduffield/lazygit/pkg/commands"
|
||||||
|
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
"github.com/jesseduffield/lazygit/pkg/commands/git_config"
|
||||||
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
|
||||||
"github.com/jesseduffield/lazygit/pkg/common"
|
"github.com/jesseduffield/lazygit/pkg/common"
|
||||||
@ -151,16 +152,6 @@ func isDirectoryAGitRepository(dir string) (bool, error) {
|
|||||||
return info != nil, err
|
return info != nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
func openRecentRepo(app *App) bool {
|
func openRecentRepo(app *App) bool {
|
||||||
for _, repoDir := range app.Config.GetAppState().RecentRepos {
|
for _, repoDir := range app.Config.GetAppState().RecentRepos {
|
||||||
@ -231,7 +222,7 @@ func (app *App) setupRepo() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run this afterward so that the previous repo creation steps can run without this interfering
|
// Run this afterward so that the previous repo creation steps can run without this interfering
|
||||||
if isBare, err := isBareRepo(app.OSCommand); isBare {
|
if isBare, err := git_commands.IsBareRepo(app.OSCommand); isBare {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,10 @@ package git_commands
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"path/filepath"
|
"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"
|
"github.com/jesseduffield/lazygit/pkg/commands/types/enums"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -49,13 +51,21 @@ func (self *StatusCommands) WorkingTreeState() enums.RebaseMode {
|
|||||||
return enums.REBASE_MODE_NONE
|
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
|
// IsInMergeState states whether we are still mid-merge
|
||||||
func (self *StatusCommands) IsInMergeState() (bool, error) {
|
func (self *StatusCommands) IsInMergeState() (bool, error) {
|
||||||
return self.os.FileExists(filepath.Join(self.dotGitDir, "MERGE_HEAD"))
|
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
|
|
||||||
}
|
|
||||||
|
@ -158,7 +158,12 @@ func (gui *Gui) dispatchSwitchToRepo(path string, reuse bool) error {
|
|||||||
// updateRecentRepoList registers the fact that we opened lazygit in this repo,
|
// updateRecentRepoList registers the fact that we opened lazygit in this repo,
|
||||||
// so that we can open the same repo via the 'recent repos' menu
|
// so that we can open the same repo via the 'recent repos' menu
|
||||||
func (gui *Gui) updateRecentRepoList() error {
|
func (gui *Gui) updateRecentRepoList() error {
|
||||||
if gui.git.Status.IsBareRepo() {
|
isBareRepo, err := gui.git.Status.IsBareRepo()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if isBareRepo {
|
||||||
// we could totally do this but it would require storing both the git-dir and the
|
// we could totally do this but it would require storing both the git-dir and the
|
||||||
// worktree in our recent repos list, which is a change that would need to be
|
// worktree in our recent repos list, which is a change that would need to be
|
||||||
// backwards compatible
|
// backwards compatible
|
||||||
|
Reference in New Issue
Block a user