From 66308f3095ed47f56056b50fe9b513bbf3dcc5af Mon Sep 17 00:00:00 2001 From: Brandon Date: Sat, 11 Jul 2026 00:28:32 -0700 Subject: [PATCH] Allow rebase custom patch options for subcommits-started patch if from current branch Semantically, starting a custom patch from the commits panel vs the subcommits panel of the currently checked-out branch should be identical. However, the rebase-related options are currently hidden for the latter case. This code change matches the two in behavior. --- pkg/gui/context/local_commits_context.go | 2 +- pkg/gui/context/reflog_commits_context.go | 2 +- pkg/gui/context/stash_context.go | 2 +- pkg/gui/context/sub_commits_context.go | 4 +- .../switch_to_diff_files_controller.go | 4 +- .../move_to_index_from_subcommit.go | 58 +++++++++++++++++++ pkg/integration/tests/test_list.go | 1 + 7 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 pkg/integration/tests/patch_building/move_to_index_from_subcommit.go diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index a66c720c9ad..17aaa33ddfc 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -161,7 +161,7 @@ func NewLocalCommitsViewModel(getModel func() []*models.Commit, c *ContextCommon return self } -func (self *LocalCommitsContext) CanRebase() bool { +func (self *LocalCommitsContext) CanRebase(currentBranch *models.Branch) bool { return true } diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 6358fbbb003..303951c88ef 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -66,7 +66,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext { } } -func (self *ReflogCommitsContext) CanRebase() bool { +func (self *ReflogCommitsContext) CanRebase(currentBranch *models.Branch) bool { return false } diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index 2014de9f309..80745d13573 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -49,7 +49,7 @@ func NewStashContext( } } -func (self *StashContext) CanRebase() bool { +func (self *StashContext) CanRebase(currentBranch *models.Branch) bool { return false } diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index 4e05c9594a2..84f92703bc3 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -171,8 +171,8 @@ func (self *SubCommitsViewModel) GetShowBranchHeads() bool { return self.showBranchHeads } -func (self *SubCommitsContext) CanRebase() bool { - return false +func (self *SubCommitsContext) CanRebase(currentBranch *models.Branch) bool { + return self.GetRef() == currentBranch } func (self *SubCommitsContext) GetSelectedRef() models.Ref { diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index afdf92c80ad..9f826e6ca1f 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -13,7 +13,7 @@ var _ types.IController = &SwitchToDiffFilesController{} type CanSwitchToDiffFiles interface { types.IListContext - CanRebase() bool + CanRebase(currentBranch *models.Branch) bool GetSelectedRef() models.Ref GetSelectedRefRangeForDiffFiles() *types.RefRange } @@ -69,7 +69,7 @@ func (self *SwitchToDiffFilesController) enter() error { refsRange := self.context.GetSelectedRefRangeForDiffFiles() commitFilesContext := self.c.Contexts().CommitFiles - canRebase := self.context.CanRebase() + canRebase := self.context.CanRebase(self.c.Helpers().Refs.GetCheckedOutRef()) if canRebase { if self.c.Modes().Diffing.Active() { if self.c.Modes().Diffing.Ref != ref.RefName() { diff --git a/pkg/integration/tests/patch_building/move_to_index_from_subcommit.go b/pkg/integration/tests/patch_building/move_to_index_from_subcommit.go new file mode 100644 index 00000000000..4d5e55ef623 --- /dev/null +++ b/pkg/integration/tests/patch_building/move_to_index_from_subcommit.go @@ -0,0 +1,58 @@ +package patch_building + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var MoveToIndexFromSubcommit = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Move a patch from a commit of the current branch to the index", + ExtraCmdArgs: []string{}, + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFileAndAdd("file1", "file1 content\n") + shell.CreateFileAndAdd("file2", "file2 content\n") + shell.Commit("first commit") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Branches(). + Focus(). + Lines( + Contains("master").IsSelected(), + ). + PressEnter() + + t.Views().SubCommits(). + IsFocused(). + Lines( + Contains("first commit").IsSelected(), + ). + PressEnter() + + t.Views().CommitFiles(). + IsFocused(). + Lines( + Equals("▼ /").IsSelected(), + Contains("file1"), + Contains("file2"), + ). + SelectNextItem(). + PressPrimaryAction() + + t.Views().Information().Content(Contains("Building patch")) + + t.Views().Secondary().Content(Contains("+file1 content")) + + t.Common().SelectPatchOption(Contains("Move patch out into index")) + + t.Views().Files(). + Lines( + Contains("A").Contains("file1"), + ). + Focus() + + t.Views().Main(). + Content(Contains("file1 content")) + }, +}) diff --git a/pkg/integration/tests/test_list.go b/pkg/integration/tests/test_list.go index abf13073ed0..cfe15e9fdfc 100644 --- a/pkg/integration/tests/test_list.go +++ b/pkg/integration/tests/test_list.go @@ -360,6 +360,7 @@ var tests = []*components.IntegrationTest{ patch_building.MoveToEarlierCommitFromAddedFile, patch_building.MoveToIndex, patch_building.MoveToIndexFromAddedFileWithConflict, + patch_building.MoveToIndexFromSubcommit, patch_building.MoveToIndexPartOfAdjacentAddedLines, patch_building.MoveToIndexPartial, patch_building.MoveToIndexWithConflict,