1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
package gui
import (
"fmt"
"strings"
"github.com/jesseduffield/lazygit/pkg/gui/types"
"github.com/jesseduffield/lazygit/pkg/utils"
)
// list panel functions
func (gui *Gui) remoteBranchesRenderToMain() error {
var task updateTask
remoteBranch := gui.State.Contexts.RemoteBranches.GetSelected()
if remoteBranch == nil {
task = NewRenderStringTask("No branches for this remote")
} else {
cmdObj := gui.git.Branch.GetGraphCmdObj(remoteBranch.FullName())
task = NewRunCommandTask(cmdObj.GetCmd())
}
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
title: "Remote Branch",
task: task,
},
})
}
func (gui *Gui) handleRemoteBranchesEscape() error {
return gui.c.PushContext(gui.State.Contexts.Remotes)
}
func (gui *Gui) handleMergeRemoteBranch() error {
selectedBranchName := gui.State.Contexts.RemoteBranches.GetSelected().FullName()
return gui.helpers.MergeAndRebase.MergeRefIntoCheckedOutBranch(selectedBranchName)
}
func (gui *Gui) handleDeleteRemoteBranch() error {
remoteBranch := gui.State.Contexts.RemoteBranches.GetSelected()
if remoteBranch == nil {
return nil
}
message := fmt.Sprintf("%s '%s'?", gui.c.Tr.DeleteRemoteBranchMessage, remoteBranch.FullName())
return gui.c.Ask(types.AskOpts{
Title: gui.c.Tr.DeleteRemoteBranch,
Prompt: message,
HandleConfirm: func() error {
return gui.c.WithWaitingStatus(gui.c.Tr.DeletingStatus, func() error {
gui.c.LogAction(gui.c.Tr.Actions.DeleteRemoteBranch)
err := gui.git.Remote.DeleteRemoteBranch(remoteBranch.RemoteName, remoteBranch.Name)
if err != nil {
_ = gui.c.Error(err)
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
})
},
})
}
func (gui *Gui) handleRebaseOntoRemoteBranch() error {
selectedBranchName := gui.State.Contexts.RemoteBranches.GetSelected().FullName()
return gui.helpers.MergeAndRebase.RebaseOntoRef(selectedBranchName)
}
func (gui *Gui) handleSetBranchUpstream() error {
selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected()
checkedOutBranch := gui.helpers.Refs.GetCheckedOutRef()
message := utils.ResolvePlaceholderString(
gui.c.Tr.SetUpstreamMessage,
map[string]string{
"checkedOut": checkedOutBranch.Name,
"selected": selectedBranch.FullName(),
},
)
return gui.c.Ask(types.AskOpts{
Title: gui.c.Tr.SetUpstreamTitle,
Prompt: message,
HandleConfirm: func() error {
gui.c.LogAction(gui.c.Tr.Actions.SetBranchUpstream)
if err := gui.git.Branch.SetUpstream(selectedBranch.RemoteName, selectedBranch.Name, checkedOutBranch.Name); err != nil {
return gui.c.Error(err)
}
return gui.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.BRANCHES, types.REMOTES}})
},
})
}
func (gui *Gui) handleCreateResetToRemoteBranchMenu() error {
selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected()
if selectedBranch == nil {
return nil
}
return gui.helpers.Refs.CreateGitResetMenu(selectedBranch.FullName())
}
func (gui *Gui) handleNewBranchOffRemoteBranch() error {
selectedBranch := gui.State.Contexts.RemoteBranches.GetSelected()
if selectedBranch == nil {
return nil
}
// will set to the remote's branch name without the remote name
nameSuggestion := strings.SplitAfterN(selectedBranch.RefName(), "/", 2)[1]
return gui.helpers.Refs.NewBranch(selectedBranch.RefName(), selectedBranch.RefName(), nameSuggestion)
}
|