This commit is contained in:
Brandon Dong 2026-08-30 13:30:56 -07:00 committed by GitHub
commit 10a024b564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 66 additions and 7 deletions

View file

@ -237,7 +237,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
}

View file

@ -66,7 +66,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
}
}
func (self *ReflogCommitsContext) CanRebase() bool {
func (self *ReflogCommitsContext) CanRebase(currentBranch *models.Branch) bool {
return false
}

View file

@ -49,7 +49,7 @@ func NewStashContext(
}
}
func (self *StashContext) CanRebase() bool {
func (self *StashContext) CanRebase(currentBranch *models.Branch) bool {
return false
}

View file

@ -170,8 +170,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 {

View file

@ -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() {

View file

@ -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"))
},
})

View file

@ -373,6 +373,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,