Skip to content

Run integration tests with all supported git versions #2754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Unshallow repo
run: git fetch --prune --unshallow
- name: Setup Go
Expand Down
50 changes: 43 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
GOFLAGS: -mod=vendor
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand All @@ -47,13 +47,47 @@ jobs:
run: |
go test ./... -short
integration-tests:
strategy:
fail-fast: false
matrix:
git-version:
- 2.20.0 # oldest supported version
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is going to increase our discipline around flakiness because now there's 6 runs of each test!

- 2.22.5
- 2.23.0
- 2.25.1
- 2.30.8
- latest # We rely on github to have the latest version installed on their VMs
runs-on: ubuntu-latest
name: "Integration Tests"
name: "Integration Tests - git ${{matrix.git-version}}"
env:
GOFLAGS: -mod=vendor
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Restore Git cache
if: matrix.git-version != 'latest'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the idea that the latest git version is already installed? If so could you leave a comment to that effect?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We know that some git version must already be installed, because before this branch we didn't bother installing git at all.

So this relies on the assumption that github's CI VMs are up to date wrt which git version they have. (I added the print git version step specifically so that we can verify this.) At the moment it is the current one.

In an earlier iteration of the branch I had an entry in the matrix for 2.41.0 instead of latest; this simplifies the code a bit, as we don't need all the conditional logic for 'latest', but the downside is that we need to update the matrix every time a new git version is released, which I thought is too easy to forget. But I can easily revert back to that if you prefer it; let me know what you think.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with using latest, it'll ensure we support the bleeding edge

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK; I added a comment in 50c975b. Gonna rebase one more time now and then merge.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good

