1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-03-19 21:28:28 +02:00

discard changes integration test

This commit is contained in:
Jesse Duffield 2022-12-24 16:46:01 +11:00
parent 7c7f7bf9b9
commit 5c11b1ecb7
64 changed files with 153 additions and 145 deletions

View File

@ -1,6 +1,8 @@
package gui
import (
"fmt"
"strings"
"time"
"github.com/gdamore/tcell/v2"
@ -55,7 +57,7 @@ func (self *GuiDriver) Fail(message string) {
self.gui.g.Close()
// need to give the gui time to close
time.Sleep(time.Millisecond * 100)
panic(message)
panic(fmt.Sprintf("%s\nLog:\n%s", message, strings.Join(self.gui.CmdLog, "\n")))
}
// logs to the normal place that you log to i.e. viewable with `lazygit --logs`

View File

@ -35,6 +35,32 @@ func (s *Shell) RunCommand(cmdStr string) *Shell {
return s
}
func (s *Shell) RunShellCommand(cmdStr string) *Shell {
cmd := secureexec.Command("sh", "-c", cmdStr)
cmd.Env = os.Environ()
cmd.Dir = s.dir
output, err := cmd.CombinedOutput()
if err != nil {
panic(fmt.Sprintf("error running shell command: %s\n%s", cmdStr, string(output)))
}
return s
}
func (s *Shell) RunShellCommandExpectError(cmdStr string) *Shell {
cmd := secureexec.Command("sh", "-c", cmdStr)
cmd.Env = os.Environ()
cmd.Dir = s.dir
output, err := cmd.CombinedOutput()
if err == nil {
panic(fmt.Sprintf("Expected error running shell command: %s\n%s", cmdStr, string(output)))
}
return s
}
func (s *Shell) CreateFile(path string, content string) *Shell {
fullPath := filepath.Join(s.dir, path)
err := os.WriteFile(fullPath, []byte(content), 0o644)

View File

@ -0,0 +1,123 @@
package file
import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)
var DiscardChanges = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Discarding all possible permutations of changed files",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
},
SetupRepo: func(shell *Shell) {
// typically we would use more bespoke shell methods here, but I struggled to find a way to do that,
// and this is copied over from a legacy integration test which did everything in a big shell script
// so I'm just copying it across.
// common stuff
shell.RunShellCommand(`echo test > both-deleted.txt`)
shell.RunShellCommand(`git checkout -b conflict && git add both-deleted.txt`)
shell.RunShellCommand(`echo bothmodded > both-modded.txt && git add both-modded.txt`)
shell.RunShellCommand(`echo haha > deleted-them.txt && git add deleted-them.txt`)
shell.RunShellCommand(`echo haha2 > deleted-us.txt && git add deleted-us.txt`)
shell.RunShellCommand(`echo mod > modded.txt & git add modded.txt`)
shell.RunShellCommand(`echo mod > modded-staged.txt & git add modded-staged.txt`)
shell.RunShellCommand(`echo del > deleted.txt && git add deleted.txt`)
shell.RunShellCommand(`echo del > deleted-staged.txt && git add deleted-staged.txt`)
shell.RunShellCommand(`echo change-delete > change-delete.txt && git add change-delete.txt`)
shell.RunShellCommand(`echo delete-change > delete-change.txt && git add delete-change.txt`)
shell.RunShellCommand(`echo double-modded > double-modded.txt && git add double-modded.txt`)
shell.RunShellCommand(`echo "renamed\nhaha" > renamed.txt && git add renamed.txt`)
shell.RunShellCommand(`git commit -m one`)
// stuff on other branch
shell.RunShellCommand(`git branch conflict_second && git mv both-deleted.txt added-them-changed-us.txt`)
shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in added-them-changed-us.txt"`)
shell.RunShellCommand(`echo blah > both-added.txt && git add both-added.txt`)
shell.RunShellCommand(`echo mod1 > both-modded.txt && git add both-modded.txt`)
shell.RunShellCommand(`rm deleted-them.txt && git add deleted-them.txt`)
shell.RunShellCommand(`echo modded > deleted-us.txt && git add deleted-us.txt`)
shell.RunShellCommand(`git commit -m "two"`)
// stuff on our branch
shell.RunShellCommand(`git checkout conflict_second`)
shell.RunShellCommand(`git mv both-deleted.txt changed-them-added-us.txt`)
shell.RunShellCommand(`git commit -m "both-deleted.txt renamed in changed-them-added-us.txt"`)
shell.RunShellCommand(`echo mod2 > both-modded.txt && git add both-modded.txt`)
shell.RunShellCommand(`echo blah2 > both-added.txt && git add both-added.txt`)
shell.RunShellCommand(`echo modded > deleted-them.txt && git add deleted-them.txt`)
shell.RunShellCommand(`rm deleted-us.txt && git add deleted-us.txt`)
shell.RunShellCommand(`git commit -m "three"`)
shell.RunShellCommand(`git reset --hard conflict_second`)
shell.RunShellCommandExpectError(`git merge conflict`)
shell.RunShellCommand(`echo "new" > new.txt`)
shell.RunShellCommand(`echo "new staged" > new-staged.txt && git add new-staged.txt`)
shell.RunShellCommand(`echo mod2 > modded.txt`)
shell.RunShellCommand(`echo mod2 > modded-staged.txt && git add modded-staged.txt`)
shell.RunShellCommand(`rm deleted.txt`)
shell.RunShellCommand(`rm deleted-staged.txt && git add deleted-staged.txt`)
shell.RunShellCommand(`echo change-delete2 > change-delete.txt && git add change-delete.txt`)
shell.RunShellCommand(`rm change-delete.txt`)
shell.RunShellCommand(`rm delete-change.txt && git add delete-change.txt`)
shell.RunShellCommand(`echo "changed" > delete-change.txt`)
shell.RunShellCommand(`echo "change1" > double-modded.txt && git add double-modded.txt`)
shell.RunShellCommand(`echo "change2" > double-modded.txt`)
shell.RunShellCommand(`echo before > added-changed.txt && git add added-changed.txt`)
shell.RunShellCommand(`echo after > added-changed.txt`)
shell.RunShellCommand(`rm renamed.txt && git add renamed.txt`)
shell.RunShellCommand(`echo "renamed\nhaha" > renamed2.txt && git add renamed2.txt`)
},
Run: func(shell *Shell, input *Input, assert *Assert, keys config.KeybindingConfig) {
assert.CommitCount(3)
type statusFile struct {
status string
path string
}
discardOneByOne := func(files []statusFile) {
for _, file := range files {
assert.MatchSelectedLine(Contains(file.status + " " + file.path))
input.PressKeys(keys.Universal.Remove)
assert.InMenu()
assert.MatchCurrentViewContent(Contains("discard all changes"))
input.Confirm()
}
}
discardOneByOne([]statusFile{
{"UA", "added-them-changed-us.txt"},
{"AA", "both-added.txt"},
{"DD", "both-deleted.txt"},
{"UU", "both-modded.txt"},
{"AU", "changed-them-added-us.txt"},
{"UD", "deleted-them.txt"},
{"DU", "deleted-us.txt"},
})
assert.InConfirm()
assert.MatchCurrentViewTitle(Contains("continue"))
assert.MatchCurrentViewContent(Contains("all merge conflicts resolved. Continue?"))
input.PressKeys(keys.Universal.Return)
discardOneByOne([]statusFile{
{"MD", "change-delete.txt"},
{"D ", "delete-change.txt"},
{"D ", "deleted-staged.txt"},
{" D", "deleted.txt"},
{"MM", "double-modded.txt"},
{"M ", "modded-staged.txt"},
{" M", "modded.txt"},
{"R ", "renamed.txt → renamed2.txt"},
{"AM", "added-changed.txt"},
{"A ", "new-staged.txt"},
{"??", "new.txt"},
})
assert.WorkingTreeFileCount(0)
},
})

