diff --git a/e2e_tests/helpers.go b/e2e_tests/helpers.go index 898093dc..dc35447e 100644 --- a/e2e_tests/helpers.go +++ b/e2e_tests/helpers.go @@ -4,6 +4,8 @@ import ( "testing" "github.com/aviator-co/av/internal/git" + "github.com/aviator-co/av/internal/meta" + "github.com/aviator-co/av/internal/meta/jsonfiledb" "github.com/stretchr/testify/require" ) @@ -12,3 +14,11 @@ func RequireCurrentBranchName(t *testing.T, repo *git.Repo, name string) { require.NoError(t, err, "failed to determine current branch name") require.Equal(t, name, currentBranch, "expected current branch to be %q, got %q", name, currentBranch) } + +func GetStoredParentBranchState(t *testing.T, repo *git.Repo, name string) meta.BranchState { + // We shouldn't do this as part of an E2E test, but it's hard to ensure otherwise. + db, err := jsonfiledb.OpenRepo(repo) + require.NoError(t, err, "failed to open repo db") + br, _ := db.ReadTx().Branch(name) + return br.Parent +} diff --git a/e2e_tests/stack_sync_test.go b/e2e_tests/stack_sync_test.go index cf55896c..a22f4761 100644 --- a/e2e_tests/stack_sync_test.go +++ b/e2e_tests/stack_sync_test.go @@ -9,6 +9,7 @@ import ( "github.com/aviator-co/av/internal/git" "github.com/aviator-co/av/internal/git/gittest" + "github.com/aviator-co/av/internal/meta" "github.com/stretchr/testify/require" ) @@ -126,6 +127,25 @@ func TestStackSync(t *testing.T) { }) require.NoError(t, err) require.Equal(t, 4, len(revs)) + + stack1Commit, err := repo.RevParse(&git.RevParse{Rev: "stack-1"}) + require.NoError(t, err) + + stack2Commit, err := repo.RevParse(&git.RevParse{Rev: "stack-2"}) + require.NoError(t, err) + + require.Equal(t, meta.BranchState{ + Name: "main", + Trunk: true, + }, GetStoredParentBranchState(t, repo, "stack-1")) + require.Equal(t, meta.BranchState{ + Name: "stack-1", + Head: stack1Commit, + }, GetStoredParentBranchState(t, repo, "stack-2")) + require.Equal(t, meta.BranchState{ + Name: "stack-2", + Head: stack2Commit, + }, GetStoredParentBranchState(t, repo, "stack-3")) } func TestStackSyncAbort(t *testing.T) { diff --git a/internal/actions/sync_branch.go b/internal/actions/sync_branch.go index b55443be..90ba3932 100644 --- a/internal/actions/sync_branch.go +++ b/internal/actions/sync_branch.go @@ -359,6 +359,10 @@ func syncBranchRebase( } msgRebaseResult(rebase) + branch.Parent = parentState + branch.Parent.Head = parentHead + tx.SetBranch(branch) + //nolint:exhaustive switch rebase.Status { case git.RebaseConflict: