-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add worktree option to fast forwarding operation (#4051)
- **PR Description** Fix a reported issue regarding Fast-forwarding a branch that is checked out in a different worktree. It's reported, and I could [repro](#2957 (comment)), that whenever such an action is taken, the current worktree is polluted with unwanted File changes related to the Fast-forward operation. A solution is suggested – and tested to produce expected results – that adding `--work-tree` option to the generated command should fix the issue. [Issue: 2957](#2957) I'm proposing to merge these changes as it produces expected results: <img width="1722" alt="Screenshot 2024-11-08 at 19 55 31" src="https://github.com/user-attachments/assets/89ac1c8d-7a64-4d88-afd9-3ec3d41705f1"> - **Please check if the PR fulfills these requirements** * [ ] Cheatsheets are up-to-date (run `go generate ./...`) * [x] Code has been formatted (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#code-formatting)) * [ ] Tests have been added/updated (see [here](https://github.com/jesseduffield/lazygit/blob/master/pkg/integration/README.md) for the integration test guide) * [ ] Text is internationalised (see [here](https://github.com/jesseduffield/lazygit/blob/master/CONTRIBUTING.md#internationalisation)) * [ ] If a new UserConfig entry was added, make sure it can be hot-reloaded (see [here](https://github.com/jesseduffield/lazygit/blob/master/docs/dev/Codebase_Guide.md#using-userconfig)) * [ ] Docs have been updated if necessary * [x] You've read through your own file changes for silly mistakes etc <!-- Be sure to name your PR with an imperative e.g. 'Add worktrees view' see https://github.com/jesseduffield/lazygit/releases/tag/v0.40.0 for examples -->
- Loading branch information
Showing
5 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...ration/tests/worktree/fast_forward_worktree_branch_should_not_pollute_current_worktree.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package worktree | ||
|
||
import ( | ||
"github.com/jesseduffield/lazygit/pkg/config" | ||
. "github.com/jesseduffield/lazygit/pkg/integration/components" | ||
) | ||
|
||
var FastForwardWorktreeBranchShouldNotPolluteCurrentWorktree = NewIntegrationTest(NewIntegrationTestArgs{ | ||
Description: "Fast-forward a linked worktree branch from another worktree", | ||
ExtraCmdArgs: []string{}, | ||
Skip: false, | ||
SetupConfig: func(config *config.AppConfig) {}, | ||
SetupRepo: func(shell *Shell) { | ||
// both main and linked worktree will have changed to fast-forward | ||
shell.NewBranch("mybranch") | ||
shell.CreateFileAndAdd("README.md", "hello world") | ||
shell.Commit("initial commit") | ||
shell.EmptyCommit("two") | ||
shell.EmptyCommit("three") | ||
shell.NewBranch("newbranch") | ||
|
||
shell.CloneIntoRemote("origin") | ||
shell.SetBranchUpstream("mybranch", "origin/mybranch") | ||
shell.SetBranchUpstream("newbranch", "origin/newbranch") | ||
|
||
// remove the 'three' commit so that we have something to pull from the remote | ||
shell.HardReset("HEAD^") | ||
shell.Checkout("mybranch") | ||
shell.HardReset("HEAD^") | ||
|
||
shell.AddWorktreeCheckout("newbranch", "../linked-worktree") | ||
}, | ||
Run: func(t *TestDriver, keys config.KeybindingConfig) { | ||
t.Views().Branches(). | ||
Focus(). | ||
Lines( | ||
Contains("mybranch").Contains("↓1").IsSelected(), | ||
Contains("newbranch (worktree)").Contains("↓1"), | ||
). | ||
Press(keys.Branches.FastForward). | ||
Lines( | ||
Contains("mybranch").Contains("✓").IsSelected(), | ||
Contains("newbranch (worktree)").Contains("↓1"), | ||
). | ||
NavigateToLine(Contains("newbranch (worktree)")). | ||
Press(keys.Branches.FastForward). | ||
Lines( | ||
Contains("mybranch").Contains("✓"), | ||
Contains("newbranch (worktree)").Contains("✓").IsSelected(), | ||
). | ||
NavigateToLine(Contains("mybranch")) | ||
|
||
// check the current worktree that it has no lines in the File changes pane | ||
t.Views().Files(). | ||
Focus(). | ||
Press(keys.Files.RefreshFiles). | ||
LineCount(EqualsInt(0)) | ||
}, | ||
}) |