mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-23 00:39:13 +02:00
.devcontainer
.github
.vscode
cmd
demo
docs
pkg
app
cheatsheet
commands
common
config
constants
env
fakes
gui
context
controllers
helpers
attach.go
base_controller.go
basic_commits_controller.go
bisect_controller.go
branches_controller.go
command_log_controller.go
commit_description_controller.go
commit_message_controller.go
commits_files_controller.go
common.go
confirmation_controller.go
context_lines_controller.go
custom_patch_options_menu_action.go
diffing_menu_action.go
files_controller.go
filter_controller.go
filtering_menu_action.go
git_flow_controller.go
global_controller.go
jump_to_side_window_controller.go
list_controller.go
list_controller_trait.go
local_commits_controller.go
local_commits_controller_test.go
main_view_controller.go
menu_controller.go
merge_conflicts_controller.go
options_menu_action.go
patch_building_controller.go
patch_explorer_controller.go
quit_actions.go
reflog_commits_controller.go
remote_branches_controller.go
remotes_controller.go
rename_similarity_threshold_controller.go
screen_mode_actions.go
scroll_off_margin.go
scroll_off_margin_test.go
search_controller.go
search_prompt_controller.go
shell_command_action.go
side_window_controller.go
snake_controller.go
staging_controller.go
stash_controller.go
status_controller.go
sub_commits_controller.go
submodules_controller.go
suggestions_controller.go
switch_to_diff_files_controller.go
switch_to_focused_main_view_controller.go
switch_to_sub_commits_controller.go
sync_controller.go
tags_controller.go
toggle_whitespace_action.go
undo_controller.go
vertical_scroll_controller.go
view_selection_controller.go
workspace_reset_controller.go
worktree_options_controller.go
worktrees_controller.go
filetree
keybindings
mergeconflicts
modes
patch_exploring
popup
presentation
services
status
style
types
background.go
command_log_panel.go
context.go
context_config.go
controllers.go
dummies.go
editors.go
extras_panel.go
global_handlers.go
gui.go
gui_common.go
gui_driver.go
information_panel.go
keybindings.go
layout.go
main_panels.go
menu_panel.go
options_map.go
pty.go
pty_windows.go
recent_repos_panel.go
tasks_adapter.go
test_mode.go
view_helpers.go
views.go
i18n
integration
jsonschema
logs
snake
tasks
theme
updates
utils
schema
scripts
test
vendor
.codespellrc
.editorconfig
.gitattributes
.gitignore
.golangci.yml
.goreleaser.yml
CODE-OF-CONDUCT.md
CONTRIBUTING.md
Dockerfile
LICENSE
Makefile
README.md
VISION.md
go.mod
go.sum
main.go
I'm getting warnings in my editor about these, probably because of an updated gopls again.
115 lines
2.8 KiB
Go
115 lines
2.8 KiB
Go
package controllers
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
|
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
|
)
|
|
|
|
type GitFlowController struct {
|
|
baseController
|
|
*ListControllerTrait[*models.Branch]
|
|
c *ControllerCommon
|
|
}
|
|
|
|
var _ types.IController = &GitFlowController{}
|
|
|
|
func NewGitFlowController(
|
|
c *ControllerCommon,
|
|
) *GitFlowController {
|
|
return &GitFlowController{
|
|
baseController: baseController{},
|
|
ListControllerTrait: NewListControllerTrait(
|
|
c,
|
|
c.Contexts().Branches,
|
|
c.Contexts().Branches.GetSelected,
|
|
c.Contexts().Branches.GetSelectedItems,
|
|
),
|
|
c: c,
|
|
}
|
|
}
|
|
|
|
func (self *GitFlowController) GetKeybindings(opts types.KeybindingsOpts) []*types.Binding {
|
|
bindings := []*types.Binding{
|
|
{
|
|
Key: opts.GetKey(opts.Config.Branches.ViewGitFlowOptions),
|
|
Handler: self.withItem(self.handleCreateGitFlowMenu),
|
|
Description: self.c.Tr.GitFlowOptions,
|
|
OpensMenu: true,
|
|
},
|
|
}
|
|
|
|
return bindings
|
|
}
|
|
|
|
func (self *GitFlowController) handleCreateGitFlowMenu(branch *models.Branch) error {
|
|
if !self.c.Git().Flow.GitFlowEnabled() {
|
|
return errors.New("You need to install git-flow and enable it in this repo to use git-flow features")
|
|
}
|
|
|
|
startHandler := func(branchType string) func() error {
|
|
return func() error {
|
|
title := utils.ResolvePlaceholderString(self.c.Tr.NewGitFlowBranchPrompt, map[string]string{"branchType": branchType})
|
|
|
|
self.c.Prompt(types.PromptOpts{
|
|
Title: title,
|
|
HandleConfirm: func(name string) error {
|
|
self.c.LogAction(self.c.Tr.Actions.GitFlowStart)
|
|
return self.c.RunSubprocessAndRefresh(
|
|
self.c.Git().Flow.StartCmdObj(branchType, name),
|
|
)
|
|
},
|
|
})
|
|
|
|
return nil
|
|
}
|
|
}
|
|
|
|
return self.c.Menu(types.CreateMenuOptions{
|
|
Title: "git flow",
|
|
Items: []*types.MenuItem{
|
|
{
|
|
// not localising here because it's one to one with the actual git flow commands
|
|
Label: fmt.Sprintf("finish branch '%s'", branch.Name),
|
|
OnPress: func() error {
|
|
return self.gitFlowFinishBranch(branch.Name)
|
|
},
|
|
DisabledReason: self.require(self.singleItemSelected())(),
|
|
},
|
|
{
|
|
Label: "start feature",
|
|
OnPress: startHandler("feature"),
|
|
Key: 'f',
|
|
},
|
|
{
|
|
Label: "start hotfix",
|
|
OnPress: startHandler("hotfix"),
|
|
Key: 'h',
|
|
},
|
|
{
|
|
Label: "start bugfix",
|
|
OnPress: startHandler("bugfix"),
|
|
Key: 'b',
|
|
},
|
|
{
|
|
Label: "start release",
|
|
OnPress: startHandler("release"),
|
|
Key: 'r',
|
|
},
|
|
},
|
|
})
|
|
}
|
|
|
|
func (self *GitFlowController) gitFlowFinishBranch(branchName string) error {
|
|
cmdObj, err := self.c.Git().Flow.FinishCmdObj(branchName)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
self.c.LogAction(self.c.Tr.Actions.GitFlowFinish)
|
|
return self.c.RunSubprocessAndRefresh(cmdObj)
|
|
}
|