1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-27 12:32:37 +02:00
lazygit/pkg/integration/tests/branch/reset_to_upstream.go
Stefan Haller 33e81f717d Extend reset/rebase test to use upstream branch name that is different from local one
The easiest way to do that is to rename the local branch after pushing.

This shows various levels of brokenness for the reset and rebase to upstream
commands: both menu entries display the wrong upstream branch name in the menu
(the local one rather than the remote one); executing the rebase command works
correctly though, the rebase command uses the right branch name. Resetting
fails, though.

We'll fix this in the next commit.
2025-01-04 15:46:14 +01:00

118 lines
3.4 KiB
Go

package branch
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var ResetToUpstream = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Hard reset the current branch to the selected branch upstream",
ExtraCmdArgs: []string{},
Skip: false,
SetupConfig: func(config *config.AppConfig) {},
SetupRepo: func(shell *Shell) {
shell.
CloneIntoRemote("origin").
NewBranch("hard-branch").
EmptyCommit("hard commit").
PushBranchAndSetUpstream("origin", "hard-branch").
NewBranch("soft-branch").
EmptyCommit("soft commit").
PushBranchAndSetUpstream("origin", "soft-branch").
RenameCurrentBranch("soft-branch-local").
NewBranch("base").
EmptyCommit("base-branch commit").
CreateFile("file-1", "content").
GitAdd("file-1").
Commit("commit with file").
CreateFile("file-2", "content").
GitAdd("file-2")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
// soft reset
t.Views().Branches().
Focus().
Lines(
Contains("base").IsSelected(),
Contains("soft-branch-local"),
Contains("hard-branch"),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Reset checked-out branch onto upstream of selected branch")).
Tooltip(Contains("Disabled: The selected branch has no upstream (or the upstream is not stored locally)")).
Confirm().
Tap(func() {
t.ExpectToast(Equals("Disabled: The selected branch has no upstream (or the upstream is not stored locally)"))
}).
Cancel()
}).
SelectNextItem().
Lines(
Contains("base"),
Contains("soft-branch-local").IsSelected(),
Contains("hard-branch"),
).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
/* EXPECTED:
Select(Contains("Reset checked-out branch onto origin/soft-branch...")).
ACTUAL: */
Select(Contains("Reset checked-out branch onto origin/soft-branch-local...")).
Confirm()
t.ExpectPopup().Menu().
/* EXPECTED:
Title(Equals("Reset to origin/soft-branch")).
ACTUAL: */
Title(Equals("Reset to origin/soft-branch-local")).
Select(Contains("Soft reset")).
Confirm()
// Bug: the command fails
t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Contains("fatal: ambiguous argument 'origin/soft-branch-local': unknown revision or path not in the working tree.")).
Confirm()
})
/* Since the command failed, the following assertions are not valid
t.Views().Commits().Lines(
Contains("soft commit"),
Contains("hard commit"),
)
t.Views().Files().Lines(
Contains("file-1").Contains("A"),
Contains("file-2").Contains("A"),
)
*/
// hard reset
t.Views().Branches().
Focus().
Lines(
Contains("base"),
Contains("soft-branch-local").IsSelected(),
Contains("hard-branch"),
).
NavigateToLine(Contains("hard-branch")).
Press(keys.Branches.SetUpstream).
Tap(func() {
t.ExpectPopup().Menu().
Title(Equals("Upstream options")).
Select(Contains("Reset checked-out branch onto origin/hard-branch...")).
Confirm()
t.ExpectPopup().Menu().
Title(Equals("Reset to origin/hard-branch")).
Select(Contains("Hard reset")).
Confirm()
})
t.Views().Commits().Lines(Contains("hard commit"))
t.Views().Files().IsEmpty()
},
})