Skip to content

Commit

Permalink
fix: Update recorded parent's HEAD after rebase (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
draftcode authored May 8, 2023
1 parent 244991f commit ba0e475
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
10 changes: 10 additions & 0 deletions e2e_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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
}
20 changes: 20 additions & 0 deletions e2e_tests/stack_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions internal/actions/sync_branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ba0e475

Please sign in to comment.