-
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.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package e2e_tests | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/aviator-co/av/internal/git/gittest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestBranch(t *testing.T) { | ||
repo := gittest.NewTempRepo(t) | ||
Chdir(t, repo.Dir()) | ||
|
||
// To start, we create a simple two-stack where each stack has a single commit. | ||
// Our stack looks like: | ||
// stack-1: main -> 1a -> 1b | ||
// stack-2: \ -> 2a -> 2b | ||
|
||
// Then create new branch stack-3 use by "av branch" command | ||
// stack-1: main -> 1a -> 1b | ||
// stack-2: \ -> 2a -> 2b | ||
// stack-3: \ | ||
|
||
// Setup initial state | ||
require.Equal(t, 0, Cmd(t, "git", "checkout", "-b", "stack-1").ExitCode) | ||
gittest.CommitFile(t, repo, "my-file", []byte("1a\n"), gittest.WithMessage("Commit 1a")) | ||
gittest.CommitFile(t, repo, "my-file", []byte("1a\n1b\n"), gittest.WithMessage("Commit 1b")) | ||
RequireAv(t, "stack", "branch", "stack-2") | ||
gittest.CommitFile(t, repo, "my-file", []byte("1a\n1b\n2a\n"), gittest.WithMessage("Commit 2a")) | ||
gittest.CommitFile( | ||
t, | ||
repo, | ||
"my-file", | ||
[]byte("1a\n1b\n2a\n2b\n"), | ||
gittest.WithMessage("Commit 2b"), | ||
) | ||
|
||
tree := Av(t, "stack", "tree") | ||
require.Contains(t, tree.Stdout, "stack-1") | ||
require.Contains(t, tree.Stdout, "stack-2") | ||
require.NotContains(t, tree.Stdout, "stack-3") | ||
|
||
out := Av(t, "branch", "stack-3", "stack-1") | ||
require.Equal(t, "Created branch stack-3 from stack-1\n", out.Stdout) | ||
|
||
tree = Av(t, "stack", "tree") | ||
require.Contains(t, tree.Stdout, "stack-1") | ||
require.Contains(t, tree.Stdout, "stack-2") | ||
require.Contains(t, tree.Stdout, "stack-3") | ||
|
||
} |