Repository: jesseduffield/lazygit (language: go)

Issue:
Focus commits view after moving custom patch into new commit
**Is your feature request related to a problem? Please describe.**
When a custom patch is moved out into a new commit, we stay in the commit files view but end up looking at the new commit's files. This is a bit jarring: the important context we want to show the user is where this new commit is situated compared to the existing ones. The user already knows what changes the new commit contains because they just selected the changes themselves, and if they want to double-check they can easily press enter to view them.

**Describe the solution you'd like**
Focus the commits view after moving a custom patch out into a new commit.



Discussion / hints:
Hey @jesseduffield - I started working on this, but I need clarification on the best path.

I was trying to intercept the error coming from `CheckMergeOrRebase` to avoid focusing the local commit's context in case of an error here: https://github.com/jesseduffield/lazygit/blob/49df908dd310a9cf793a58d974256e9368f4cdd6/pkg/gui/controllers/custom_patch_options_menu_action.go#L219

The problem is that the `isMergeConflictErr` method does not propagate the original error and returns the one coming from the `ErrorMsg` method: https://github.com/jesseduffield/lazygit/blob/49df908dd310a9cf793a58d974256e9368f4cdd6/pkg/gui/controllers/helpers/merge_and_rebase_helper.go#L173

What do you think is the best solution here? Thanks!

P.S. Feel free to assign this issue to me :) 

Fix patch:
diff --git a/pkg/gui/controllers/custom_patch_options_menu_action.go b/pkg/gui/controllers/custom_patch_options_menu_action.go
index 2d57f0ac039..f5099ae2e26 100644
--- a/pkg/gui/controllers/custom_patch_options_menu_action.go
+++ b/pkg/gui/controllers/custom_patch_options_menu_action.go
@@ -217,7 +217,10 @@ func (self *CustomPatchOptionsMenuAction) handlePullPatchIntoNewCommit() error {
 					_ = self.c.Helpers().Commits.PopCommitMessageContexts()
 					self.c.LogAction(self.c.Tr.Actions.MovePatchIntoNewCommit)
 					err := self.c.Git().Patch.PullPatchIntoNewCommit(self.c.Model().Commits, commitIndex, summary, description)
-					return self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err)
+					if err := self.c.Helpers().MergeAndRebase.CheckMergeOrRebase(err); err != nil {
+						return err
+					}
+					return self.c.PushContext(self.c.Contexts().LocalCommits)
 				})
 			},
 		},


Test patch:
diff --git a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go b/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go
index dd0b4c3f211..62dfb1dec65 100644
--- a/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go
+++ b/pkg/integration/tests/patch_building/move_to_new_commit_partial_hunk.go
@@ -51,6 +51,16 @@ var MoveToNewCommitPartialHunk = NewIntegrationTest(NewIntegrationTestArgs{
 			InitialText(Equals("")).
 			Type("new commit").Confirm()
 
+		t.Views().Commits().
+			IsFocused().
+			Lines(
+				Contains("third commit"),
+				Contains("new commit").IsSelected(),
+				Contains("commit to move from"),
+				Contains("first commit"),
+			).
+			PressEnter()
+
 		t.Views().CommitFiles().
 			IsFocused().
 			Lines(