diff --git a/pkg/integration/components/assert.go b/pkg/integration/components/assert.go index 3ce842ebf..65e3e6ec9 100644 --- a/pkg/integration/components/assert.go +++ b/pkg/integration/components/assert.go @@ -2,6 +2,7 @@ package components import ( "fmt" + "os" "regexp" "strings" "time" @@ -259,3 +260,19 @@ func (self *Assert) assertWithRetries(test func() (bool, string)) { func (self *Assert) Fail(message string) { self.gui.Fail(message) } + +// This does _not_ check the files panel, it actually checks the filesystem +func (self *Assert) FileSystemPathPresent(path string) { + self.assertWithRetries(func() (bool, string) { + _, err := os.Stat(path) + return err == nil, fmt.Sprintf("Expected path '%s' to exist, but it does not", path) + }) +} + +// This does _not_ check the files panel, it actually checks the filesystem +func (self *Assert) FileSystemPathNotPresent(path string) { + self.assertWithRetries(func() (bool, string) { + _, err := os.Stat(path) + return os.IsNotExist(err), fmt.Sprintf("Expected path '%s' to not exist, but it does", path) + }) +} diff --git a/pkg/integration/tests/commit/revert.go b/pkg/integration/tests/commit/revert.go new file mode 100644 index 000000000..c42c7af53 --- /dev/null +++ b/pkg/integration/tests/commit/revert.go @@ -0,0 +1,37 @@ +package commit + +import ( + "github.com/jesseduffield/lazygit/pkg/config" + . "github.com/jesseduffield/lazygit/pkg/integration/components" +) + +var Revert = NewIntegrationTest(NewIntegrationTestArgs{ + Description: "Reverts a commit", + ExtraCmdArgs: "", + Skip: false, + SetupConfig: func(config *config.AppConfig) {}, + SetupRepo: func(shell *Shell) { + shell.CreateFile("myfile", "myfile content") + shell.GitAddAll() + shell.Commit("first commit") + }, + Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) { + assert.CommitCount(1) + + input.SwitchToCommitsWindow() + + input.PressKeys(keys.Commits.RevertCommit) + assert.InConfirm() + assert.MatchCurrentViewTitle(Equals("Revert commit")) + assert.MatchCurrentViewContent(MatchesRegexp("Are you sure you want to revert \\w+?")) + input.Confirm() + + assert.CommitCount(2) + assert.MatchHeadCommitMessage(Contains("Revert \"first commit\"")) + input.PreviousItem() + assert.MatchMainViewContent(Contains("-myfile content")) + assert.FileSystemPathNotPresent("myfile") + + input.Wait(10) + }, +}) diff --git a/pkg/integration/tests/tests.go b/pkg/integration/tests/tests.go index e1a23bb14..bad90f0cc 100644 --- a/pkg/integration/tests/tests.go +++ b/pkg/integration/tests/tests.go @@ -37,6 +37,7 @@ var tests = []*components.IntegrationTest{ cherry_pick.CherryPickConflicts, commit.Commit, commit.CommitMultiline, + commit.Revert, commit.NewBranch, commit.Staged, commit.Unstaged, diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/COMMIT_EDITMSG b/test/integration/commitsRevert/expected/repo/.git_keep/COMMIT_EDITMSG deleted file mode 100644 index a04a59a53..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/COMMIT_EDITMSG +++ /dev/null @@ -1 +0,0 @@ -revert commit diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/FETCH_HEAD b/test/integration/commitsRevert/expected/repo/.git_keep/FETCH_HEAD deleted file mode 100644 index e69de29bb..000000000 diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/HEAD b/test/integration/commitsRevert/expected/repo/.git_keep/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/config b/test/integration/commitsRevert/expected/repo/.git_keep/config deleted file mode 100644 index 8ae104545..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/config +++ /dev/null @@ -1,10 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true - precomposeunicode = true -[user] - email = CI@example.com - name = CI diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/description b/test/integration/commitsRevert/expected/repo/.git_keep/description deleted file mode 100644 index 498b267a8..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/index b/test/integration/commitsRevert/expected/repo/.git_keep/index deleted file mode 100644 index fabd517d8..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/index and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/info/exclude b/test/integration/commitsRevert/expected/repo/.git_keep/info/exclude deleted file mode 100644 index 8e9f2071f..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/info/exclude +++ /dev/null @@ -1,7 +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] -# *~ -.DS_Store diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/logs/HEAD b/test/integration/commitsRevert/expected/repo/.git_keep/logs/HEAD deleted file mode 100644 index d82a2c6a4..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/logs/HEAD +++ /dev/null @@ -1,5 +0,0 @@ -0000000000000000000000000000000000000000 9eaae8f342ca71c060b760870a715a6303905935 CI 1643148217 +1100 commit (initial): file0 -9eaae8f342ca71c060b760870a715a6303905935 1727eeb6864e52a8967a1a494099359dbdfcc235 CI 1643148217 +1100 commit: file1 -1727eeb6864e52a8967a1a494099359dbdfcc235 b781ffd3aa940dde39f73c9149b67e2b128de085 CI 1643148217 +1100 commit: file2 -b781ffd3aa940dde39f73c9149b67e2b128de085 ab15072795e72a2061bc40060494c3ca2138b297 CI 1643148219 +1100 revert: Revert "file1" -ab15072795e72a2061bc40060494c3ca2138b297 7e03c9a9538a907c936de5c9a2154707b9ee541c CI 1643148227 +1100 commit (amend): revert commit diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/logs/refs/heads/master b/test/integration/commitsRevert/expected/repo/.git_keep/logs/refs/heads/master deleted file mode 100644 index d82a2c6a4..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/logs/refs/heads/master +++ /dev/null @@ -1,5 +0,0 @@ -0000000000000000000000000000000000000000 9eaae8f342ca71c060b760870a715a6303905935 CI 1643148217 +1100 commit (initial): file0 -9eaae8f342ca71c060b760870a715a6303905935 1727eeb6864e52a8967a1a494099359dbdfcc235 CI 1643148217 +1100 commit: file1 -1727eeb6864e52a8967a1a494099359dbdfcc235 b781ffd3aa940dde39f73c9149b67e2b128de085 CI 1643148217 +1100 commit: file2 -b781ffd3aa940dde39f73c9149b67e2b128de085 ab15072795e72a2061bc40060494c3ca2138b297 CI 1643148219 +1100 revert: Revert "file1" -ab15072795e72a2061bc40060494c3ca2138b297 7e03c9a9538a907c936de5c9a2154707b9ee541c CI 1643148227 +1100 commit (amend): revert commit diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/17/27eeb6864e52a8967a1a494099359dbdfcc235 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/17/27eeb6864e52a8967a1a494099359dbdfcc235 deleted file mode 100644 index 59a430624..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/17/27eeb6864e52a8967a1a494099359dbdfcc235 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 deleted file mode 100644 index f74bf2335..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/18/0cf8328022becee9aaa2577a8f84ea2b9f3827 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/1e/3e67b999db1576ad1ee08bf4f02bdf29e49442 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/1e/3e67b999db1576ad1ee08bf4f02bdf29e49442 deleted file mode 100644 index 79fcadf67..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/1e/3e67b999db1576ad1ee08bf4f02bdf29e49442 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/38/143ad4a0fe2ab6ee53c2ef89a5d9e2bd9535da b/test/integration/commitsRevert/expected/repo/.git_keep/objects/38/143ad4a0fe2ab6ee53c2ef89a5d9e2bd9535da deleted file mode 100644 index 06c9cb73d..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/38/143ad4a0fe2ab6ee53c2ef89a5d9e2bd9535da and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/3a/1ee58e5736049ad5b9266715d3642614816c1f b/test/integration/commitsRevert/expected/repo/.git_keep/objects/3a/1ee58e5736049ad5b9266715d3642614816c1f deleted file mode 100644 index 2d68564f5..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/objects/3a/1ee58e5736049ad5b9266715d3642614816c1f +++ /dev/null @@ -1,2 +0,0 @@ -x+)JMU03c040031QHI5`ֶww.hT[H -$x~5(;rբW-9 \ No newline at end of file diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/7e/03c9a9538a907c936de5c9a2154707b9ee541c b/test/integration/commitsRevert/expected/repo/.git_keep/objects/7e/03c9a9538a907c936de5c9a2154707b9ee541c deleted file mode 100644 index fea4aa6be..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/objects/7e/03c9a9538a907c936de5c9a2154707b9ee541c +++ /dev/null @@ -1,4 +0,0 @@ -x}K -1]$O'AY1`!DmQxym6@IytDf:M҄Xl -ȡ-"4)c[Z1Y -PMHX%TV縮y;Χ3 * pDRt?5O_|3< \ No newline at end of file diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/88a70dc8d82dd2afbfd50176ef78e18823bc2c b/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/88a70dc8d82dd2afbfd50176ef78e18823bc2c deleted file mode 100644 index 0e95eb06d..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/88a70dc8d82dd2afbfd50176ef78e18823bc2c and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/aae8f342ca71c060b760870a715a6303905935 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/aae8f342ca71c060b760870a715a6303905935 deleted file mode 100644 index dfcaf39be..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/9e/aae8f342ca71c060b760870a715a6303905935 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 deleted file mode 100644 index 285df3e5f..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/a5/bce3fd2565d8f458555a0c6f42d0504a848bd5 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/ab/15072795e72a2061bc40060494c3ca2138b297 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/ab/15072795e72a2061bc40060494c3ca2138b297 deleted file mode 100644 index 28a9eaf41..000000000 Binary files a/test/integration/commitsRevert/expected/repo/.git_keep/objects/ab/15072795e72a2061bc40060494c3ca2138b297 and /dev/null differ diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/b7/81ffd3aa940dde39f73c9149b67e2b128de085 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/b7/81ffd3aa940dde39f73c9149b67e2b128de085 deleted file mode 100644 index c32d4b681..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/objects/b7/81ffd3aa940dde39f73c9149b67e2b128de085 +++ /dev/null @@ -1,2 +0,0 @@ -xK -0@] & "tcL [Jo /I8Z֊r@ " F"9Pp).9JAk;44?}_VGQ_Q'=\9 \ No newline at end of file diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/objects/d0/76cc9cc09acaa2d36fbc7a95fd3e2306494641 b/test/integration/commitsRevert/expected/repo/.git_keep/objects/d0/76cc9cc09acaa2d36fbc7a95fd3e2306494641 deleted file mode 100644 index 2e9066287..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/objects/d0/76cc9cc09acaa2d36fbc7a95fd3e2306494641 +++ /dev/null @@ -1,2 +0,0 @@ -x+)JMU03c040031QHI5`ֶww.hT[H - yW5Ɨ(| ^-W(x9 \ No newline at end of file diff --git a/test/integration/commitsRevert/expected/repo/.git_keep/refs/heads/master b/test/integration/commitsRevert/expected/repo/.git_keep/refs/heads/master deleted file mode 100644 index 7edf473fd..000000000 --- a/test/integration/commitsRevert/expected/repo/.git_keep/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -7e03c9a9538a907c936de5c9a2154707b9ee541c diff --git a/test/integration/commitsRevert/expected/repo/file0 b/test/integration/commitsRevert/expected/repo/file0 deleted file mode 100644 index 38143ad4a..000000000 --- a/test/integration/commitsRevert/expected/repo/file0 +++ /dev/null @@ -1 +0,0 @@ -test0 diff --git a/test/integration/commitsRevert/expected/repo/file2 b/test/integration/commitsRevert/expected/repo/file2 deleted file mode 100644 index 180cf8328..000000000 --- a/test/integration/commitsRevert/expected/repo/file2 +++ /dev/null @@ -1 +0,0 @@ -test2 diff --git a/test/integration/commitsRevert/recording.json b/test/integration/commitsRevert/recording.json deleted file mode 100644 index 80125e840..000000000 --- a/test/integration/commitsRevert/recording.json +++ /dev/null @@ -1 +0,0 @@ -{"KeyEvents":[{"Timestamp":614,"Mod":0,"Key":259,"Ch":0},{"Timestamp":749,"Mod":0,"Key":259,"Ch":0},{"Timestamp":980,"Mod":0,"Key":258,"Ch":0},{"Timestamp":1219,"Mod":0,"Key":256,"Ch":116},{"Timestamp":1854,"Mod":0,"Key":13,"Ch":13},{"Timestamp":2469,"Mod":0,"Key":257,"Ch":0},{"Timestamp":2725,"Mod":0,"Key":257,"Ch":0},{"Timestamp":3892,"Mod":0,"Key":256,"Ch":114},{"Timestamp":5421,"Mod":2,"Key":21,"Ch":21},{"Timestamp":5854,"Mod":2,"Key":21,"Ch":21},{"Timestamp":6197,"Mod":2,"Key":21,"Ch":21},{"Timestamp":6469,"Mod":2,"Key":21,"Ch":21},{"Timestamp":6781,"Mod":2,"Key":21,"Ch":21},{"Timestamp":7078,"Mod":2,"Key":21,"Ch":21},{"Timestamp":7907,"Mod":0,"Key":256,"Ch":114},{"Timestamp":7989,"Mod":0,"Key":256,"Ch":101},{"Timestamp":8148,"Mod":0,"Key":256,"Ch":118},{"Timestamp":8285,"Mod":0,"Key":256,"Ch":101},{"Timestamp":8356,"Mod":0,"Key":256,"Ch":114},{"Timestamp":8493,"Mod":0,"Key":256,"Ch":116},{"Timestamp":8604,"Mod":0,"Key":256,"Ch":32},{"Timestamp":8700,"Mod":0,"Key":256,"Ch":102},{"Timestamp":9125,"Mod":0,"Key":127,"Ch":127},{"Timestamp":9189,"Mod":0,"Key":256,"Ch":99},{"Timestamp":9317,"Mod":0,"Key":256,"Ch":111},{"Timestamp":9509,"Mod":0,"Key":256,"Ch":109},{"Timestamp":9637,"Mod":0,"Key":256,"Ch":109},{"Timestamp":9685,"Mod":0,"Key":256,"Ch":105},{"Timestamp":9781,"Mod":0,"Key":256,"Ch":116},{"Timestamp":9918,"Mod":0,"Key":13,"Ch":13},{"Timestamp":11110,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":272,"Height":74}]} \ No newline at end of file diff --git a/test/integration/commitsRevert/setup.sh b/test/integration/commitsRevert/setup.sh deleted file mode 100644 index 4e35cf543..000000000 --- a/test/integration/commitsRevert/setup.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/bin/sh - -set -e - -cd $1 - -git init - -git config user.email "CI@example.com" -git config user.name "CI" - -echo test0 > file0 -git add . -git commit -am file0 - -echo test1 > file1 -git add . -git commit -am file1 - -echo test2 > file2 -git add . -git commit -am file2 diff --git a/test/integration/commitsRevert/test.json b/test/integration/commitsRevert/test.json deleted file mode 100644 index d760dcc6c..000000000 --- a/test/integration/commitsRevert/test.json +++ /dev/null @@ -1 +0,0 @@ -{ "description": "Reverting a commit. Note here that our snapshot test fails if the commit SHA is included in the message hence the renaming of the revert commit after creating it", "speed": 20 }