View File

@ -52,6 +52,7 @@ var tests = []*components.IntegrationTest{
custom_commands.MenuFromCommandsOutput,
custom_commands.MultiplePrompts,
file.DirWithUntrackedFile,
file.DiscardChanges,
interactive_rebase.AmendMerge,
interactive_rebase.One,
stash.Rename,

View File

@ -1,23 +0,0 @@
Merge branch 'conflict' into conflict_second
# Conflicts:
# added-them-changed-us.txt
# both-added.txt
# both-deleted.txt
# both-modded.txt
# changed-them-added-us.txt
# deleted-them.txt
# deleted-us.txt
#
# It looks like you may be committing a merge.
# If this is not correct, please remove the file
# /Users/jesseduffieldduffield/go/src/github.com/jesseduffield/lazygit/test/integration/discardFileChanges/actual/.git/MERGE_HEAD
# and try again.
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# On branch conflict_second
# All conflicts fixed but you are still merging.
#

View File

@ -1 +0,0 @@
ref: refs/heads/conflict_second

View File

@ -1 +0,0 @@
11bdfc142c42c6ffaa904890ab61ec76262ec9ca

View File

@ -1,10 +0,0 @@
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[user]
email = CI@example.com
name = CI

View File

@ -1 +0,0 @@
Unnamed repository; edit this file 'description' to name the repository.

View File

@ -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

View File

@ -1,8 +0,0 @@
0000000000000000000000000000000000000000 98e834e9cdae1191de7fafb2b6f334bddd0793e8 CI <CI@example.com> 1617671344 +1000 commit (initial): one
98e834e9cdae1191de7fafb2b6f334bddd0793e8 9976d7948def8b082e9d20135d6a04624d711752 CI <CI@example.com> 1617671344 +1000 commit: both-deleted.txt renamed in added-them-changed-us.txt
9976d7948def8b082e9d20135d6a04624d711752 8c82faa1358ce6cddba19d59b2924cbcc5ef1c8e CI <CI@example.com> 1617671344 +1000 commit: two
8c82faa1358ce6cddba19d59b2924cbcc5ef1c8e 98e834e9cdae1191de7fafb2b6f334bddd0793e8 CI <CI@example.com> 1617671344 +1000 checkout: moving from conflict to conflict_second
98e834e9cdae1191de7fafb2b6f334bddd0793e8 c91b3b139ea108475c19839fcda3a4e33db4ccc9 CI <CI@example.com> 1617671344 +1000 commit: both-deleted.txt renamed in changed-them-added-us.txt
c91b3b139ea108475c19839fcda3a4e33db4ccc9 11bdfc142c42c6ffaa904890ab61ec76262ec9ca CI <CI@example.com> 1617671344 +1000 commit: three
11bdfc142c42c6ffaa904890ab61ec76262ec9ca 11bdfc142c42c6ffaa904890ab61ec76262ec9ca CI <CI@example.com> 1617671344 +1000 reset: moving to conflict_second
11bdfc142c42c6ffaa904890ab61ec76262ec9ca 854f08fa802293e0679d07771547fe9fe5d159e8 CI <CI@example.com> 1617671365 +1000 commit (merge): Merge branch 'conflict' into conflict_second

View File

@ -1,3 +0,0 @@
0000000000000000000000000000000000000000 98e834e9cdae1191de7fafb2b6f334bddd0793e8 CI <CI@example.com> 1617671344 +1000 commit (initial): one
98e834e9cdae1191de7fafb2b6f334bddd0793e8 9976d7948def8b082e9d20135d6a04624d711752 CI <CI@example.com> 1617671344 +1000 commit: both-deleted.txt renamed in added-them-changed-us.txt
9976d7948def8b082e9d20135d6a04624d711752 8c82faa1358ce6cddba19d59b2924cbcc5ef1c8e CI <CI@example.com> 1617671344 +1000 commit: two

View File

@ -1,4 +0,0 @@
0000000000000000000000000000000000000000 98e834e9cdae1191de7fafb2b6f334bddd0793e8 CI <CI@example.com> 1617671344 +1000 branch: Created from conflict
98e834e9cdae1191de7fafb2b6f334bddd0793e8 c91b3b139ea108475c19839fcda3a4e33db4ccc9 CI <CI@example.com> 1617671344 +1000 commit: both-deleted.txt renamed in changed-them-added-us.txt
c91b3b139ea108475c19839fcda3a4e33db4ccc9 11bdfc142c42c6ffaa904890ab61ec76262ec9ca CI <CI@example.com> 1617671344 +1000 commit: three
11bdfc142c42c6ffaa904890ab61ec76262ec9ca 854f08fa802293e0679d07771547fe9fe5d159e8 CI <CI@example.com> 1617671365 +1000 commit (merge): Merge branch 'conflict' into conflict_second

View File

@ -1,2 +0,0 @@
xŤÎA
Â0@Q×9Eö‚d:i“ˇ«cf2AÁŘR"x|{·źżxş¶öěh8őÝĚŹ¤5IĘ\‰YrĚ€˘DłŘ�j)4Ŕ$�¸Ťw{wŻ‚HĆrLŁe¤Ş…‘Ł!‰ŞJŽ?ý±î~^üu^îö嶽ě˘k»y� M 0F†‚;ę�ęöçîúă »!z:ě

View File

@ -1 +0,0 @@
x�ŽAjÃ0E»ö)f_4–*YJ!«c¤ùª‘Ü äøuoÐå{¼Å«[ï7£)¸7Ûª€›‹” »Üs ¤ÈGK1ûê2Òð�«Qž1û€\UÀœY‘š´2•Ø¼EU]Êó O[¶�.W:_®_xIÜqª[ÿ$Žœbb½³sn8ì1eøg>”Í–Qq‡AOö2:Ö¤C鶒¨BG[ÐǺÈú}Àóç/~ LÈ

View File

@ -1,2 +0,0 @@
x�ŽKŠÃ0³Ö)z?8ègÉ‚0 d•cHêç8ÙÁé@Ž?Ê ²{<
ªêÖÚMÈz}� ¤qd�èlpÞköa4ˆ ÉGԩؤ­‹N=òŽU(M˜œGªœaL2Œ8ç¹Øfç|af“äòK–m§ó…NçËÞ¹=î8Ö­ý’ &†hº�~ŒÖZõ·G ¾ÄUÙdwø(o¡ž–˜n+Õ%¯Wð Ú�™û|=?�ú¸XK.

View File

@ -1 +0,0 @@
8c82faa1358ce6cddba19d59b2924cbcc5ef1c8e

View File

@ -1 +0,0 @@
854f08fa802293e0679d07771547fe9fe5d159e8

View File

@ -1 +0,0 @@
renamed\nhaha

View File

@ -1 +0,0 @@
{"KeyEvents":[{"Timestamp":966,"Mod":0,"Key":256,"Ch":100},{"Timestamp":1564,"Mod":0,"Key":13,"Ch":13},{"Timestamp":2093,"Mod":0,"Key":256,"Ch":100},{"Timestamp":2621,"Mod":0,"Key":13,"Ch":13},{"Timestamp":3173,"Mod":0,"Key":256,"Ch":100},{"Timestamp":3652,"Mod":0,"Key":13,"Ch":13},{"Timestamp":4165,"Mod":0,"Key":256,"Ch":100},{"Timestamp":4629,"Mod":0,"Key":13,"Ch":13},{"Timestamp":5190,"Mod":0,"Key":256,"Ch":100},{"Timestamp":5686,"Mod":0,"Key":13,"Ch":13},{"Timestamp":6198,"Mod":0,"Key":256,"Ch":100},{"Timestamp":6733,"Mod":0,"Key":13,"Ch":13},{"Timestamp":7254,"Mod":0,"Key":256,"Ch":100},{"Timestamp":7789,"Mod":0,"Key":13,"Ch":13},{"Timestamp":8285,"Mod":0,"Key":256,"Ch":100},{"Timestamp":8773,"Mod":0,"Key":13,"Ch":13},{"Timestamp":9237,"Mod":0,"Key":256,"Ch":100},{"Timestamp":9725,"Mod":0,"Key":13,"Ch":13},{"Timestamp":10181,"Mod":0,"Key":256,"Ch":100},{"Timestamp":10653,"Mod":0,"Key":13,"Ch":13},{"Timestamp":11125,"Mod":0,"Key":256,"Ch":100},{"Timestamp":11621,"Mod":0,"Key":13,"Ch":13},{"Timestamp":12093,"Mod":0,"Key":256,"Ch":100},{"Timestamp":12565,"Mod":0,"Key":13,"Ch":13},{"Timestamp":13037,"Mod":0,"Key":256,"Ch":100},{"Timestamp":13509,"Mod":0,"Key":13,"Ch":13},{"Timestamp":13965,"Mod":0,"Key":256,"Ch":100},{"Timestamp":14461,"Mod":0,"Key":13,"Ch":13},{"Timestamp":14909,"Mod":0,"Key":256,"Ch":100},{"Timestamp":15382,"Mod":0,"Key":13,"Ch":13},{"Timestamp":15853,"Mod":0,"Key":256,"Ch":100},{"Timestamp":16325,"Mod":0,"Key":13,"Ch":13},{"Timestamp":16765,"Mod":0,"Key":256,"Ch":100},{"Timestamp":17222,"Mod":0,"Key":13,"Ch":13},{"Timestamp":17637,"Mod":0,"Key":256,"Ch":100},{"Timestamp":18077,"Mod":0,"Key":13,"Ch":13},{"Timestamp":20190,"Mod":0,"Key":256,"Ch":109},{"Timestamp":20447,"Mod":0,"Key":13,"Ch":13},{"Timestamp":21414,"Mod":0,"Key":256,"Ch":113}],"ResizeEvents":[{"Timestamp":0,"Width":127,"Height":23}]}

View File

@ -1,65 +0,0 @@
#!/bin/sh
# expecting an error so we're not setting this
# set -e
cd $1
git init
git config user.email "CI@example.com"
git config user.name "CI"
# common stuff
echo test > both-deleted.txt
git checkout -b conflict && git add both-deleted.txt
echo bothmodded > both-modded.txt && git add both-modded.txt
echo haha > deleted-them.txt && git add deleted-them.txt
echo haha2 > deleted-us.txt && git add deleted-us.txt
echo mod > modded.txt & git add modded.txt
echo mod > modded-staged.txt & git add modded-staged.txt
echo del > deleted.txt && git add deleted.txt
echo del > deleted-staged.txt && git add deleted-staged.txt
echo change-delete > change-delete.txt && git add change-delete.txt
echo delete-change > delete-change.txt && git add delete-change.txt
echo double-modded > double-modded.txt && git add double-modded.txt
echo "renamed\nhaha" > renamed.txt && git add renamed.txt
git commit -m one
# stuff on other branch
git branch conflict_second && git mv both-deleted.txt added-them-changed-us.txt
git commit -m "both-deleted.txt renamed in added-them-changed-us.txt"
echo blah > both-added.txt && git add both-added.txt
echo mod1 > both-modded.txt && git add both-modded.txt
rm deleted-them.txt && git add deleted-them.txt
echo modded > deleted-us.txt && git add deleted-us.txt
git commit -m "two"
# stuff on our branch
git checkout conflict_second
git mv both-deleted.txt changed-them-added-us.txt
git commit -m "both-deleted.txt renamed in changed-them-added-us.txt"
echo mod2 > both-modded.txt && git add both-modded.txt
echo blah2 > both-added.txt && git add both-added.txt
echo modded > deleted-them.txt && git add deleted-them.txt
rm deleted-us.txt && git add deleted-us.txt
git commit -m "three"
git reset --hard conflict_second
git merge conflict
echo "new" > new.txt
echo "new staged" > new-staged.txt && git add new-staged.txt
echo mod2 > modded.txt
echo mod2 > modded-staged.txt && git add modded-staged.txt
rm deleted.txt
rm deleted-staged.txt && git add deleted-staged.txt
echo change-delete2 > change-delete.txt && git add change-delete.txt
rm change-delete.txt
rm delete-change.txt && git add delete-change.txt
echo "changed" > delete-change.txt
echo "change1" > double-modded.txt && git add double-modded.txt
echo "change2" > double-modded.txt
echo before > added-changed.txt && git add added-changed.txt
echo after > added-changed.txt
rm renamed.txt && git add renamed.txt
echo "renamed\nhaha" > renamed2.txt && git add renamed2.txt

View File

@ -1 +0,0 @@
{ "description": "discard file changes for various kinds of situations (merge conflicts, etc). Skipped because it's failing on CI for some reason", "speed": 5, "skip": true }