2018-08-14 11:05:26 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
2021-04-10 09:31:23 +02:00
|
|
|
"fmt"
|
2020-03-26 14:48:11 +02:00
|
|
|
"sync"
|
2018-08-14 11:05:26 +02:00
|
|
|
|
2021-12-30 04:35:10 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/loaders"
|
2020-09-29 12:28:39 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
2020-10-04 02:00:48 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-08-14 11:05:26 +02:00
|
|
|
)
|
|
|
|
|
2021-11-02 07:39:15 +02:00
|
|
|
// after selecting the 200th commit, we'll load in all the rest
|
|
|
|
const COMMIT_THRESHOLD = 200
|
|
|
|
|
2018-12-06 13:18:17 +02:00
|
|
|
// list panel functions
|
|
|
|
|
2020-09-29 10:36:54 +02:00
|
|
|
func (gui *Gui) getSelectedLocalCommit() *models.Commit {
|
2020-08-20 00:53:10 +02:00
|
|
|
selectedLine := gui.State.Panels.Commits.SelectedLineIdx
|
2021-04-03 02:32:14 +02:00
|
|
|
if selectedLine == -1 || selectedLine > len(gui.State.Commits)-1 {
|
2018-12-06 13:18:17 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return gui.State.Commits[selectedLine]
|
|
|
|
}
|
|
|
|
|
2021-11-21 03:48:49 +02:00
|
|
|
func (gui *Gui) onCommitFocus() error {
|
2020-01-11 09:23:35 +02:00
|
|
|
state := gui.State.Panels.Commits
|
2021-11-02 07:39:15 +02:00
|
|
|
if state.SelectedLineIdx > COMMIT_THRESHOLD && state.LimitCommits {
|
2020-01-11 09:23:35 +02:00
|
|
|
state.LimitCommits = false
|
2020-10-07 12:19:38 +02:00
|
|
|
go utils.Safe(func() {
|
2020-01-11 09:23:35 +02:00
|
|
|
if err := gui.refreshCommitsWithLimit(); err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
_ = gui.surfaceError(err)
|
2020-01-11 09:23:35 +02:00
|
|
|
}
|
2020-10-07 12:19:38 +02:00
|
|
|
})
|
2020-01-11 09:23:35 +02:00
|
|
|
}
|
|
|
|
|
2020-10-01 23:56:14 +02:00
|
|
|
gui.escapeLineByLinePanel()
|
2019-11-10 07:20:35 +02:00
|
|
|
|
2021-11-21 03:48:49 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) branchCommitsRenderToMain() error {
|
2020-08-18 14:02:35 +02:00
|
|
|
var task updateTask
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2018-12-06 13:18:17 +02:00
|
|
|
if commit == nil {
|
2021-04-04 15:51:59 +02:00
|
|
|
task = NewRenderStringTask(gui.Tr.NoCommitsThisBranch)
|
2020-08-18 14:02:35 +02:00
|
|
|
} else {
|
2022-01-08 05:10:01 +02:00
|
|
|
cmdObj := gui.Git.Commit.ShowCmdObj(commit.Sha, gui.State.Modes.Filtering.GetPath())
|
2021-12-07 12:59:36 +02:00
|
|
|
task = NewRunPtyTask(cmdObj.GetCmd())
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
allow fast flicking through any list panel
Up till now our approach to rendering things like file diffs, branch logs, and
commit patches, has been to run a command on the command line, wait for it to
complete, take its output as a string, and then write that string to the main
view (or secondary view e.g. when showing both staged and unstaged changes of a
file).
This has caused various issues. For once, if you are flicking through a list of
files and an untracked file is particularly large, not only will this require
lazygit to load that whole file into memory (or more accurately it's equally
large diff), it also will slow down the UI thread while loading that file, and
if the user continued down the list, the original command might eventually
resolve and replace whatever the diff is for the newly selected file.
Following what we've done in lazydocker, I've added a tasks package for when you
need something done but you want it to cancel as soon as something newer comes
up. Given this typically involves running a command to display to a view, I've
added a viewBufferManagerMap struct to the Gui struct which allows you to define
these tasks on a per-view basis.
viewBufferManagers can run files and directly write the output to their view,
meaning we no longer need to use so much memory.
In the tasks package there is a helper method called NewCmdTask which takes a
command, an initial amount of lines to read, and then runs that command, reads
that number of lines, and allows for a readLines channel to tell it to read more
lines. We read more lines when we scroll or resize the window.
There is an adapter for the tasks package in a file called tasks_adapter which
wraps the functions from the tasks package in gui-specific stuff like clearing
the main view before starting the next task that wants to write to the main
view.
I've removed some small features as part of this work, namely the little headers
that were at the top of the main view for some situations. For example, we no
longer show the upstream of a selected branch. I want to re-introduce this in
the future, but I didn't want to make this tasks system too complicated, and in
order to facilitate a header section in the main view we'd need to have a task
that gets the upstream for the current branch, writes it to the header, then
tells another task to write the branch log to the main view, but without
clearing inbetween. So it would get messy. I'm thinking instead of having a
separate 'header' view atop the main view to render that kind of thing (which
can happen in another PR)
I've also simplified the 'git show' to just call 'git show' and not do anything
fancy when it comes to merge commits.
I considered using this tasks approach whenever we write to a view. The only
thing is that the renderString method currently resets the origin of a view and
I don't want to lose that. So I've left some in there that I consider harmless,
but we should probably be just using tasks now for all rendering, even if it's
just strings we can instantly make.
2020-01-11 05:54:59 +02:00
|
|
|
|
2020-08-23 01:46:28 +02:00
|
|
|
return gui.refreshMainViews(refreshMainOpts{
|
2020-08-18 14:02:35 +02:00
|
|
|
main: &viewUpdateOpts{
|
|
|
|
title: "Patch",
|
|
|
|
task: task,
|
|
|
|
},
|
|
|
|
secondary: gui.secondaryPatchPanelUpdateOpts(),
|
|
|
|
})
|
2018-12-06 13:18:17 +02:00
|
|
|
}
|
|
|
|
|
2020-03-28 02:22:11 +02:00
|
|
|
// during startup, the bottleneck is fetching the reflog entries. We need these
|
|
|
|
// on startup to sort the branches by recency. So we have two phases: INITIAL, and COMPLETE.
|
2020-03-28 02:27:05 +02:00
|
|
|
// In the initial phase we don't get any reflog commits, but we asynchronously get them
|
|
|
|
// and refresh the branches after that
|
2020-03-28 02:22:11 +02:00
|
|
|
func (gui *Gui) refreshReflogCommitsConsideringStartup() {
|
|
|
|
switch gui.State.StartupStage {
|
|
|
|
case INITIAL:
|
2020-10-07 12:19:38 +02:00
|
|
|
go utils.Safe(func() {
|
2020-03-28 02:47:54 +02:00
|
|
|
_ = gui.refreshReflogCommits()
|
2020-03-28 02:22:11 +02:00
|
|
|
gui.refreshBranches()
|
|
|
|
gui.State.StartupStage = COMPLETE
|
2020-10-07 12:19:38 +02:00
|
|
|
})
|
2020-03-28 02:22:11 +02:00
|
|
|
|
|
|
|
case COMPLETE:
|
2020-03-28 02:47:54 +02:00
|
|
|
_ = gui.refreshReflogCommits()
|
2020-03-28 02:22:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-28 01:27:34 +02:00
|
|
|
// whenever we change commits, we should update branches because the upstream/downstream
|
|
|
|
// counts can change. Whenever we change branches we should probably also change commits
|
2020-03-28 02:22:11 +02:00
|
|
|
// e.g. in the case of switching branches.
|
2022-01-08 06:46:35 +02:00
|
|
|
func (gui *Gui) refreshCommits() {
|
2020-03-26 14:48:11 +02:00
|
|
|
wg := sync.WaitGroup{}
|
|
|
|
wg.Add(2)
|
2018-09-17 13:02:30 +02:00
|
|
|
|
2020-10-07 12:19:38 +02:00
|
|
|
go utils.Safe(func() {
|
2020-03-28 02:22:11 +02:00
|
|
|
gui.refreshReflogCommitsConsideringStartup()
|
|
|
|
|
2020-03-26 14:48:11 +02:00
|
|
|
gui.refreshBranches()
|
|
|
|
wg.Done()
|
2020-10-07 12:19:38 +02:00
|
|
|
})
|
2020-03-26 14:48:11 +02:00
|
|
|
|
2020-10-07 12:19:38 +02:00
|
|
|
go utils.Safe(func() {
|
2020-03-28 02:47:54 +02:00
|
|
|
_ = gui.refreshCommitsWithLimit()
|
2021-04-03 06:56:11 +02:00
|
|
|
context, ok := gui.State.Contexts.CommitFiles.GetParentContext()
|
2020-09-26 03:35:06 +02:00
|
|
|
if ok && context.GetKey() == BRANCH_COMMITS_CONTEXT_KEY {
|
|
|
|
// This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position.
|
|
|
|
// However if we've just added a brand new commit, it pushes the list down by one and so we would end up
|
|
|
|
// showing the contents of a different commit than the one we initially entered.
|
|
|
|
// Ideally we would know when to refresh the commit files context and when not to,
|
|
|
|
// or perhaps we could just pop that context off the stack whenever cycling windows.
|
|
|
|
// For now the awkwardness remains.
|
|
|
|
commit := gui.getSelectedLocalCommit()
|
|
|
|
if commit != nil {
|
|
|
|
gui.State.Panels.CommitFiles.refName = commit.RefName()
|
|
|
|
_ = gui.refreshCommitFilesView()
|
|
|
|
}
|
2020-03-27 10:12:15 +02:00
|
|
|
}
|
2020-03-26 14:48:11 +02:00
|
|
|
wg.Done()
|
2020-10-07 12:19:38 +02:00
|
|
|
})
|
2020-03-26 13:51:24 +02:00
|
|
|
|
2020-03-26 14:48:11 +02:00
|
|
|
wg.Wait()
|
2020-01-11 09:23:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) refreshCommitsWithLimit() error {
|
2020-10-07 12:45:57 +02:00
|
|
|
gui.Mutexes.BranchCommitsMutex.Lock()
|
|
|
|
defer gui.Mutexes.BranchCommitsMutex.Unlock()
|
2020-08-27 12:50:30 +02:00
|
|
|
|
2022-01-19 09:32:27 +02:00
|
|
|
refName := "HEAD"
|
|
|
|
bisectInfo := gui.Git.Bisect.GetInfo()
|
|
|
|
gui.State.BisectInfo = bisectInfo
|
|
|
|
if bisectInfo.Started() {
|
|
|
|
refName = bisectInfo.StartSha()
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
commits, err := gui.Git.Loaders.Commits.GetCommits(
|
2021-12-30 04:35:10 +02:00
|
|
|
loaders.GetCommitsOptions{
|
2020-08-22 00:49:02 +02:00
|
|
|
Limit: gui.State.Panels.Commits.LimitCommits,
|
2021-04-03 02:32:14 +02:00
|
|
|
FilterPath: gui.State.Modes.Filtering.GetPath(),
|
2020-08-22 00:49:02 +02:00
|
|
|
IncludeRebaseCommits: true,
|
2022-01-19 09:32:27 +02:00
|
|
|
RefName: refName,
|
2021-11-02 12:16:00 +02:00
|
|
|
All: gui.State.ShowWholeGitGraph,
|
2020-08-22 00:49:02 +02:00
|
|
|
},
|
|
|
|
)
|
2020-01-11 09:23:35 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gui.State.Commits = commits
|
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
return gui.postRefreshUpdate(gui.State.Contexts.BranchCommits)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 12:50:30 +02:00
|
|
|
func (gui *Gui) refreshRebaseCommits() error {
|
2020-10-07 12:45:57 +02:00
|
|
|
gui.Mutexes.BranchCommitsMutex.Lock()
|
|
|
|
defer gui.Mutexes.BranchCommitsMutex.Unlock()
|
2020-08-27 12:50:30 +02:00
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
updatedCommits, err := gui.Git.Loaders.Commits.MergeRebasingCommits(gui.State.Commits)
|
2020-08-27 12:50:30 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
gui.State.Commits = updatedCommits
|
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
return gui.postRefreshUpdate(gui.State.Contexts.BranchCommits)
|
2020-08-27 12:50:30 +02:00
|
|
|
}
|
|
|
|
|
2018-12-06 13:18:17 +02:00
|
|
|
// specific functions
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitSquashDown() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
if len(gui.State.Commits) <= 1 {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.createErrorPanel(gui.Tr.YouNoCommitsToSquash)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
|
|
|
applied, err := gui.handleMidRebaseCommand("squash")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
if applied {
|
|
|
|
return nil
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.Squash,
|
|
|
|
prompt: gui.Tr.SureSquashThisCommit,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.SquashCommitDown)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "squash")
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitFixup() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2018-12-04 10:50:11 +02:00
|
|
|
if len(gui.State.Commits) <= 1 {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.createErrorPanel(gui.Tr.YouNoCommitsToSquash)
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
|
|
|
applied, err := gui.handleMidRebaseCommand("fixup")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
if applied {
|
|
|
|
return nil
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.Fixup,
|
|
|
|
prompt: gui.Tr.SureFixupThisCommit,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.FixingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.FixupCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "fixup")
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2022-01-02 01:34:33 +02:00
|
|
|
func (gui *Gui) handleRewordCommit() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
applied, err := gui.handleMidRebaseCommand("reword")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if applied {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2020-08-16 11:31:55 +02:00
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
message, err := gui.Git.Commit.GetCommitMessage(commit.Sha)
|
2020-08-16 11:31:55 +02:00
|
|
|
if err != nil {
|
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
2022-01-09 05:04:49 +02:00
|
|
|
// TODO: use the commit message panel here
|
2020-11-28 04:35:58 +02:00
|
|
|
return gui.prompt(promptOpts{
|
2022-01-02 01:34:33 +02:00
|
|
|
title: gui.Tr.LcRewordCommit,
|
2020-11-28 04:35:58 +02:00
|
|
|
initialContent: message,
|
|
|
|
handleConfirm: func(response string) error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.RewordCommit)
|
2022-01-09 04:36:07 +02:00
|
|
|
if err := gui.Git.Rebase.RewordCommit(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, response); err != nil {
|
2020-11-28 04:35:58 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2020-03-27 12:25:37 +02:00
|
|
|
|
2020-11-28 04:35:58 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
|
|
|
},
|
2018-08-14 11:05:26 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-01-09 04:36:07 +02:00
|
|
|
func (gui *Gui) handleRewordCommitEditor() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
applied, err := gui.handleMidRebaseCommand("reword")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if applied {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.RewordCommit)
|
2022-01-09 04:36:07 +02:00
|
|
|
subProcess, err := gui.Git.Rebase.RewordCommitInEditor(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx)
|
2019-02-18 12:29:43 +02:00
|
|
|
if err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2018-08-29 14:27:17 +02:00
|
|
|
}
|
2019-02-18 12:29:43 +02:00
|
|
|
if subProcess != nil {
|
2021-04-10 03:40:42 +02:00
|
|
|
return gui.runSubprocessWithSuspenseAndRefresh(subProcess)
|
2019-02-18 12:29:43 +02:00
|
|
|
}
|
2018-08-29 14:27:17 +02:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2019-02-18 14:27:54 +02:00
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
// handleMidRebaseCommand sees if the selected commit is in fact a rebasing
|
|
|
|
// commit meaning you are trying to edit the todo file rather than actually
|
|
|
|
// begin a rebase. It then updates the todo file with that action
|
|
|
|
func (gui *Gui) handleMidRebaseCommand(action string) (bool, error) {
|
2020-08-20 00:53:10 +02:00
|
|
|
selectedCommit := gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx]
|
2019-02-24 00:42:24 +02:00
|
|
|
if selectedCommit.Status != "rebasing" {
|
|
|
|
return false, nil
|
|
|
|
}
|
|
|
|
|
2019-02-20 13:52:17 +02:00
|
|
|
// for now we do not support setting 'reword' because it requires an editor
|
|
|
|
// and that means we either unconditionally wait around for the subprocess to ask for
|
|
|
|
// our input or we set a lazygit client as the EDITOR env variable and have it
|
|
|
|
// request us to edit the commit message when prompted.
|
|
|
|
if action == "reword" {
|
2020-10-04 02:00:48 +02:00
|
|
|
return true, gui.createErrorPanel(gui.Tr.LcRewordNotSupported)
|
2019-02-20 13:52:17 +02:00
|
|
|
}
|
|
|
|
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction("Update rebase TODO")
|
|
|
|
gui.logCommand(
|
2021-04-10 09:31:23 +02:00
|
|
|
fmt.Sprintf("Updating rebase action of commit %s to '%s'", selectedCommit.ShortSha(), action),
|
|
|
|
false,
|
2022-01-05 03:01:59 +02:00
|
|
|
)
|
2021-04-10 09:31:23 +02:00
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Rebase.EditRebaseTodo(gui.State.Panels.Commits.SelectedLineIdx, action); err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
return false, gui.surfaceError(err)
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
2020-08-27 12:50:30 +02:00
|
|
|
|
|
|
|
return true, gui.refreshRebaseCommits()
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitDelete() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
applied, err := gui.handleMidRebaseCommand("drop")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if applied {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.DeleteCommitTitle,
|
|
|
|
prompt: gui.Tr.DeleteCommitPrompt,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.DeletingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.DropCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "drop")
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
2019-02-18 14:27:54 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitMoveDown() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-20 00:53:10 +02:00
|
|
|
index := gui.State.Panels.Commits.SelectedLineIdx
|
2019-02-20 11:51:24 +02:00
|
|
|
selectedCommit := gui.State.Commits[index]
|
|
|
|
if selectedCommit.Status == "rebasing" {
|
|
|
|
if gui.State.Commits[index+1].Status != "rebasing" {
|
|
|
|
return nil
|
|
|
|
}
|
2021-04-10 09:31:23 +02:00
|
|
|
|
|
|
|
// logging directly here because MoveTodoDown doesn't have enough information
|
|
|
|
// to provide a useful log
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.MoveCommitDown)
|
|
|
|
gui.logCommand(fmt.Sprintf("Moving commit %s down", selectedCommit.ShortSha()), false)
|
2021-04-10 09:31:23 +02:00
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Rebase.MoveTodoDown(index); err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2019-02-20 11:51:24 +02:00
|
|
|
}
|
2020-08-20 00:53:10 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLineIdx++
|
2020-08-29 01:52:01 +02:00
|
|
|
return gui.refreshRebaseCommits()
|
2019-02-20 11:51:24 +02:00
|
|
|
}
|
2019-02-18 14:27:54 +02:00
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.MoveCommitDown)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.MoveCommitDown(gui.State.Commits, index)
|
2019-03-03 06:21:33 +02:00
|
|
|
if err == nil {
|
2020-08-20 00:53:10 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLineIdx++
|
2019-03-03 06:21:33 +02:00
|
|
|
}
|
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
2019-02-18 14:27:54 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitMoveUp() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-20 00:53:10 +02:00
|
|
|
index := gui.State.Panels.Commits.SelectedLineIdx
|
2019-02-20 11:51:24 +02:00
|
|
|
if index == 0 {
|
|
|
|
return nil
|
2019-02-18 14:27:54 +02:00
|
|
|
}
|
2021-04-10 09:31:23 +02:00
|
|
|
|
2019-02-20 11:51:24 +02:00
|
|
|
selectedCommit := gui.State.Commits[index]
|
|
|
|
if selectedCommit.Status == "rebasing" {
|
2021-04-10 09:31:23 +02:00
|
|
|
// logging directly here because MoveTodoDown doesn't have enough information
|
|
|
|
// to provide a useful log
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.MoveCommitUp)
|
|
|
|
gui.logCommand(
|
2021-04-10 09:31:23 +02:00
|
|
|
fmt.Sprintf("Moving commit %s up", selectedCommit.ShortSha()),
|
|
|
|
false,
|
2022-01-05 03:01:59 +02:00
|
|
|
)
|
2021-04-10 09:31:23 +02:00
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Rebase.MoveTodoDown(index - 1); err != nil {
|
2020-03-28 02:47:54 +02:00
|
|
|
return gui.surfaceError(err)
|
2019-02-20 11:51:24 +02:00
|
|
|
}
|
2020-08-20 00:53:10 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLineIdx--
|
2020-08-29 01:52:01 +02:00
|
|
|
return gui.refreshRebaseCommits()
|
2019-02-20 11:51:24 +02:00
|
|
|
}
|
2019-02-18 14:27:54 +02:00
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.MovingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.MoveCommitUp)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.MoveCommitDown(gui.State.Commits, index-1)
|
2019-03-03 06:21:33 +02:00
|
|
|
if err == nil {
|
2020-08-20 00:53:10 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLineIdx--
|
2019-03-03 06:21:33 +02:00
|
|
|
}
|
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
2019-02-18 14:27:54 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitEdit() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
applied, err := gui.handleMidRebaseCommand("edit")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if applied {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.RebasingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.EditCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
err = gui.Git.Rebase.InteractiveRebase(gui.State.Commits, gui.State.Panels.Commits.SelectedLineIdx, "edit")
|
2019-03-03 06:21:33 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
2019-02-18 14:27:54 +02:00
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitAmendTo() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.AmendCommitTitle,
|
|
|
|
prompt: gui.Tr.AmendCommitPrompt,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.AmendingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.AmendCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.AmendTo(gui.State.Commits[gui.State.Panels.Commits.SelectedLineIdx].Sha)
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitPick() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2019-02-19 14:36:29 +02:00
|
|
|
applied, err := gui.handleMidRebaseCommand("pick")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if applied {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// at this point we aren't actually rebasing so we will interpret this as an
|
|
|
|
// attempt to pull. We might revoke this later after enabling configurable keybindings
|
2021-04-02 10:20:40 +02:00
|
|
|
return gui.handlePullFiles()
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCommitRevert() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-06-05 08:39:59 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
|
|
|
|
|
|
|
if commit.IsMerge() {
|
|
|
|
return gui.createRevertMergeCommitMenu(commit)
|
|
|
|
} else {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.RevertCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Commit.Revert(commit.Sha); err != nil {
|
2021-06-05 08:39:59 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
return gui.afterRevertCommit()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) createRevertMergeCommitMenu(commit *models.Commit) error {
|
|
|
|
menuItems := make([]*menuItem, len(commit.Parents))
|
|
|
|
for i, parentSha := range commit.Parents {
|
|
|
|
i := i
|
2022-01-08 05:10:01 +02:00
|
|
|
message, err := gui.Git.Commit.GetCommitMessageFirstLine(parentSha)
|
2021-06-05 08:39:59 +02:00
|
|
|
if err != nil {
|
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
menuItems[i] = &menuItem{
|
|
|
|
displayString: fmt.Sprintf("%s: %s", utils.SafeTruncate(parentSha, 8), message),
|
|
|
|
onPress: func() error {
|
|
|
|
parentNumber := i + 1
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.RevertCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Commit.RevertMerge(commit.Sha, parentNumber); err != nil {
|
2021-06-05 08:39:59 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
return gui.afterRevertCommit()
|
|
|
|
},
|
|
|
|
}
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
2021-06-05 08:39:59 +02:00
|
|
|
|
|
|
|
return gui.createMenu(gui.Tr.SelectParentCommitForMerge, menuItems, createMenuOptions{showCancel: true})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) afterRevertCommit() error {
|
2020-08-20 00:53:10 +02:00
|
|
|
gui.State.Panels.Commits.SelectedLineIdx++
|
2021-03-31 14:55:06 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: BLOCK_UI, scope: []RefreshableView{COMMITS, BRANCHES}})
|
2019-02-19 14:36:29 +02:00
|
|
|
}
|
2019-02-24 04:51:52 +02:00
|
|
|
|
2020-08-21 01:12:45 +02:00
|
|
|
func (gui *Gui) handleViewCommitFiles() error {
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2020-08-21 01:12:45 +02:00
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-04-03 06:56:11 +02:00
|
|
|
return gui.switchToCommitFilesContext(commit.Sha, true, gui.State.Contexts.BranchCommits, "commits")
|
2019-03-09 16:42:10 +02:00
|
|
|
}
|
2019-03-23 15:46:08 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCreateFixupCommit() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2019-04-07 03:35:34 +02:00
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
prompt := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.SureCreateFixupCommit,
|
|
|
|
map[string]string{
|
|
|
|
"commit": commit.Sha,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.CreateFixupCommit,
|
|
|
|
prompt: prompt,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.CreateFixupCommit)
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Commit.CreateFixupCommit(commit.Sha); err != nil {
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2019-04-07 03:35:34 +02:00
|
|
|
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
|
|
|
},
|
|
|
|
})
|
2019-04-07 03:35:34 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleSquashAllAboveFixupCommits() error {
|
2020-03-29 01:11:15 +02:00
|
|
|
if ok, err := gui.validateNotInFilterMode(); err != nil || !ok {
|
2020-03-28 07:28:35 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2019-04-07 03:35:34 +02:00
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-10-04 02:00:48 +02:00
|
|
|
prompt := utils.ResolvePlaceholderString(
|
|
|
|
gui.Tr.SureSquashAboveCommits,
|
|
|
|
map[string]string{
|
|
|
|
"commit": commit.Sha,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.SquashAboveCommits,
|
|
|
|
prompt: prompt,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.SquashingStatus, func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.SquashAllAboveFixupCommits)
|
2022-01-08 05:10:01 +02:00
|
|
|
err := gui.Git.Rebase.SquashAllAboveFixupCommits(commit.Sha)
|
2020-08-15 08:36:39 +02:00
|
|
|
return gui.handleGenericMergeCommandResult(err)
|
|
|
|
})
|
2019-04-07 03:35:34 +02:00
|
|
|
},
|
2020-08-15 08:36:39 +02:00
|
|
|
})
|
2019-04-07 03:35:34 +02:00
|
|
|
}
|
2019-04-02 10:53:16 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleTagCommit() error {
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2019-11-18 00:38:36 +02:00
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-09-12 01:29:52 +02:00
|
|
|
return gui.createTagMenu(commit.Sha)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) createTagMenu(commitSha string) error {
|
2021-09-12 00:19:25 +02:00
|
|
|
items := []*menuItem{
|
2021-09-12 01:29:52 +02:00
|
|
|
{
|
2021-09-12 13:48:07 +02:00
|
|
|
displayString: gui.Tr.LcLightweightTag,
|
2021-09-12 01:29:52 +02:00
|
|
|
onPress: func() error {
|
|
|
|
return gui.handleCreateLightweightTag(commitSha)
|
2021-09-12 20:34:37 +02:00
|
|
|
},
|
|
|
|
},
|
2021-09-12 01:29:52 +02:00
|
|
|
{
|
2021-09-12 13:48:07 +02:00
|
|
|
displayString: gui.Tr.LcAnnotatedTag,
|
2021-09-12 01:29:52 +02:00
|
|
|
onPress: func() error {
|
|
|
|
return gui.handleCreateAnnotatedTag(commitSha)
|
2021-09-12 20:34:37 +02:00
|
|
|
},
|
|
|
|
},
|
2021-09-12 00:19:25 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 13:48:39 +02:00
|
|
|
return gui.createMenu(gui.Tr.TagMenuTitle, items, createMenuOptions{showCancel: true})
|
2021-09-12 00:19:25 +02:00
|
|
|
}
|
|
|
|
|
2022-01-08 06:46:35 +02:00
|
|
|
func (gui *Gui) afterTagCreate() error {
|
2021-10-29 01:21:07 +02:00
|
|
|
gui.State.Panels.Tags.SelectedLineIdx = 0 // Set to the top
|
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS, TAGS}})
|
2021-09-12 01:29:52 +02:00
|
|
|
}
|
|
|
|
|
2021-09-12 00:19:25 +02:00
|
|
|
func (gui *Gui) handleCreateAnnotatedTag(commitSha string) error {
|
|
|
|
return gui.prompt(promptOpts{
|
|
|
|
title: gui.Tr.TagNameTitle,
|
2021-09-12 01:29:52 +02:00
|
|
|
handleConfirm: func(tagName string) error {
|
2021-09-12 00:19:25 +02:00
|
|
|
return gui.prompt(promptOpts{
|
|
|
|
title: gui.Tr.TagMessageTitle,
|
|
|
|
handleConfirm: func(msg string) error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.CreateAnnotatedTag)
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Tag.CreateAnnotated(tagName, commitSha, msg); err != nil {
|
2021-09-12 00:19:25 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2022-01-08 06:46:35 +02:00
|
|
|
return gui.afterTagCreate()
|
2021-09-12 00:19:25 +02:00
|
|
|
},
|
|
|
|
})
|
|
|
|
},
|
|
|
|
})
|
2019-11-18 00:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) handleCreateLightweightTag(commitSha string) error {
|
2020-11-28 04:35:58 +02:00
|
|
|
return gui.prompt(promptOpts{
|
|
|
|
title: gui.Tr.TagNameTitle,
|
2021-09-12 01:29:52 +02:00
|
|
|
handleConfirm: func(tagName string) error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.CreateLightweightTag)
|
2022-01-08 05:10:01 +02:00
|
|
|
if err := gui.Git.Tag.CreateLightweight(tagName, commitSha); err != nil {
|
2020-11-28 04:35:58 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2022-01-08 06:46:35 +02:00
|
|
|
return gui.afterTagCreate()
|
2020-11-28 04:35:58 +02:00
|
|
|
},
|
2019-11-18 00:38:36 +02:00
|
|
|
})
|
|
|
|
}
|
2020-01-07 11:24:10 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCheckoutCommit() error {
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2020-01-07 11:24:10 +02:00
|
|
|
if commit == nil {
|
2020-01-09 13:08:28 +02:00
|
|
|
return nil
|
2020-01-07 11:24:10 +02:00
|
|
|
}
|
|
|
|
|
2020-08-15 08:38:16 +02:00
|
|
|
return gui.ask(askOpts{
|
2020-10-04 02:00:48 +02:00
|
|
|
title: gui.Tr.LcCheckoutCommit,
|
|
|
|
prompt: gui.Tr.SureCheckoutThisCommit,
|
2020-08-15 08:36:39 +02:00
|
|
|
handleConfirm: func() error {
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.CheckoutCommit)
|
2022-01-05 02:57:32 +02:00
|
|
|
return gui.handleCheckoutRef(commit.Sha, handleCheckoutRefOptions{})
|
2020-08-15 08:36:39 +02:00
|
|
|
},
|
|
|
|
})
|
2020-01-07 11:24:10 +02:00
|
|
|
}
|
2020-01-09 12:34:17 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleCreateCommitResetMenu() error {
|
2020-08-22 01:48:20 +02:00
|
|
|
commit := gui.getSelectedLocalCommit()
|
2020-02-15 23:59:48 +02:00
|
|
|
if commit == nil {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.createErrorPanel(gui.Tr.NoCommitsThisBranch)
|
2020-02-15 23:59:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return gui.createResetMenu(commit.Sha)
|
|
|
|
}
|
2020-02-23 12:53:30 +02:00
|
|
|
|
2022-01-08 06:46:35 +02:00
|
|
|
func (gui *Gui) handleOpenSearchForCommitsPanel(string) error {
|
2020-02-23 13:00:42 +02:00
|
|
|
// we usually lazyload these commits but now that we're searching we need to load them now
|
|
|
|
if gui.State.Panels.Commits.LimitCommits {
|
|
|
|
gui.State.Panels.Commits.LimitCommits = false
|
2021-03-31 14:55:06 +02:00
|
|
|
if err := gui.refreshSidePanels(refreshOptions{mode: ASYNC, scope: []RefreshableView{COMMITS}}); err != nil {
|
2020-02-23 13:00:42 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
return gui.handleOpenSearch("commits")
|
2020-02-23 13:00:42 +02:00
|
|
|
}
|
2020-03-18 23:45:21 +02:00
|
|
|
|
2021-04-02 10:20:40 +02:00
|
|
|
func (gui *Gui) handleGotoBottomForCommitsPanel() error {
|
2020-03-28 04:57:16 +02:00
|
|
|
// we usually lazyload these commits but now that we're searching we need to load them now
|
|
|
|
if gui.State.Panels.Commits.LimitCommits {
|
|
|
|
gui.State.Panels.Commits.LimitCommits = false
|
2021-03-31 14:55:06 +02:00
|
|
|
if err := gui.refreshSidePanels(refreshOptions{mode: SYNC, scope: []RefreshableView{COMMITS}}); err != nil {
|
2020-03-28 04:57:16 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-17 13:58:30 +02:00
|
|
|
for _, context := range gui.getListContexts() {
|
2021-11-01 00:35:54 +02:00
|
|
|
if context.GetViewName() == "commits" {
|
2021-04-02 10:20:40 +02:00
|
|
|
return context.handleGotoBottom()
|
2020-03-28 04:57:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2020-10-12 10:13:19 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleCopySelectedCommitMessageToClipboard() error {
|
|
|
|
commit := gui.getSelectedLocalCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-08 05:10:01 +02:00
|
|
|
message, err := gui.Git.Commit.GetCommitMessage(commit.Sha)
|
2020-10-12 10:13:19 +02:00
|
|
|
if err != nil {
|
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2020-11-21 08:15:43 +02:00
|
|
|
|
2022-01-05 03:01:59 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.CopyCommitMessageToClipboard)
|
2022-01-05 02:57:32 +02:00
|
|
|
if err := gui.OSCommand.CopyToClipboard(message); err != nil {
|
2020-11-21 08:15:43 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.raiseToast(gui.Tr.CommitMessageCopiedToClipboard)
|
|
|
|
|
|
|
|
return nil
|
2020-10-12 10:13:19 +02:00
|
|
|
}
|
2021-11-02 12:16:00 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleOpenLogMenu() error {
|
|
|
|
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
|
|
|
|
{
|
|
|
|
displayString: gui.Tr.ToggleShowGitGraphAll,
|
|
|
|
onPress: func() error {
|
|
|
|
gui.State.ShowWholeGitGraph = !gui.State.ShowWholeGitGraph
|
|
|
|
|
|
|
|
if gui.State.ShowWholeGitGraph {
|
|
|
|
gui.State.Panels.Commits.LimitCommits = false
|
|
|
|
}
|
|
|
|
|
|
|
|
return gui.WithWaitingStatus(gui.Tr.LcLoadingCommits, func() error {
|
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: SYNC, scope: []RefreshableView{COMMITS}})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: gui.Tr.ShowGitGraph,
|
|
|
|
opensMenu: true,
|
|
|
|
onPress: func() error {
|
|
|
|
onSelect := func(value string) {
|
2021-12-29 02:50:20 +02:00
|
|
|
gui.UserConfig.Git.Log.ShowGraph = value
|
2021-11-02 12:16:00 +02:00
|
|
|
gui.render()
|
|
|
|
}
|
|
|
|
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
|
|
|
|
{
|
|
|
|
displayString: "always",
|
|
|
|
onPress: func() error {
|
|
|
|
onSelect("always")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: "never",
|
|
|
|
onPress: func() error {
|
|
|
|
onSelect("never")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: "when maximised",
|
|
|
|
onPress: func() error {
|
|
|
|
onSelect("when-maximised")
|
|
|
|
return nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, createMenuOptions{showCancel: true})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: gui.Tr.SortCommits,
|
|
|
|
opensMenu: true,
|
|
|
|
onPress: func() error {
|
|
|
|
onSelect := func(value string) error {
|
2021-12-29 02:50:20 +02:00
|
|
|
gui.UserConfig.Git.Log.Order = value
|
2021-11-02 12:16:00 +02:00
|
|
|
return gui.WithWaitingStatus(gui.Tr.LcLoadingCommits, func() error {
|
|
|
|
return gui.refreshSidePanels(refreshOptions{mode: SYNC, scope: []RefreshableView{COMMITS}})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return gui.createMenu(gui.Tr.LogMenuTitle, []*menuItem{
|
|
|
|
{
|
|
|
|
displayString: "topological (topo-order)",
|
|
|
|
onPress: func() error {
|
|
|
|
return onSelect("topo-order")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: "date-order",
|
|
|
|
onPress: func() error {
|
|
|
|
return onSelect("date-order")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
displayString: "author-date-order",
|
|
|
|
onPress: func() error {
|
|
|
|
return onSelect("author-date-order")
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, createMenuOptions{showCancel: true})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}, createMenuOptions{showCancel: true})
|
|
|
|
}
|
2021-12-28 04:31:20 +02:00
|
|
|
|
|
|
|
func (gui *Gui) handleOpenCommitInBrowser() error {
|
|
|
|
commit := gui.getSelectedLocalCommit()
|
|
|
|
if commit == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:58:09 +02:00
|
|
|
hostingServiceMgr := gui.getHostingServiceMgr()
|
|
|
|
|
|
|
|
url, err := hostingServiceMgr.GetCommitURL(commit.Sha)
|
2021-12-28 04:31:20 +02:00
|
|
|
if err != nil {
|
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
2021-12-28 04:58:09 +02:00
|
|
|
|
2022-01-06 02:44:41 +02:00
|
|
|
gui.logAction(gui.Tr.Actions.OpenCommitInBrowser)
|
2022-01-07 06:01:07 +02:00
|
|
|
if err := gui.OSCommand.OpenLink(url); err != nil {
|
2021-12-28 04:58:09 +02:00
|
|
|
return gui.surfaceError(err)
|
|
|
|
}
|
|
|
|
|
2021-12-28 04:31:20 +02:00
|
|
|
return nil
|
|
|
|
}
|