Skip to content

Commit

Permalink
chore: suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AzraelSec committed Jun 3, 2024
1 parent 15cf8c5 commit c36bbb1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
19 changes: 15 additions & 4 deletions pkg/gui/controllers/branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ func (self *BranchesController) GetKeybindings(opts types.KeybindingsOpts) []*ty
DisplayOnScreen: true,
},
{
Key: opts.GetKey(opts.Config.Branches.SquashBranch),
Handler: opts.Guards.OutsideFilterMode(self.squash),
GetDisabledReason: self.require(self.singleItemSelected()),
Description: self.c.Tr.Squash,
Key: opts.GetKey(opts.Config.Branches.SquashBranch),
Handler: opts.Guards.OutsideFilterMode(self.squash),
GetDisabledReason: self.require(self.singleItemSelected(self.notMergingIntoYourself)),
Description: self.c.Tr.Squash,
},
{
Key: opts.GetKey(opts.Config.Branches.FastForward),
Expand Down Expand Up @@ -813,3 +813,14 @@ func (self *BranchesController) branchIsReal(branch *models.Branch) *types.Disab

return nil
}

func (self *BranchesController) notMergingIntoYourself(branch *models.Branch) *types.DisabledReason {
selectedBranchName := branch.Name
checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef().Name

if checkedOutBranch == selectedBranchName {
return &types.DisabledReason{Text: self.c.Tr.CantMergeBranchIntoItself}
}

return nil
}
8 changes: 0 additions & 8 deletions pkg/gui/controllers/helpers/merge_and_rebase_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,6 @@ func (self *MergeAndRebaseHelper) SquashBranch(refName string) error {
"selectedBranch": refName,
},
),
DisabledReason: &types.DisabledReason{
Text: self.c.Tr.CantMergeBranchIntoItself,
ShowErrorInPanel: checkedOutBranchName == refName,
},
},
{
Label: self.c.Tr.SquashInCommitTitle,
Expand All @@ -355,10 +351,6 @@ func (self *MergeAndRebaseHelper) SquashBranch(refName string) error {
"selectedBranch": refName,
},
),
DisabledReason: &types.DisabledReason{
Text: self.c.Tr.CantMergeBranchIntoItself,
ShowErrorInPanel: checkedOutBranchName == refName,
},
},
},
})
Expand Down
18 changes: 15 additions & 3 deletions pkg/gui/controllers/remote_branches_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ func (self *RemoteBranchesController) GetKeybindings(opts types.KeybindingsOpts)
DisplayOnScreen: true,
},
{
Key: opts.GetKey(opts.Config.Branches.SquashBranch),
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.squash)),
Description: self.c.Tr.Squash,
Key: opts.GetKey(opts.Config.Branches.SquashBranch),
Handler: opts.Guards.OutsideFilterMode(self.withItem(self.squash)),
GetDisabledReason: self.require(self.singleItemSelected(self.notMergingIntoYourself)),
Description: self.c.Tr.Squash,
},
{
Key: opts.GetKey(opts.Config.Branches.RebaseBranch),
Expand Down Expand Up @@ -196,3 +197,14 @@ func (self *RemoteBranchesController) newLocalBranch(selectedBranch *models.Remo
func (self *RemoteBranchesController) checkoutBranch(selectedBranch *models.RemoteBranch) error {
return self.c.Helpers().Refs.CheckoutRemoteBranch(selectedBranch.FullName(), selectedBranch.Name)
}

func (self *RemoteBranchesController) notMergingIntoYourself(branch *models.RemoteBranch) *types.DisabledReason {
selectedBranchName := branch.Name
checkedOutBranch := self.c.Helpers().Refs.GetCheckedOutRef().Name

if checkedOutBranch == selectedBranchName {
return &types.DisabledReason{Text: self.c.Tr.CantMergeBranchIntoItself}
}

return nil
}

0 comments on commit c36bbb1

Please sign in to comment.