Skip to content

Commit

Permalink
update as per comments, but still WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Chafid committed Nov 10, 2024
1 parent ed184fe commit a642da1
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 22 deletions.
Binary file added cmd/av/av
Binary file not shown.
21 changes: 14 additions & 7 deletions cmd/av/stack_restack.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ import (
)

var stackRestackFlags struct {
All bool
Current bool
Abort bool
Continue bool
Skip bool
DryRun bool
All bool
Current bool
Abort bool
Continue bool
Skip bool
DryRun bool
Interactive bool
}

var stackRestackCmd = &cobra.Command{
Expand Down Expand Up @@ -77,6 +78,7 @@ func (vm *stackRestackViewModel) Init() tea.Cmd {
vm.restackModel.Continue = stackRestackFlags.Continue
vm.restackModel.Skip = stackRestackFlags.Skip
vm.restackModel.DryRun = stackRestackFlags.DryRun
vm.restackModel.Interactive = stackRestackFlags.Interactive
return vm.restackModel.Init()
}

Expand Down Expand Up @@ -191,6 +193,7 @@ func (vm *stackRestackViewModel) createState() (*sequencerui.RestackState, error
currentBranchRef,
stackRestackFlags.All,
stackRestackFlags.Current,
stackRestackFlags.Interactive,
)
if err != nil {
return nil, err
Expand Down Expand Up @@ -224,6 +227,10 @@ func init() {
&stackRestackFlags.DryRun, "dry-run", false,
"show the list of branches that will be rebased without actually rebasing them",
)
stackRestackCmd.Flags().BoolVar(
&stackRestackFlags.Interactive, "interactive", false,
"run the rebase command with interactive option",
)

stackRestackCmd.MarkFlagsMutuallyExclusive("continue", "abort", "skip")
stackRestackCmd.MarkFlagsMutuallyExclusive("continue", "abort", "skip", "interactive")
}
3 changes: 3 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ func (o Output) Lines() []string {
}

func (r *Repo) Run(opts *RunOpts) (*Output, error) {
fmt.Println("git rebase with option ")
fmt.Println(opts.Args)
fmt.Println(opts.Interactive)
cmd := exec.Command("git", opts.Args...)
cmd.Dir = r.repoDir
r.log.Debugf("git %s", opts.Args)
Expand Down
12 changes: 12 additions & 0 deletions internal/git/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ type RebaseOpts struct {
// Optional (mutually exclusive with all other options)
Skip bool
// Optional
// If set, this is the rebase will be run with interactive option
Interactive bool
// Optional
// If set, use `git rebase --onto <upstream> ...`
Onto string
// Optional
Expand Down Expand Up @@ -49,6 +52,15 @@ func (r *Repo) Rebase(opts RebaseOpts) (*Output, error) {
Args: []string{"rebase", "--skip"},
})
}

if opts.Interactive {
args = append(args, "-i")
args = append(args, "master")
return r.Run(&RunOpts{
Args: args,
Interactive: true,
})
}
if opts.Onto != "" {
args = append(args, "--onto", opts.Onto)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/sequencer/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func PlanForRestack(
tx meta.ReadTx,
repo *git.Repo,
currentBranch plumbing.ReferenceName,
restackAll, restackCurrent bool,
restackAll, restackCurrent, restackInteractive bool,
) ([]sequencer.RestackOp, error) {
var targetBranches []plumbing.ReferenceName
var err error
Expand Down
14 changes: 8 additions & 6 deletions internal/sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func getBranchSnapshots(db meta.DB) map[plumbing.ReferenceName]*branchSnapshot {
func (seq *Sequencer) Run(
repo *git.Repo,
db meta.DB,
seqAbort, seqContinue, seqSkip bool,
seqAbort, seqContinue, seqSkip, seqInteractive bool,
) (*git.RebaseResult, error) {
if seqAbort || seqContinue || seqSkip {
return seq.runFromInterruptedState(repo, db, seqAbort, seqContinue, seqSkip)
Expand All @@ -99,7 +99,7 @@ func (seq *Sequencer) Run(
if seq.CurrentSyncRef == "" {
return nil, nil
}
return seq.rebaseBranch(repo, db)
return seq.rebaseBranch(repo, db, seqInteractive)
}

func (seq *Sequencer) runFromInterruptedState(
Expand Down Expand Up @@ -156,7 +156,7 @@ func (seq *Sequencer) runFromInterruptedState(
panic("unreachable")
}

func (seq *Sequencer) rebaseBranch(repo *git.Repo, db meta.DB) (*git.RebaseResult, error) {
func (seq *Sequencer) rebaseBranch(repo *git.Repo, db meta.DB, interactive bool) (*git.RebaseResult, error) {
op := seq.getCurrentOp()
snapshot, ok := seq.OriginalBranchSnapshots[op.Name]
if !ok {
Expand Down Expand Up @@ -196,10 +196,12 @@ func (seq *Sequencer) rebaseBranch(repo *git.Repo, db meta.DB) (*git.RebaseResul

// The commits from `rebaseFrom` to `snapshot.Name` should be rebased onto `rebaseOnto`.
opts := git.RebaseOpts{
Branch: op.Name.Short(),
Upstream: previousParentHash.String(),
Onto: newParentHash.String(),
Branch: op.Name.Short(),
Upstream: previousParentHash.String(),
Onto: newParentHash.String(),
Interactive: interactive,
}

result, err := repo.RebaseParse(opts)
if err != nil {
return nil, err
Expand Down
20 changes: 12 additions & 8 deletions internal/sequencer/sequencerui/ui.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sequencerui

import (
"fmt"
"strings"

"github.com/aviator-co/av/internal/git"
Expand Down Expand Up @@ -39,12 +40,13 @@ type RestackAbort struct{}
type RestackDone struct{}

type RestackModel struct {
Skip bool
Continue bool
Abort bool
DryRun bool
State *RestackState
Command string
Skip bool
Continue bool
Abort bool
DryRun bool
Interactive bool
State *RestackState
Command string

repo *git.Repo
db meta.DB
Expand Down Expand Up @@ -200,11 +202,13 @@ func (vm *RestackModel) View() string {
}

func (vm *RestackModel) runSeqWithContinuationFlags() tea.Msg {
result, err := vm.State.Seq.Run(vm.repo, vm.db, vm.Abort, vm.Continue, vm.Skip)
result, err := vm.State.Seq.Run(vm.repo, vm.db, vm.Abort, vm.Continue, vm.Skip, false)
return &RestackProgress{result: result, err: err}
}

func (vm *RestackModel) runSeq() tea.Msg {
result, err := vm.State.Seq.Run(vm.repo, vm.db, false, false, false)
fmt.Print("interactive ")
fmt.Print(vm.Interactive)
result, err := vm.State.Seq.Run(vm.repo, vm.db, false, false, false, vm.Interactive)
return &RestackProgress{result: result, err: err}
}

0 comments on commit a642da1

Please sign in to comment.