Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/gui/context/local_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/context/reflog_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func NewReflogCommitsContext(c *ContextCommon) *ReflogCommitsContext {
}
}

func (self *ReflogCommitsContext) CanRebase() bool {
func (self *ReflogCommitsContext) CanRebase(currentBranch *models.Branch) bool {
return false
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/context/stash_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func NewStashContext(
}
}

func (self *StashContext) CanRebase() bool {
func (self *StashContext) CanRebase(currentBranch *models.Branch) bool {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/context/sub_commits_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions pkg/gui/controllers/switch_to_diff_files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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"))
},
})
1 change: 1 addition & 0 deletions pkg/integration/tests/test_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading