mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-04-27 12:32:37 +02:00
Fix reset/rebase to upstream (#4151)
- **PR Description** Resetting to the upstream branch was broken when the remote branch has a different name than the local branch. Rebasing onto the upstream worked fine, but also displayed the wrong branch name in the menu. Fixes #4148.
This commit is contained in:
commit
13829d8ff7
@ -194,6 +194,10 @@ func (self *BranchesController) GetOnRenderToMain() func() {
|
||||
}
|
||||
|
||||
func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branch) error {
|
||||
upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(),
|
||||
selectedBranch.ShortUpstreamRefName(),
|
||||
self.c.Tr.UpstreamGenericName)
|
||||
|
||||
viewDivergenceItem := &types.MenuItem{
|
||||
LabelColumns: []string{self.c.Tr.ViewDivergenceFromUpstream},
|
||||
OnPress: func() error {
|
||||
@ -204,7 +208,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
|
||||
|
||||
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
|
||||
Ref: branch,
|
||||
TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), branch.ShortUpstreamRefName()),
|
||||
TitleRef: fmt.Sprintf("%s <-> %s", branch.RefName(), upstream),
|
||||
RefToShowDivergenceFrom: branch.FullUpstreamRefName(),
|
||||
Context: self.context(),
|
||||
ShowBranchHeads: false,
|
||||
@ -293,9 +297,6 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
|
||||
Key: 's',
|
||||
}
|
||||
|
||||
upstream := lo.Ternary(selectedBranch.RemoteBranchStoredLocally(),
|
||||
fmt.Sprintf("%s/%s", selectedBranch.UpstreamRemote, selectedBranch.Name),
|
||||
self.c.Tr.UpstreamGenericName)
|
||||
upstreamResetOptions := utils.ResolvePlaceholderString(
|
||||
self.c.Tr.ViewUpstreamResetOptions,
|
||||
map[string]string{"upstream": upstream},
|
||||
@ -332,7 +333,7 @@ func (self *BranchesController) viewUpstreamOptions(selectedBranch *models.Branc
|
||||
LabelColumns: []string{upstreamRebaseOptions},
|
||||
OpensMenu: true,
|
||||
OnPress: func() error {
|
||||
if err := self.c.Helpers().MergeAndRebase.RebaseOntoRef(selectedBranch.ShortUpstreamRefName()); err != nil {
|
||||
if err := self.c.Helpers().MergeAndRebase.RebaseOntoRef(upstream); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
|
@ -142,6 +142,10 @@ func (self *Shell) NewBranchFrom(name string, from string) *Shell {
|
||||
return self.RunCommand([]string{"git", "checkout", "-b", name, from})
|
||||
}
|
||||
|
||||
func (self *Shell) RenameCurrentBranch(newName string) *Shell {
|
||||
return self.RunCommand([]string{"git", "branch", "-m", newName})
|
||||
}
|
||||
|
||||
func (self *Shell) Checkout(name string) *Shell {
|
||||
return self.RunCommand([]string{"git", "checkout", name})
|
||||
}
|
||||
|
@ -16,8 +16,9 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
EmptyCommit("ensure-master").
|
||||
EmptyCommit("to-be-added"). // <- this will only exist remotely
|
||||
PushBranchAndSetUpstream("origin", "master").
|
||||
RenameCurrentBranch("master-local").
|
||||
HardReset("HEAD~1").
|
||||
NewBranchFrom("base-branch", "master").
|
||||
NewBranchFrom("base-branch", "master-local").
|
||||
EmptyCommit("base-branch-commit").
|
||||
NewBranch("target").
|
||||
EmptyCommit("target-commit")
|
||||
@ -34,13 +35,13 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Lines(
|
||||
Contains("target").IsSelected(),
|
||||
Contains("base-branch"),
|
||||
Contains("master"),
|
||||
Contains("master-local"),
|
||||
).
|
||||
SelectNextItem().
|
||||
Lines(
|
||||
Contains("target"),
|
||||
Contains("base-branch").IsSelected(),
|
||||
Contains("master"),
|
||||
Contains("master-local"),
|
||||
).
|
||||
Press(keys.Branches.SetUpstream).
|
||||
Tap(func() {
|
||||
@ -58,7 +59,7 @@ var RebaseToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Lines(
|
||||
Contains("target"),
|
||||
Contains("base-branch"),
|
||||
Contains("master").IsSelected(),
|
||||
Contains("master-local").IsSelected(),
|
||||
).
|
||||
Press(keys.Branches.SetUpstream).
|
||||
Tap(func() {
|
||||
|
@ -19,6 +19,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
NewBranch("soft-branch").
|
||||
EmptyCommit("soft commit").
|
||||
PushBranchAndSetUpstream("origin", "soft-branch").
|
||||
RenameCurrentBranch("soft-branch-local").
|
||||
NewBranch("base").
|
||||
EmptyCommit("base-branch commit").
|
||||
CreateFile("file-1", "content").
|
||||
@ -33,7 +34,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("base").IsSelected(),
|
||||
Contains("soft-branch"),
|
||||
Contains("soft-branch-local"),
|
||||
Contains("hard-branch"),
|
||||
).
|
||||
Press(keys.Branches.SetUpstream).
|
||||
@ -51,7 +52,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
SelectNextItem().
|
||||
Lines(
|
||||
Contains("base"),
|
||||
Contains("soft-branch").IsSelected(),
|
||||
Contains("soft-branch-local").IsSelected(),
|
||||
Contains("hard-branch"),
|
||||
).
|
||||
Press(keys.Branches.SetUpstream).
|
||||
@ -80,7 +81,7 @@ var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("base"),
|
||||
Contains("soft-branch").IsSelected(),
|
||||
Contains("soft-branch-local").IsSelected(),
|
||||
Contains("hard-branch"),
|
||||
).
|
||||
NavigateToLine(Contains("hard-branch")).
|
||||
|
Loading…
x
Reference in New Issue
Block a user