Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions cmd/av/adopt.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,11 @@ func adoptForceAdoption(
return errors.New("cannot adopt the current branch as its parent")
}

if isCurrentBranchTrunk, err := repo.IsTrunkBranch(ctx, currentBranch); err != nil {
return errors.Wrap(err, "failed to check if the current branch is trunk")
} else if isCurrentBranchTrunk {
if repo.IsTrunkBranch(currentBranch) {
return errors.New("cannot adopt the default branch")
}

isParentBranchTrunk, err := repo.IsTrunkBranch(ctx, parent)
if err != nil {
return errors.Wrap(err, "failed to check if the parent branch is trunk")
}
isParentBranchTrunk := repo.IsTrunkBranch(parent)
if isParentBranchTrunk {
branch.Parent = meta.BranchState{
Name: parent,
Expand Down
19 changes: 5 additions & 14 deletions cmd/av/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,7 @@ func createBranch(
) (reterr error) {
// Determine important contextual information from Git
// or if a parent branch is provided, check it allows as a default branch
defaultBranch, err := repo.DefaultBranch(ctx)
if err != nil {
return errors.WrapIf(err, "failed to determine repository default branch")
}
defaultBranch := repo.DefaultBranch()

tx := db.WriteTx()
cu := cleanup.New(func() {
Expand All @@ -283,7 +280,7 @@ func createBranch(
// Determine the parent branch and make sure it's checked out
if parentBranchName == "" {
var err error
parentBranchName, err = repo.CurrentBranchName(ctx)
parentBranchName, err = repo.CurrentBranchName()
if err != nil {
return errors.WrapIff(err, "failed to get current branch name")
}
Expand All @@ -295,10 +292,7 @@ func createBranch(
}
parentBranchName = strings.TrimPrefix(parentBranchName, remoteName+"/")

isBranchFromTrunk, err := repo.IsTrunkBranch(ctx, parentBranchName)
if err != nil {
return errors.WrapIf(err, "failed to determine if branch is a trunk")
}
isBranchFromTrunk := repo.IsTrunkBranch(parentBranchName)
checkoutStartingPoint := parentBranchName
var parentHead string
if isBranchFromTrunk {
Expand Down Expand Up @@ -403,7 +397,7 @@ func branchMove(
oldBranch, newBranch, _ = strings.Cut(newBranch, ":")
} else {
var err error
oldBranch, err = repo.CurrentBranchName(ctx)
oldBranch, err = repo.CurrentBranchName()
if err != nil {
return err
}
Expand All @@ -422,10 +416,7 @@ func branchMove(

currentMeta, ok := tx.Branch(oldBranch)
if !ok {
defaultBranch, err := repo.DefaultBranch(ctx)
if err != nil {
return errors.WrapIf(err, "failed to determine repository default branch")
}
defaultBranch := repo.DefaultBranch()
currentMeta.Parent = meta.BranchState{
Name: defaultBranch,
Trunk: true,
Expand Down
4 changes: 2 additions & 2 deletions cmd/av/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ var commitCmd = &cobra.Command{
}

func runCreate(ctx context.Context, repo *git.Repo, db meta.DB) error {
currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return errors.WrapIf(err, "failed to determine current branch")
}
Expand Down Expand Up @@ -182,7 +182,7 @@ func runAmend(
edit bool,
all bool,
) error {
currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return errors.WrapIf(err, "failed to determine current branch")
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/av/commit_common.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"context"
"strings"

"emperror.dev/errors"
Expand Down Expand Up @@ -114,7 +113,7 @@ func (vm *postCommitRestackViewModel) writeState(state *sequencerui.RestackState
}

func (vm *postCommitRestackViewModel) createState() (*sequencerui.RestackState, error) {
currentBranch, err := vm.repo.CurrentBranchName(context.Background())
currentBranch, err := vm.repo.CurrentBranchName()
if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions cmd/av/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,15 @@ Generates the diff between the working tree and the parent branch
return err
}

currentBranchName, err := repo.CurrentBranchName(ctx)
currentBranchName, err := repo.CurrentBranchName()
if err != nil {
return err
}

tx := db.ReadTx()
branch, exists := tx.Branch(currentBranchName)
if !exists {
defaultBranch, err := repo.DefaultBranch(ctx)
if err != nil {
return err
}
defaultBranch := repo.DefaultBranch()
branch.Parent = meta.BranchState{
Name: defaultBranch,
Trunk: true,
Expand Down
10 changes: 3 additions & 7 deletions cmd/av/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ var ErrRepoNotInitialized = errors.Sentinel(
)

func getDB(ctx context.Context, repo *git.Repo) (meta.DB, error) {
db, exists, err := getOrCreateDB(ctx, repo)
db, exists, err := getOrCreateDB(repo)
if err != nil {
return nil, err
}
Expand All @@ -67,7 +67,7 @@ func getDB(ctx context.Context, repo *git.Repo) (meta.DB, error) {
return db, nil
}

func getOrCreateDB(ctx context.Context, repo *git.Repo) (meta.DB, bool, error) {
func getOrCreateDB(repo *git.Repo) (meta.DB, bool, error) {
dbPath := filepath.Join(repo.AvDir(), "av.db")
return jsonfiledb.OpenPath(dbPath)
}
Expand All @@ -82,11 +82,7 @@ func allBranches(ctx context.Context) ([]string, error) {
return nil, err
}

defaultBranch, err := repo.DefaultBranch(ctx)
if err != nil {
return nil, err
}

defaultBranch := repo.DefaultBranch()
tx := db.ReadTx()

branches := []string{defaultBranch}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ var initCmd = &cobra.Command{
return err
}

db, _, err := getOrCreateDB(ctx, repo)
db, _, err := getOrCreateDB(repo)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/next.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func newNextModel(ctx context.Context, lastInStack bool, nInStack int) (stackNex
return stackNextModel{}, err
}

currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return stackNextModel{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/orphan.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var orphanCmd = &cobra.Command{
tx := db.WriteTx()
defer tx.Abort()

currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return errors.WrapIf(err, "failed to determine current branch")
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/av/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Examples:
if err != nil {
return err
}
branchName, err := repo.CurrentBranchName(ctx)
branchName, err := repo.CurrentBranchName()
if err != nil {
return errors.WrapIf(err, "failed to determine current branch")
}
Expand Down Expand Up @@ -183,7 +183,7 @@ func submitAll(ctx context.Context, current bool, draft bool) error {
cu := cleanup.New(func() { tx.Abort() })
defer cu.Cleanup()

currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return err
}
Expand Down Expand Up @@ -288,7 +288,7 @@ func queue(ctx context.Context) error {
}

tx := db.ReadTx()
currentBranchName, err := repo.CurrentBranchName(ctx)
currentBranchName, err := repo.CurrentBranchName()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/pr_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ func getQueryVariables(ctx context.Context) (map[string]any, error) {

tx := db.ReadTx()

currentBranchName, err := repo.CurrentBranchName(ctx)
currentBranchName, err := repo.CurrentBranchName()
if err != nil {
return nil, err
}
Expand Down
7 changes: 2 additions & 5 deletions cmd/av/prev.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,11 @@ var prevCmd = &cobra.Command{
return err
}
tx := db.ReadTx()
currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return err
}
isCurrentBranchTrunk, err := repo.IsTrunkBranch(ctx, currentBranch)
if err != nil {
return err
} else if isCurrentBranchTrunk {
if repo.IsTrunkBranch(currentBranch) {
fmt.Fprint(os.Stderr, "already on trunk branch (", colors.UserInput(currentBranch), ")\n")
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/reorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ squashed, dropped, or moved within the stack.
return actions.ErrExitSilently{ExitCode: 127}
}
tx := db.ReadTx()
currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return err
}
Expand Down
10 changes: 3 additions & 7 deletions cmd/av/reparent.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,18 @@ func (vm *reparentViewModel) writeState(state *sequencerui.RestackState) error {

func (vm *reparentViewModel) createState() (*sequencerui.RestackState, error) {
ctx := context.Background()
currentBranch, err := vm.repo.CurrentBranchName(ctx)
currentBranch, err := vm.repo.CurrentBranchName()
if err != nil {
return nil, err
}
if isCurrentBranchTrunk, err := vm.repo.IsTrunkBranch(ctx, currentBranch); err != nil {
return nil, err
} else if isCurrentBranchTrunk {
if vm.repo.IsTrunkBranch(currentBranch) {
return nil, errors.New("current branch is a trunk branch")
}
if _, exist := vm.db.ReadTx().Branch(currentBranch); !exist {
return nil, errors.New("current branch is not adopted to av")
}

if isParentBranchTrunk, err := vm.repo.IsTrunkBranch(ctx, reparentFlags.Parent); err != nil {
return nil, err
} else if !isParentBranchTrunk {
if !vm.repo.IsTrunkBranch(reparentFlags.Parent) {
if _, exist := vm.db.ReadTx().Branch(reparentFlags.Parent); !exist {
return nil, errors.New("parent branch is not adopted to av")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/squash.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func runSquash(ctx context.Context, repo *git.Repo, db meta.DB) error {
)
}

currentBranchName, err := repo.CurrentBranchName(ctx)
currentBranchName, err := repo.CurrentBranchName()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/stack_foreach.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Examples:
return err
}
tx := db.ReadTx()
currentBranch, err := repo.CurrentBranchName(ctx)
currentBranch, err := repo.CurrentBranchName()
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/av/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (vm *syncViewModel) initSync() tea.Cmd {
return uiutils.ErrCmd(errors.New("no restack in progress"))
}

isTrunkBranch, err := vm.repo.IsCurrentBranchTrunk(context.Background())
isTrunkBranch, err := vm.repo.IsCurrentBranchTrunk()
if err != nil {
return uiutils.ErrCmd(err)
}
Expand Down
5 changes: 1 addition & 4 deletions internal/actions/pr.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ func CreatePullRequest(
// figure this out based on whether or not we're on a stacked branch
parentState := branchMeta.Parent
if parentState.Name == "" {
defaultBranch, err := repo.DefaultBranch(ctx)
if err != nil {
return nil, errors.WrapIf(err, "failed to determine default branch")
}
defaultBranch := repo.DefaultBranch()
parentState = meta.BranchState{
Name: defaultBranch,
Trunk: true,
Expand Down
Loading