From ae10a5ea8865e04b6369f6a0f9cd8a554ca6cac1 Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sat, 26 Mar 2022 21:18:10 +1100 Subject: [PATCH] add git fetch prune integration test --- pkg/integration/integration.go | 11 +++--- test/integration/fetchPrune/config/config.yml | 10 ++++++ .../expected/.git_keep/COMMIT_EDITMSG | 1 + .../fetchPrune/expected/.git_keep/FETCH_HEAD | 1 + .../fetchPrune/expected/.git_keep/HEAD | 1 + .../fetchPrune/expected/.git_keep/config | 21 +++++++++++ .../fetchPrune/expected/.git_keep/description | 1 + .../fetchPrune/expected/.git_keep/index | Bin 0 -> 137 bytes .../expected/.git_keep/info/exclude | 7 ++++ .../fetchPrune/expected/.git_keep/logs/HEAD | 3 ++ .../expected/.git_keep/logs/refs/heads/master | 1 + .../.git_keep/logs/refs/heads/other_branch | 1 + .../.git_keep/logs/refs/remotes/origin/master | 1 + .../0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 | Bin 0 -> 52 bytes .../a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 | Bin 0 -> 21 bytes .../f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 | Bin 0 -> 121 bytes .../fetchPrune/expected/.git_keep/packed-refs | 1 + .../expected/.git_keep/refs/heads/master | 1 + .../.git_keep/refs/heads/other_branch | 1 + .../.git_keep/refs/remotes/origin/master | 1 + test/integration/fetchPrune/expected/myfile1 | 1 + .../fetchPrune/expected_remote/HEAD | 1 + .../fetchPrune/expected_remote/config | 8 +++++ .../fetchPrune/expected_remote/description | 1 + .../fetchPrune/expected_remote/info/exclude | 7 ++++ .../0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 | Bin 0 -> 52 bytes .../a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 | Bin 0 -> 21 bytes .../f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 | Bin 0 -> 121 bytes .../fetchPrune/expected_remote/packed-refs | 2 ++ test/integration/fetchPrune/recording.json | 1 + test/integration/fetchPrune/setup.sh | 34 ++++++++++++++++++ test/integration/fetchPrune/test.json | 4 +++ 32 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 test/integration/fetchPrune/config/config.yml create mode 100644 test/integration/fetchPrune/expected/.git_keep/COMMIT_EDITMSG create mode 100644 test/integration/fetchPrune/expected/.git_keep/FETCH_HEAD create mode 100644 test/integration/fetchPrune/expected/.git_keep/HEAD create mode 100644 test/integration/fetchPrune/expected/.git_keep/config create mode 100644 test/integration/fetchPrune/expected/.git_keep/description create mode 100644 test/integration/fetchPrune/expected/.git_keep/index create mode 100644 test/integration/fetchPrune/expected/.git_keep/info/exclude create mode 100644 test/integration/fetchPrune/expected/.git_keep/logs/HEAD create mode 100644 test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/master create mode 100644 test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/other_branch create mode 100644 test/integration/fetchPrune/expected/.git_keep/logs/refs/remotes/origin/master create mode 100644 test/integration/fetchPrune/expected/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 create mode 100644 test/integration/fetchPrune/expected/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 create mode 100644 test/integration/fetchPrune/expected/.git_keep/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 create mode 100644 test/integration/fetchPrune/expected/.git_keep/packed-refs create mode 100644 test/integration/fetchPrune/expected/.git_keep/refs/heads/master create mode 100644 test/integration/fetchPrune/expected/.git_keep/refs/heads/other_branch create mode 100644 test/integration/fetchPrune/expected/.git_keep/refs/remotes/origin/master create mode 100644 test/integration/fetchPrune/expected/myfile1 create mode 100644 test/integration/fetchPrune/expected_remote/HEAD create mode 100644 test/integration/fetchPrune/expected_remote/config create mode 100644 test/integration/fetchPrune/expected_remote/description create mode 100644 test/integration/fetchPrune/expected_remote/info/exclude create mode 100644 test/integration/fetchPrune/expected_remote/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 create mode 100644 test/integration/fetchPrune/expected_remote/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 create mode 100644 test/integration/fetchPrune/expected_remote/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 create mode 100644 test/integration/fetchPrune/expected_remote/packed-refs create mode 100644 test/integration/fetchPrune/recording.json create mode 100644 test/integration/fetchPrune/setup.sh create mode 100644 test/integration/fetchPrune/test.json diff --git a/pkg/integration/integration.go b/pkg/integration/integration.go index bb2d7a0b0..ed1c0fe42 100644 --- a/pkg/integration/integration.go +++ b/pkg/integration/integration.go @@ -89,12 +89,12 @@ func RunTests( for _, test := range tests { test := test - if test.Skip && !includeSkipped { - logf("skipping test: %s", test.Name) - continue - } - fnWrapper(test, func(t *testing.T) error { //nolint: thelper + if test.Skip && !includeSkipped { + logf("skipping test: %s", test.Name) + return nil + } + speeds := getTestSpeeds(test.Speed, mode, speedEnv) testPath := filepath.Join(testDir, test.Name) actualRepoDir := filepath.Join(testPath, "actual") @@ -357,6 +357,7 @@ func generateSnapshot(dir string) (string, error) { snapshot := "" cmdStrs := []string{ + `remote show -n origin`, // remote branches `status`, // file tree `log --pretty=%B -p -1`, // log `tag -n`, // tags diff --git a/test/integration/fetchPrune/config/config.yml b/test/integration/fetchPrune/config/config.yml new file mode 100644 index 000000000..a77fb48ed --- /dev/null +++ b/test/integration/fetchPrune/config/config.yml @@ -0,0 +1,10 @@ +disableStartupPopups: true +git: + autoFetch: false +gui: + theme: + activeBorderColor: + - green + - bold + SelectedRangeBgcolor: + - reverse diff --git a/test/integration/fetchPrune/expected/.git_keep/COMMIT_EDITMSG b/test/integration/fetchPrune/expected/.git_keep/COMMIT_EDITMSG new file mode 100644 index 000000000..3829ab872 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/COMMIT_EDITMSG @@ -0,0 +1 @@ +myfile1 diff --git a/test/integration/fetchPrune/expected/.git_keep/FETCH_HEAD b/test/integration/fetchPrune/expected/.git_keep/FETCH_HEAD new file mode 100644 index 000000000..8ef89fd5e --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/FETCH_HEAD @@ -0,0 +1 @@ +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 branch 'master' of ../actual_remote diff --git a/test/integration/fetchPrune/expected/.git_keep/HEAD b/test/integration/fetchPrune/expected/.git_keep/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration/fetchPrune/expected/.git_keep/config b/test/integration/fetchPrune/expected/.git_keep/config new file mode 100644 index 000000000..6dfad7326 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/config @@ -0,0 +1,21 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = false + logallrefupdates = true + ignorecase = true + precomposeunicode = true +[user] + email = CI@example.com + name = CI +[fetch] + prune = true +[remote "origin"] + url = ../actual_remote + fetch = +refs/heads/*:refs/remotes/origin/* +[branch "master"] + remote = origin + merge = refs/heads/master +[branch "other_branch"] + remote = origin + merge = refs/heads/other_branch diff --git a/test/integration/fetchPrune/expected/.git_keep/description b/test/integration/fetchPrune/expected/.git_keep/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration/fetchPrune/expected/.git_keep/index b/test/integration/fetchPrune/expected/.git_keep/index new file mode 100644 index 0000000000000000000000000000000000000000..35b2e51a41fb2f2f9e218cffb40a031b02f6096b GIT binary patch literal 137 zcmZ?q402{*U|<4b#w5EpmF64um|-*{0|P75oPAFj7#f!VrN08zhyXF$(mjv=s;1uf z5)m53lkapPz^kSEDg%3NWm;xVsv%H8NRX>5kdkCDR50M;%lWWu`@CM4hix~67Jm13 ezUIFs=mej|q}#XDe!ICeo|kQ?QVuWiPXhoKkuLK9 literal 0 HcmV?d00001 diff --git a/test/integration/fetchPrune/expected/.git_keep/info/exclude b/test/integration/fetchPrune/expected/.git_keep/info/exclude new file mode 100644 index 000000000..8e9f2071f --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/info/exclude @@ -0,0 +1,7 @@ +# 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] +# *~ +.DS_Store diff --git a/test/integration/fetchPrune/expected/.git_keep/logs/HEAD b/test/integration/fetchPrune/expected/.git_keep/logs/HEAD new file mode 100644 index 000000000..eac6e78df --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/logs/HEAD @@ -0,0 +1,3 @@ +0000000000000000000000000000000000000000 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290937 +1100 commit (initial): myfile1 +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290937 +1100 checkout: moving from master to other_branch +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290937 +1100 checkout: moving from other_branch to master diff --git a/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/master b/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/master new file mode 100644 index 000000000..94180e0b5 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290937 +1100 commit (initial): myfile1 diff --git a/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/other_branch b/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/other_branch new file mode 100644 index 000000000..7cd5bcbce --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/logs/refs/heads/other_branch @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290937 +1100 branch: Created from HEAD diff --git a/test/integration/fetchPrune/expected/.git_keep/logs/refs/remotes/origin/master b/test/integration/fetchPrune/expected/.git_keep/logs/refs/remotes/origin/master new file mode 100644 index 000000000..225a60ab5 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/logs/refs/remotes/origin/master @@ -0,0 +1 @@ +0000000000000000000000000000000000000000 f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 CI 1648290938 +1100 fetch origin: storing head diff --git a/test/integration/fetchPrune/expected/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 b/test/integration/fetchPrune/expected/.git_keep/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 new file mode 100644 index 0000000000000000000000000000000000000000..7f2ebf4eeb6ad6875bcc2a2b91ca3345ee06b45e GIT binary patch literal 52 zcmb`~^A08nuUMF0Q* literal 0 HcmV?d00001 diff --git a/test/integration/fetchPrune/expected/.git_keep/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 b/test/integration/fetchPrune/expected/.git_keep/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 new file mode 100644 index 0000000000000000000000000000000000000000..3d352742a54fef71e79f7712cdc1716f1d7fa401 GIT binary patch literal 121 zcmV-<0EYi~0gcT;3d0}}K+&!}#q0}Z#!N?rQVLn+7)D1Lh**M!r}>NB&Fm+Z+#DvoC!vT%v%ZcY65ciUi`;4w}w-DCZ%dP}W7frPyc b7zPJdB1Ci6bJF!sZt78%RmuDSG=MDIu$DTV literal 0 HcmV?d00001 diff --git a/test/integration/fetchPrune/expected/.git_keep/packed-refs b/test/integration/fetchPrune/expected/.git_keep/packed-refs new file mode 100644 index 000000000..250f18738 --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/packed-refs @@ -0,0 +1 @@ +# pack-refs with: peeled fully-peeled sorted diff --git a/test/integration/fetchPrune/expected/.git_keep/refs/heads/master b/test/integration/fetchPrune/expected/.git_keep/refs/heads/master new file mode 100644 index 000000000..0725115bd --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/refs/heads/master @@ -0,0 +1 @@ +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 diff --git a/test/integration/fetchPrune/expected/.git_keep/refs/heads/other_branch b/test/integration/fetchPrune/expected/.git_keep/refs/heads/other_branch new file mode 100644 index 000000000..0725115bd --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/refs/heads/other_branch @@ -0,0 +1 @@ +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 diff --git a/test/integration/fetchPrune/expected/.git_keep/refs/remotes/origin/master b/test/integration/fetchPrune/expected/.git_keep/refs/remotes/origin/master new file mode 100644 index 000000000..0725115bd --- /dev/null +++ b/test/integration/fetchPrune/expected/.git_keep/refs/remotes/origin/master @@ -0,0 +1 @@ +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 diff --git a/test/integration/fetchPrune/expected/myfile1 b/test/integration/fetchPrune/expected/myfile1 new file mode 100644 index 000000000..a5bce3fd2 --- /dev/null +++ b/test/integration/fetchPrune/expected/myfile1 @@ -0,0 +1 @@ +test1 diff --git a/test/integration/fetchPrune/expected_remote/HEAD b/test/integration/fetchPrune/expected_remote/HEAD new file mode 100644 index 000000000..cb089cd89 --- /dev/null +++ b/test/integration/fetchPrune/expected_remote/HEAD @@ -0,0 +1 @@ +ref: refs/heads/master diff --git a/test/integration/fetchPrune/expected_remote/config b/test/integration/fetchPrune/expected_remote/config new file mode 100644 index 000000000..0c3c56578 --- /dev/null +++ b/test/integration/fetchPrune/expected_remote/config @@ -0,0 +1,8 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true + ignorecase = true + precomposeunicode = true +[remote "origin"] + url = /Users/jesseduffieldduffield/go/src/github.com/jesseduffield/lazygit/test/integration/fetchPrune/./actual diff --git a/test/integration/fetchPrune/expected_remote/description b/test/integration/fetchPrune/expected_remote/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/test/integration/fetchPrune/expected_remote/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration/fetchPrune/expected_remote/info/exclude b/test/integration/fetchPrune/expected_remote/info/exclude new file mode 100644 index 000000000..8e9f2071f --- /dev/null +++ b/test/integration/fetchPrune/expected_remote/info/exclude @@ -0,0 +1,7 @@ +# 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] +# *~ +.DS_Store diff --git a/test/integration/fetchPrune/expected_remote/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 b/test/integration/fetchPrune/expected_remote/objects/0e/6cf0a6b79e8d44e186d812a1f74b43d64fac52 new file mode 100644 index 0000000000000000000000000000000000000000..7f2ebf4eeb6ad6875bcc2a2b91ca3345ee06b45e GIT binary patch literal 52 zcmb`~^A08nuUMF0Q* literal 0 HcmV?d00001 diff --git a/test/integration/fetchPrune/expected_remote/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 b/test/integration/fetchPrune/expected_remote/objects/f3/ff4de48fa4e8fdb4f3631e58841ba81047d8f1 new file mode 100644 index 0000000000000000000000000000000000000000..3d352742a54fef71e79f7712cdc1716f1d7fa401 GIT binary patch literal 121 zcmV-<0EYi~0gcT;3d0}}K+&!}#q0}Z#!N?rQVLn+7)D1Lh**M!r}>NB&Fm+Z+#DvoC!vT%v%ZcY65ciUi`;4w}w-DCZ%dP}W7frPyc b7zPJdB1Ci6bJF!sZt78%RmuDSG=MDIu$DTV literal 0 HcmV?d00001 diff --git a/test/integration/fetchPrune/expected_remote/packed-refs b/test/integration/fetchPrune/expected_remote/packed-refs new file mode 100644 index 000000000..0488de20d --- /dev/null +++ b/test/integration/fetchPrune/expected_remote/packed-refs @@ -0,0 +1,2 @@ +# pack-refs with: peeled fully-peeled sorted +f3ff4de48fa4e8fdb4f3631e58841ba81047d8f1 refs/heads/master diff --git a/test/integration/fetchPrune/recording.json b/test/integration/fetchPrune/recording.json new file mode 100644 index 000000000..b24cbf0cb --- /dev/null +++ b/test/integration/fetchPrune/recording.json @@ -0,0 +1 @@ +{"KeyEvents":[{"Timestamp":608,"Mod":0,"Key":256,"Ch":102},{"Timestamp":1568,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]} \ No newline at end of file diff --git a/test/integration/fetchPrune/setup.sh b/test/integration/fetchPrune/setup.sh new file mode 100644 index 000000000..19d0beec7 --- /dev/null +++ b/test/integration/fetchPrune/setup.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +set -e + +cd $1 + +git init + +git config user.email "CI@example.com" +git config user.name "CI" + +# we're setting this to ensure that it's honoured by the fetch command +git config fetch.prune true + +echo test1 > myfile1 +git add . +git commit -am "myfile1" + +git checkout -b other_branch +git checkout master + +cd .. +git clone --bare ./actual actual_remote + +cd actual + +git remote add origin ../actual_remote +git fetch origin +git branch --set-upstream-to=origin/master master +git branch --set-upstream-to=origin/other_branch other_branch + +# unbenownst to our test repo we're removing the branch on the remote, so upon +# fetching with prune: true we expect git to realise the remote branch is gone +git -C ../actual_remote branch -d other_branch diff --git a/test/integration/fetchPrune/test.json b/test/integration/fetchPrune/test.json new file mode 100644 index 000000000..e358a8c9a --- /dev/null +++ b/test/integration/fetchPrune/test.json @@ -0,0 +1,4 @@ +{ + "description": "fetch from the remote with the 'prune' option set in the git config", + "speed": 10 +}