id: cache-git-restore
uses: actions/cache/restore@v3
with:
path: ~/git-${{matrix.git-version}}
key: ${{runner.os}}-git-${{matrix.git-version}}
- name: Build Git ${{matrix.git-version}}
if: steps.cache-git-restore.outputs.cache-hit != 'true' && matrix.git-version != 'latest'
run: >
sudo apt-get update && sudo apt-get install --no-install-recommends -y build-essential ca-certificates curl gettext libexpat1-dev libssl-dev libz-dev openssl
&& curl -sL "https://mirrors.edge.kernel.org/pub/software/scm/git/git-${{matrix.git-version}}.tar.xz" -o - | tar xJ -C "$HOME"
&& cd "$HOME/git-${{matrix.git-version}}"
&& ./configure
&& make -j
- name: Install Git ${{matrix.git-version}}
if: matrix.git-version != 'latest'
run: sudo make -C "$HOME/git-${{matrix.git-version}}" -j install
- name: Save Git cache
if: steps.cache-git-restore.outputs.cache-hit != 'true' && matrix.git-version != 'latest'
uses: actions/cache/save@v3
with:
path: ~/git-${{matrix.git-version}}
key: ${{runner.os}}-git-${{matrix.git-version}}
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand All @@ -67,17 +101,19 @@ jobs:
key: ${{runner.os}}-go-${{hashFiles('**/go.sum')}}-test
restore-keys: |
${{runner.os}}-go-
- name: Print git version
run: git --version
- name: Test code
run: |
go test pkg/integration/clients/*.go
./scripts/run_integration_tests.sh
build:
runs-on: ubuntu-latest
env:
GOFLAGS: -mod=vendor
GOARCH: amd64
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand Down Expand Up @@ -113,7 +149,7 @@ jobs:
GOARCH: amd64
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand Down Expand Up @@ -147,7 +183,7 @@ jobs:
GOFLAGS: -mod=vendor
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Go
uses: actions/setup-go@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sponsors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Generate Sponsors 💖
uses: JamesIves/github-sponsors-readme-action@v1.0.8
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/git_commands/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ func (self *PatchCommands) MovePatchToSelectedCommit(commits []*models.Commit, s

func (self *PatchCommands) MovePatchIntoIndex(commits []*models.Commit, commitIdx int, stash bool) error {
if stash {
if err := self.stash.Save(self.Tr.StashPrefix + commits[commitIdx].Sha); err != nil {
if err := self.stash.Push(self.Tr.StashPrefix + commits[commitIdx].Sha); err != nil {
return err
}
}
Expand Down
17 changes: 9 additions & 8 deletions pkg/commands/git_commands/stash.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func (self *StashCommands) Apply(index int) error {
return self.cmd.New(cmdArgs).Run()
}

// Save save stash
func (self *StashCommands) Save(message string) error {
cmdArgs := NewGitCmd("stash").Arg("save", message).
// Push push stash
func (self *StashCommands) Push(message string) error {
cmdArgs := NewGitCmd("stash").Arg("push", "-m", message).
ToArgv()

return self.cmd.New(cmdArgs).Run()
Expand All @@ -63,8 +63,9 @@ func (self *StashCommands) Save(message string) error {
func (self *StashCommands) Store(sha string, message string) error {
trimmedMessage := strings.Trim(message, " \t")

cmdArgs := NewGitCmd("stash").Arg("store", sha).
cmdArgs := NewGitCmd("stash").Arg("store").
ArgIf(trimmedMessage != "", "-m", trimmedMessage).
Arg(sha).
ToArgv()

return self.cmd.New(cmdArgs).Run()
Expand Down Expand Up @@ -93,7 +94,7 @@ func (self *StashCommands) ShowStashEntryCmdObj(index int, ignoreWhitespace bool
}

func (self *StashCommands) StashAndKeepIndex(message string) error {
cmdArgs := NewGitCmd("stash").Arg("save", message, "--keep-index").
cmdArgs := NewGitCmd("stash").Arg("push", "--keep-index", "-m", message).
ToArgv()

return self.cmd.New(cmdArgs).Run()
Expand All @@ -107,7 +108,7 @@ func (self *StashCommands) StashUnstagedChanges(message string) error {
).Run(); err != nil {
return err
}
if err := self.Save(message); err != nil {
if err := self.Push(message); err != nil {
return err
}

Expand All @@ -129,7 +130,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {
return err
}

if err := self.Save(message); err != nil {
if err := self.Push(message); err != nil {
return err
}

Expand Down Expand Up @@ -171,7 +172,7 @@ func (self *StashCommands) SaveStagedChanges(message string) error {

func (self *StashCommands) StashIncludeUntrackedChanges(message string) error {
return self.cmd.New(
NewGitCmd("stash").Arg("save", message, "--include-untracked").
NewGitCmd("stash").Arg("push", "--include-untracked", "-m", message).
ToArgv(),
).Run()
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/commands/git_commands/stash_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ func TestStashPop(t *testing.T) {

func TestStashSave(t *testing.T) {
runner := oscommands.NewFakeRunner(t).
ExpectGitArgs([]string{"stash", "save", "A stash message"}, "", nil)
ExpectGitArgs([]string{"stash", "push", "-m", "A stash message"}, "", nil)
instance := buildStashCommands(commonDeps{runner: runner})

assert.NoError(t, instance.Save("A stash message"))
assert.NoError(t, instance.Push("A stash message"))
runner.CheckForMissingCalls()
}

Expand All @@ -57,7 +57,7 @@ func TestStashStore(t *testing.T) {
testName: "Non-empty message",
sha: "0123456789abcdef",
message: "New stash name",
expected: []string{"stash", "store", "0123456789abcdef", "-m", "New stash name"},
expected: []string{"stash", "store", "-m", "New stash name", "0123456789abcdef"},
},
{
testName: "Empty message",
Expand Down Expand Up @@ -162,7 +162,7 @@ func TestStashRename(t *testing.T) {
expectedShaCmd: []string{"rev-parse", "refs/stash@{3}"},
shaResult: "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd\n",
expectedDropCmd: []string{"stash", "drop", "stash@{3}"},
expectedStoreCmd: []string{"stash", "store", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd", "-m", "New message"},
expectedStoreCmd: []string{"stash", "store", "-m", "New message", "f0d0f20f2f61ffd6d6bfe0752deffa38845a3edd"},
},
{
testName: "Empty message",
Expand Down
6 changes: 3 additions & 3 deletions pkg/gui/controllers/files_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func (self *FilesController) createStashMenu() error {
if !self.c.Helpers().WorkingTree.IsWorkingTreeDirty() {
return self.c.ErrorMsg(self.c.Tr.NoFilesToStash)
}
return self.handleStashSave(self.c.Git().Stash.Save, self.c.Tr.Actions.StashAllChanges)
return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashAllChanges)
},
Key: 'a',
},
Expand Down Expand Up @@ -740,7 +740,7 @@ func (self *FilesController) createStashMenu() error {
return self.handleStashSave(self.c.Git().Stash.StashUnstagedChanges, self.c.Tr.Actions.StashUnstagedChanges)
}
// ordinary stash
return self.handleStashSave(self.c.Git().Stash.Save, self.c.Tr.Actions.StashUnstagedChanges)
return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashUnstagedChanges)
},
Key: 'u',
},
Expand All @@ -749,7 +749,7 @@ func (self *FilesController) createStashMenu() error {
}

func (self *FilesController) stash() error {
return self.handleStashSave(self.c.Git().Stash.Save, self.c.Tr.Actions.StashAllChanges)
return self.handleStashSave(self.c.Git().Stash.Push, self.c.Tr.Actions.StashAllChanges)
}

func (self *FilesController) createResetToUpstreamMenu() error {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/helpers/refs_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions
Title: self.c.Tr.AutoStashTitle,
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
if err := self.c.Git().Stash.Save(self.c.Tr.StashPrefix + ref); err != nil {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + ref); err != nil {
return self.c.Error(err)
}
if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/controllers/undo_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (self *UndoController) hardResetWithAutoStash(commitSha string, options har
Prompt: self.c.Tr.AutoStashPrompt,
HandleConfirm: func() error {
return self.c.WithWaitingStatus(options.WaitingStatus, func(gocui.Task) error {
if err := self.c.Git().Stash.Save(self.c.Tr.StashPrefix + commitSha); err != nil {
if err := self.c.Git().Stash.Push(self.c.Tr.StashPrefix + commitSha); err != nil {
return self.c.Error(err)
}
if err := reset(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/integration/components/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func buildLazygit() error {

func createFixture(test *IntegrationTest, paths Paths, rootDir string) error {
shell := NewShell(paths.ActualRepo(), func(errorMsg string) { panic(errorMsg) })
shell.Init("master")
shell.Init()

os.Setenv(GIT_CONFIG_GLOBAL_ENV_VAR, globalGitConfigPath(rootDir))

Expand Down
11 changes: 3 additions & 8 deletions pkg/integration/components/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,6 @@ func (self *Shell) CreateNCommitsStartingAt(n, startIndex int) *Shell {
return self
}

func (self *Shell) StashWithMessage(message string) *Shell {
self.RunCommand([]string{"git", "stash", "-m", message})
return self
}

func (self *Shell) SetConfig(key string, value string) *Shell {
self.RunCommand([]string{"git", "config", "--local", key, value})
return self
Expand Down Expand Up @@ -245,7 +240,7 @@ func (self *Shell) HardReset(ref string) *Shell {
}

func (self *Shell) Stash(message string) *Shell {
self.RunCommand([]string{"git", "stash", "-m", message})
self.RunCommand([]string{"git", "stash", "push", "-m", message})
return self
}

Expand All @@ -254,8 +249,8 @@ func (self *Shell) StartBisect(good string, bad string) *Shell {
return self
}

func (self *Shell) Init(mainBranch string) *Shell {
self.RunCommand([]string{"git", "init", "-b", mainBranch})
func (self *Shell) Init() *Shell {
self.RunCommand([]string{"git", "-c", "init.defaultBranch=master", "init"})
return self
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ var ApplyInReverseWithConflict = NewIntegrationTest(NewIntegrationTestArgs{

t.ExpectPopup().Alert().
Title(Equals("Error")).
Content(Contains("Applied patch to 'file1' with conflicts.").
Contains("Applied patch to 'file2' cleanly.")).
Content(Contains("Applied patch to 'file1' with conflicts.")).
Confirm()

t.Views().Files().
Expand Down
4 changes: 2 additions & 2 deletions pkg/integration/tests/stash/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ var Rename = NewIntegrationTest(NewIntegrationTestArgs{
shell.
EmptyCommit("blah").
CreateFileAndAdd("file-1", "change to stash1").
StashWithMessage("foo").
Stash("foo").
CreateFileAndAdd("file-2", "change to stash2").
StashWithMessage("bar")
Stash("bar")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Stash().
Expand Down
6 changes: 4 additions & 2 deletions pkg/integration/tests/sync/pull_rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ var PullRebase = NewIntegrationTest(NewIntegrationTestArgs{
shell.Commit("one")
shell.UpdateFileAndAdd("file", "content2")
shell.Commit("two")
shell.EmptyCommit("three")
shell.CreateFileAndAdd("file3", "content3")
shell.Commit("three")

shell.CloneIntoRemote("origin")

shell.SetBranchUpstream("master", "origin/master")

shell.HardReset("HEAD^^")
shell.EmptyCommit("four")
shell.CreateFileAndAdd("file4", "content4")
shell.Commit("four")

shell.SetConfig("pull.rebase", "true")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var PullRebaseInteractiveConflict = NewIntegrationTest(NewIntegrationTestArgs{
shell.Commit("one")
shell.UpdateFileAndAdd("file", "content2")
shell.Commit("two")
shell.EmptyCommit("three")
shell.CreateFileAndAdd("file3", "content3")
shell.Commit("three")

shell.CloneIntoRemote("origin")

Expand All @@ -24,7 +25,8 @@ var PullRebaseInteractiveConflict = NewIntegrationTest(NewIntegrationTestArgs{
shell.HardReset("HEAD^^")
shell.UpdateFileAndAdd("file", "content4")
shell.Commit("four")
shell.EmptyCommit("five")
shell.CreateFileAndAdd("file5", "content5")
shell.Commit("five")

shell.SetConfig("pull.rebase", "interactive")
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ var PullRebaseInteractiveConflictDrop = NewIntegrationTest(NewIntegrationTestArg
shell.Commit("one")
shell.UpdateFileAndAdd("file", "content2")
shell.Commit("two")
shell.EmptyCommit("three")
shell.CreateFileAndAdd("file3", "content3")
shell.Commit("three")

shell.CloneIntoRemote("origin")

Expand All @@ -24,7 +25,8 @@ var PullRebaseInteractiveConflictDrop = NewIntegrationTest(NewIntegrationTestArg
shell.HardReset("HEAD^^")
shell.UpdateFileAndAdd("file", "content4")
shell.Commit("four")
shell.EmptyCommit("five")
shell.CreateFileAndAdd("fil5", "content5")
shell.Commit("five")

shell.SetConfig("pull.rebase", "interactive")
},
Expand Down
Loading