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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
package gui
import (
"github.com/jesseduffield/lazygit/pkg/commands/models"
"github.com/jesseduffield/lazygit/pkg/utils"
)
// list panel functions
func (gui *Gui) getSelectedStashEntry() *models.StashEntry {
selectedLine := gui.State.Panels.Stash.SelectedLineIdx
if selectedLine == -1 {
return nil
}
return gui.State.StashEntries[selectedLine]
}
func (gui *Gui) handleStashEntrySelect() error {
var task updateTask
stashEntry := gui.getSelectedStashEntry()
if stashEntry == nil {
task = gui.createRenderStringTask(gui.Tr.NoStashEntries)
} else {
cmd := gui.OSCommand.ExecutableFromString(
gui.GitCommand.ShowStashEntryCmdStr(stashEntry.Index),
)
task = gui.createRunPtyTask(cmd)
}
return gui.refreshMainViews(refreshMainOpts{
main: &viewUpdateOpts{
title: "Stash",
task: task,
},
})
}
func (gui *Gui) refreshStashEntries() error {
gui.State.StashEntries = gui.GitCommand.GetStashEntries(gui.State.Modes.Filtering.Path)
return gui.Contexts.Stash.Context.HandleRender()
}
// specific functions
func (gui *Gui) handleStashApply() error {
skipStashWarning := gui.Config.GetUserConfig().Gui.SkipStashWarning
apply := func() error {
return gui.stashDo("apply")
}
if skipStashWarning {
return apply()
}
return gui.ask(askOpts{
title: gui.Tr.StashApply,
prompt: gui.Tr.SureApplyStashEntry,
handleConfirm: func() error {
return apply()
},
})
}
func (gui *Gui) handleStashPop() error {
skipStashWarning := gui.Config.GetUserConfig().Gui.SkipStashWarning
pop := func() error {
return gui.stashDo("pop")
}
if skipStashWarning {
return pop()
}
return gui.ask(askOpts{
title: gui.Tr.StashPop,
prompt: gui.Tr.SurePopStashEntry,
handleConfirm: func() error {
return pop()
},
})
}
func (gui *Gui) handleStashDrop() error {
return gui.ask(askOpts{
title: gui.Tr.StashDrop,
prompt: gui.Tr.SureDropStashEntry,
handleConfirm: func() error {
return gui.stashDo("drop")
},
})
}
func (gui *Gui) stashDo(method string) error {
stashEntry := gui.getSelectedStashEntry()
if stashEntry == nil {
errorMessage := utils.ResolvePlaceholderString(
gui.Tr.NoStashTo,
map[string]string{
"method": method,
},
)
return gui.createErrorPanel(errorMessage)
}
if err := gui.GitCommand.StashDo(stashEntry.Index, method); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{STASH, FILES}})
}
func (gui *Gui) handleStashSave(stashFunc func(message string) error) error {
if len(gui.trackedFiles()) == 0 && len(gui.stagedFiles()) == 0 {
return gui.createErrorPanel(gui.Tr.NoTrackedStagedFilesStash)
}
return gui.prompt(promptOpts{
title: gui.Tr.StashChanges,
handleConfirm: func(stashComment string) error {
if err := stashFunc(stashComment); err != nil {
return gui.surfaceError(err)
}
return gui.refreshSidePanels(refreshOptions{scope: []RefreshableView{STASH, FILES}})
},
})
}
func (gui *Gui) handleViewStashFiles() error {
stashEntry := gui.getSelectedStashEntry()
if stashEntry == nil {
return nil
}
return gui.switchToCommitFilesContext(stashEntry.RefName(), false, gui.Contexts.Stash.Context, "stash")
}
|