-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't fetch/push upstack branches on av commit create/amend
- Loading branch information
1 parent
50d63e0
commit d0e8428
Showing
8 changed files
with
151 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package e2e_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aviator-co/av/internal/git/gittest" | ||
"github.com/aviator-co/av/internal/meta/jsonfiledb" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
func TestCommitAmendInStack(t *testing.T) { | ||
repo := gittest.NewTempRepo(t) | ||
Chdir(t, repo.Dir()) | ||
RequireCmd(t, "git", "fetch") | ||
initialTimestamp := GetFetchHeadTimestamp(t, repo) | ||
|
||
// Create a branch and commit a file. | ||
filepath := gittest.CreateFile(t, repo, "one.txt", []byte("one")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "stack", "branch", "one") | ||
RequireAv(t, "commit", "create", "-m", "one") | ||
|
||
// Create another branch and commit a file. | ||
filepath = gittest.CreateFile(t, repo, "two.txt", []byte("two")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "stack", "branch", "two") | ||
RequireAv(t, "commit", "create", "-m", "two") | ||
|
||
// Go back to the first branch and amend the commit with another file. | ||
RequireCmd(t, "git", "checkout", "one") | ||
filepath = gittest.CreateFile(t, repo, "one-b.txt", []byte("one-b")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "commit", "amend", "--no-edit") | ||
|
||
// Verify that the branches are still there. | ||
db, err := jsonfiledb.OpenRepo(repo) | ||
require.NoError(t, err, "failed to open repo db") | ||
branchNames := maps.Keys(db.ReadTx().AllBranches()) | ||
require.ElementsMatch(t, branchNames, []string{"one", "two"}) | ||
|
||
// Commit shouldn't have triggered a fetch. | ||
updatedTimestamp := GetFetchHeadTimestamp(t, repo) | ||
require.Equal(t, initialTimestamp, updatedTimestamp) | ||
|
||
// It also shouldn't have triggered a push. | ||
// TODO: once we support mocking the GitHub API and there is an associated PR, | ||
// validate that a push didn't happen. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package e2e_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aviator-co/av/internal/git/gittest" | ||
"github.com/aviator-co/av/internal/meta/jsonfiledb" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
func TestCommitCreateInStack(t *testing.T) { | ||
repo := gittest.NewTempRepo(t) | ||
Chdir(t, repo.Dir()) | ||
RequireCmd(t, "git", "fetch") | ||
initialTimestamp := GetFetchHeadTimestamp(t, repo) | ||
|
||
// Create a branch and commit a file. | ||
filepath := gittest.CreateFile(t, repo, "one.txt", []byte("one")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "stack", "branch", "one") | ||
RequireAv(t, "commit", "create", "-m", "one") | ||
|
||
// Create another branch and commit a file. | ||
filepath = gittest.CreateFile(t, repo, "two.txt", []byte("two")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "stack", "branch", "two") | ||
RequireAv(t, "commit", "create", "-m", "two") | ||
|
||
// Go back to the first branch and commit another file. | ||
RequireCmd(t, "git", "checkout", "one") | ||
filepath = gittest.CreateFile(t, repo, "one-b.txt", []byte("one-b")) | ||
gittest.AddFile(t, repo, filepath) | ||
RequireAv(t, "commit", "create", "-m", "one-b") | ||
|
||
// Verify that the branches are still there. | ||
db, err := jsonfiledb.OpenRepo(repo) | ||
require.NoError(t, err, "failed to open repo db") | ||
branchNames := maps.Keys(db.ReadTx().AllBranches()) | ||
require.ElementsMatch(t, branchNames, []string{"one", "two"}) | ||
|
||
// Commit shouldn't have triggered a fetch. | ||
updatedTimestamp := GetFetchHeadTimestamp(t, repo) | ||
require.Equal(t, initialTimestamp, updatedTimestamp) | ||
|
||
// It also shouldn't have triggered a push. | ||
// TODO: once we support mocking the GitHub API and there is an associated PR, | ||
// validate that a push didn't happen. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package gittest | ||
|
||
import ( | ||
"os" | ||
"path" | ||
"testing" | ||
|
||
"github.com/aviator-co/av/internal/git" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func CreateFile( | ||
t *testing.T, | ||
repo *git.Repo, | ||
filename string, | ||
body []byte, | ||
) string { | ||
filepath := path.Join(repo.Dir(), filename) | ||
err := os.WriteFile(filepath, body, 0644) | ||
require.NoError(t, err, "failed to write file: %s", filename) | ||
return filepath | ||
} | ||
|
||
func AddFile( | ||
t *testing.T, | ||
repo *git.Repo, | ||
filepath string, | ||
) { | ||
_, err := repo.Git("add", filepath) | ||
require.NoError(t, err, "failed to add file: %s", filepath) | ||
} |