Skip to content

Commit

Permalink
migrate fetchPrune integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed Dec 30, 2022
1 parent 8a1c763 commit 277ca70
Show file tree
Hide file tree
Showing 34 changed files with 74 additions and 117 deletions.
23 changes: 23 additions & 0 deletions pkg/integration/components/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,26 @@ func (self *Shell) SetConfig(key string, value string) *Shell {
self.RunCommand(fmt.Sprintf(`git config --local "%s" %s`, key, value))
return self
}

// creates a clone of the repo in a sibling directory and adds the clone
// as a remote, then fetches it.
func (self *Shell) CloneIntoRemote(name string) *Shell {
self.RunCommand(fmt.Sprintf("git clone --bare . ../%s", name))
self.RunCommand(fmt.Sprintf("git remote add %s ../%s", name, name))
self.RunCommand(fmt.Sprintf("git fetch %s", name))

return self
}

// e.g. branch: 'master', upstream: 'origin/master'
func (self *Shell) SetBranchUpstream(branch string, upstream string) *Shell {
self.RunCommand(fmt.Sprintf("git branch --set-upstream-to=%s %s", upstream, branch))

return self
}

func (self *Shell) RemoveRemoteBranch(remoteName string, branch string) *Shell {
self.RunCommand(fmt.Sprintf("git -C ../%s branch -d %s", remoteName, branch))

return self
}
49 changes: 49 additions & 0 deletions pkg/integration/tests/sync/fetch_prune.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package sync

import (
"github.com/jesseduffield/lazygit/pkg/config"
. "github.com/jesseduffield/lazygit/pkg/integration/components"
)

var FetchPrune = NewIntegrationTest(NewIntegrationTestArgs{
Description: "Fetch from the remote with the 'prune' option set in the git config",
ExtraCmdArgs: "",
Skip: false,
SetupConfig: func(config *config.AppConfig) {
config.UserConfig.Git.AutoFetch = false
},
SetupRepo: func(shell *Shell) {
// This option makes it so that git checks for deleted branches in the remote
// upon fetching.
shell.SetConfig("fetch.prune", "true")

shell.EmptyCommit("my commit message")

shell.NewBranch("branch_to_remove")
shell.Checkout("master")
shell.CloneIntoRemote("origin")
shell.SetBranchUpstream("master", "origin/master")
shell.SetBranchUpstream("branch_to_remove", "origin/branch_to_remove")

// # 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
shell.RemoveRemoteBranch("origin", "branch_to_remove")
},
Run: func(t *TestDriver, keys config.KeybindingConfig) {
t.Views().Branches().
Lines(
Contains("master"),
Contains("branch_to_remove").DoesNotContain("upstream gone"),
)

t.Views().Files().
IsFocused().
Press(keys.Files.Fetch)

t.Views().Branches().
Lines(
Contains("master"),
Contains("branch_to_remove").Contains("upstream gone"),
)
},
})
2 changes: 2 additions & 0 deletions pkg/integration/tests/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/jesseduffield/lazygit/pkg/integration/tests/interactive_rebase"
"github.com/jesseduffield/lazygit/pkg/integration/tests/misc"
"github.com/jesseduffield/lazygit/pkg/integration/tests/stash"
"github.com/jesseduffield/lazygit/pkg/integration/tests/sync"
)

// Here is where we lists the actual tests that will run. When you create a new test,
Expand Down Expand Up @@ -64,6 +65,7 @@ var tests = []*components.IntegrationTest{
diff.Diff,
diff.DiffAndApplyPatch,
diff.DiffCommits,
sync.FetchPrune,
}

func GetTests() []*components.IntegrationTest {
Expand Down
10 changes: 0 additions & 10 deletions test/integration/fetchPrune/config/config.yml

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/fetchPrune/expected/origin/HEAD

This file was deleted.

8 changes: 0 additions & 8 deletions test/integration/fetchPrune/expected/origin/config

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/fetchPrune/expected/origin/description

This file was deleted.

7 changes: 0 additions & 7 deletions test/integration/fetchPrune/expected/origin/info/exclude

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.
2 changes: 0 additions & 2 deletions test/integration/fetchPrune/expected/origin/packed-refs

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/fetchPrune/expected/repo/.git_keep/HEAD

This file was deleted.

21 changes: 0 additions & 21 deletions test/integration/fetchPrune/expected/repo/.git_keep/config

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

3 changes: 0 additions & 3 deletions test/integration/fetchPrune/expected/repo/.git_keep/logs/HEAD

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Binary file not shown.

This file was deleted.

Binary file not shown.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/fetchPrune/expected/repo/myfile1

This file was deleted.

1 change: 0 additions & 1 deletion test/integration/fetchPrune/recording.json

This file was deleted.

34 changes: 0 additions & 34 deletions test/integration/fetchPrune/setup.sh

This file was deleted.

4 changes: 0 additions & 4 deletions test/integration/fetchPrune/test.json

This file was deleted.

0 comments on commit 277ca70

Please sign in to comment.