diff --git a/pkg/integration/components/shell.go b/pkg/integration/components/shell.go index bfd1c5f86..9b7beca7c 100644 --- a/pkg/integration/components/shell.go +++ b/pkg/integration/components/shell.go @@ -193,3 +193,9 @@ func (self *Shell) RemoveRemoteBranch(remoteName string, branch string) *Shell { return self } + +func (self *Shell) HardReset(ref string) *Shell { + self.RunCommand(fmt.Sprintf("git reset --hard %s", ref)) + + return self +} diff --git a/pkg/integration/tests/sync/rename_branch_and_pull.go b/pkg/integration/tests/sync/rename_branch_and_pull.go new file mode 100644 index 000000000..93e28dfc3 --- /dev/null +++ b/pkg/integration/tests/sync/rename_branch_and_pull.go @@ -0,0 +1,57 @@ +package sync + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var RenameBranchAndPull = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Rename a branch to no longer match its upstream, then pull from the upstream", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) { + config.UserConfig.Git.AutoFetch = false + }, + SetupRepo: func(shell *Shell) { + shell.EmptyCommit("one") + shell.EmptyCommit("two") + + shell.CloneIntoRemote("origin") + shell.SetBranchUpstream("master", "origin/master") + + // remove the 'two' commit so that we have something to pull from the remote + shell.HardReset("HEAD^") + }, + Run: func(t *TestDriver, keys config.KeybindingConfig) { + t.Views().Commits(). + Lines( + Contains("one"), + ) + + t.Views().Branches(). + Focus(). + Lines( + Contains("master"), + ). + Press(keys.Branches.RenameBranch). + Tap(func() { + t.ExpectPopup().Confirmation(). + Title(Equals("rename branch")). + Content(Equals("This branch is tracking a remote. This action will only rename the local branch name, not the name of the remote branch. Continue?")). + Confirm() + + t.ExpectPopup().Prompt(). + Title(Contains("Enter new branch name")). + InitialText(Equals("master")). + Type("-local"). + Confirm() + }). + Press(keys.Universal.PullFiles) + + t.Views().Commits(). + Lines( + Contains("two"), + Contains("one"), + ) + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index 8a6c52565..bba5f38e3 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -66,6 +66,7 @@ var tests = []*components.IntegrationTest{ diff.DiffAndApplyPatch, diff.DiffCommits, sync.FetchPrune, + sync.RenameBranchAndPull, } func GetTests() []*components.IntegrationTest { diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/HEAD b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/config b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/config deleted file mode 100644 index ccf112f58..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/config +++ /dev/null @@ -1,6 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true -[remote "origin"] - url = /home/mark/Downloads/gits/lazygit/test/integration/fetchRemoteBranchWithNonmatchingName/actual/./repo diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/description b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/description deleted file mode 100644 index 498b267a8..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/info/exclude b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/info/exclude deleted file mode 100644 index a5196d1be..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 deleted file mode 100644 index 7f2ebf4ee..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f deleted file mode 100644 index f43085f4d..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 deleted file mode 100644 index f74bf2335..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce deleted file mode 100644 index 0a734f981..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2f/6174050380438f14b16658a356e762435ca591 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2f/6174050380438f14b16658a356e762435ca591 deleted file mode 100644 index 31ae3f5ba..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/2f/6174050380438f14b16658a356e762435ca591 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 deleted file mode 100644 index 0b97b6ff4..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/origin/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 +++ /dev/null @@ -1,3 +0,0 @@ -xA -0@Q9I -"BW=FL!R"~r*Jd ¬DjE 1654108479 +0200 commit (initial): myfile1 -3e5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108479 +0200 commit: myfile2 -12d38e54cd419303587ba4613fb1194ec5c9d04f 72ee6cc86de71389b9c70e24c7d8c8837e7d3566 CI 1654108479 +0200 commit: myfile3 -72ee6cc86de71389b9c70e24c7d8c8837e7d3566 b090d7f0029e74de260f7458721b8edd1e618edc CI 1654108479 +0200 commit: myfile4 -b090d7f0029e74de260f7458721b8edd1e618edc 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108479 +0200 reset: moving to HEAD~2 -12d38e54cd419303587ba4613fb1194ec5c9d04f 0000000000000000000000000000000000000000 CI 1654108482 +0200 Branch: renamed refs/heads/master to refs/heads/master-local -0000000000000000000000000000000000000000 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108482 +0200 Branch: renamed refs/heads/master to refs/heads/master-local -12d38e54cd419303587ba4613fb1194ec5c9d04f b090d7f0029e74de260f7458721b8edd1e618edc CI 1654108482 +0200 pull --no-edit --ff-only origin master: Fast-forward diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/heads/master-local b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/heads/master-local deleted file mode 100644 index b930bd5b6..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/heads/master-local +++ /dev/null @@ -1,7 +0,0 @@ -0000000000000000000000000000000000000000 3e5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 CI 1654108479 +0200 commit (initial): myfile1 -3e5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108479 +0200 commit: myfile2 -12d38e54cd419303587ba4613fb1194ec5c9d04f 72ee6cc86de71389b9c70e24c7d8c8837e7d3566 CI 1654108479 +0200 commit: myfile3 -72ee6cc86de71389b9c70e24c7d8c8837e7d3566 b090d7f0029e74de260f7458721b8edd1e618edc CI 1654108479 +0200 commit: myfile4 -b090d7f0029e74de260f7458721b8edd1e618edc 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108479 +0200 reset: moving to HEAD~2 -12d38e54cd419303587ba4613fb1194ec5c9d04f 12d38e54cd419303587ba4613fb1194ec5c9d04f CI 1654108482 +0200 Branch: renamed refs/heads/master to refs/heads/master-local -12d38e54cd419303587ba4613fb1194ec5c9d04f b090d7f0029e74de260f7458721b8edd1e618edc CI 1654108482 +0200 pull --no-edit --ff-only origin master: Fast-forward diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/remotes/origin/master b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/remotes/origin/master deleted file mode 100644 index 3cb40d7d3..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/logs/refs/remotes/origin/master +++ /dev/null @@ -1 +0,0 @@ -0000000000000000000000000000000000000000 b090d7f0029e74de260f7458721b8edd1e618edc CI 1654108479 +0200 fetch origin: storing head diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 deleted file mode 100644 index 7f2ebf4ee..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f deleted file mode 100644 index f43085f4d..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/12/d38e54cd419303587ba4613fb1194ec5c9d04f and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 deleted file mode 100644 index f74bf2335..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce deleted file mode 100644 index 0a734f981..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2b/173c861df433fa43ffad13f80c8b312c5c8bce and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2f/6174050380438f14b16658a356e762435ca591 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2f/6174050380438f14b16658a356e762435ca591 deleted file mode 100644 index 31ae3f5ba..000000000 Binary files a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/2f/6174050380438f14b16658a356e762435ca591 and /dev/null differ diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 b/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 deleted file mode 100644 index 0b97b6ff4..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/expected/repo/.git_keep/objects/3e/5a250f3b6d2ea4ea93b3006aaceeb75bb8d0b6 +++ /dev/null @@ -1,3 +0,0 @@ -xA -0@Q9I -"BW=FL!R"~r*Jd ¬DjE myfile1 -git add . -git commit -am "myfile1" -echo test2 > myfile2 -git add . -git commit -am "myfile2" -echo test3 > myfile3 -git add . -git commit -am "myfile3" -echo test4 > myfile4 -git add . -git commit -am "myfile4" - -cd .. -git clone --bare ./repo origin - -cd repo - -git reset --hard HEAD~2 -git remote add origin ../origin -git fetch origin -git branch --set-upstream-to=origin/master - diff --git a/test/integration/fetchRemoteBranchWithNonmatchingName/test.json b/test/integration/fetchRemoteBranchWithNonmatchingName/test.json deleted file mode 100644 index dffe129cd..000000000 --- a/test/integration/fetchRemoteBranchWithNonmatchingName/test.json +++ /dev/null @@ -1 +0,0 @@ -{ "description": "allow unsetting the upstream of the current branch", "speed": 10 }