Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve av stack reorder UX #207

Merged
Changes from 1 commit
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
Next Next commit
[MER-3061] feat: improve av stack reorder UX
Travis DePrato committed Oct 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 4d3428cdaa1edcefb47ed2c686c211ce0cb9341c
4 changes: 2 additions & 2 deletions internal/actions/sync_branch.go
Original file line number Diff line number Diff line change
@@ -355,8 +355,8 @@ func syncBranchRebase(

// Scenario 3: the branch is not up-to-date with its parent.
_, _ = fmt.Fprint(os.Stderr,
" - synching branch ", colors.UserInput(branch.Name),
" on latest commit ", git.ShortSha(parentHead),
" - syncing branch ", colors.UserInput(branch.Name),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: both are correct

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, only changing this because sync is more common and this is the only instance in this codebase where we use synch instead.

" on latest commit ", colors.UserInput(git.ShortSha(parentHead)),
" of parent branch ", colors.UserInput(parentState.Name),
"\n",
)
3 changes: 3 additions & 0 deletions internal/git/git.go
Original file line number Diff line number Diff line change
@@ -112,6 +112,9 @@ type Output struct {

func (o Output) Lines() []string {
s := strings.TrimSpace(string(o.Stdout))
if s == "" {
return nil
}
return strings.Split(s, "\n")
}

16 changes: 16 additions & 0 deletions internal/reorder/editor.go
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ func EditPlan(repo *git.Repo, plan []Cmd) ([]Cmd, error) {
text.WriteString(cmd.String())
text.WriteString("\n")
}
text.WriteString(instructionsText)

res, err := editor.Launch(repo, editor.Config{
Text: text.String(),
@@ -76,3 +77,18 @@ func Diff(old []Cmd, new []Cmd) PlanDiff {
AddedBranches: sliceutils.Subtract(newBranches, oldBranches),
}
}

const instructionsText = `
# Instructions:
#
# Commands:
# sb, stack-branch <branch-name> [--parent <parent-branch-name> | --trunk <trunk-branch-name>]
# Create a new branch as part of a stack. If parent is not specified,
# the previous branch in the stack is used (if any). If trunk is
# specified, the branch is rooted from the given branch.
# trunk-branch-name can be either a branch name or a branch name with a
# commit ID in the format "<branch-name>@<commit-id>".
# p, pick <commit-id>
# Pick a commit to be included in the stack. Only valid after a
# stack-branch command.
`
14 changes: 12 additions & 2 deletions internal/reorder/plan.go
Original file line number Diff line number Diff line change
@@ -37,9 +37,9 @@ func CreatePlan(repo *git.Repo, tx meta.ReadTx, rootBranch string) ([]Cmd, error
branchCmd.Trunk = branch.Parent.Name + "@" + trunkCommit
upstreamCommit = trunkCommit
}
cmds = append(cmds, branchCmd)

// Add a pick command for every commit associated with this branch
// Figure out the commits that belong to this branch.
// We'll use this to generate a "pick" command for each commit.
commitIDs, err := repo.RevList(git.RevListOpts{
Specifiers: []string{branchName, "^" + upstreamCommit},
Reverse: true,
@@ -48,13 +48,23 @@ func CreatePlan(repo *git.Repo, tx meta.ReadTx, rootBranch string) ([]Cmd, error
return nil, err
}

// If no commits associated with this branch, bail out early and add a
// helpful comment for the user.
if len(commitIDs) == 0 {
branchCmd.Comment = "this branch has no commits"
cmds = append(cmds, branchCmd)
continue
}

commitObjects, err := repo.GetRefs(&git.GetRefs{
Revisions: commitIDs,
})
if err != nil {
return nil, err
}

// Append the "stack-branch" command and each "pick" command to the plan
cmds = append(cmds, branchCmd)
for _, object := range commitObjects {
commit, err := git.ParseCommitContents(object.Contents)
if err != nil {
6 changes: 6 additions & 0 deletions internal/reorder/stackbranch.go
Original file line number Diff line number Diff line change
@@ -26,6 +26,8 @@ type StackBranchCmd struct {
// The branch can be rooted at a given commit by appending "@<commit>" to the
// branch name.
Trunk string
// An optional comment to include in the reorder plan for this command.
Comment string
}

func (b StackBranchCmd) Execute(ctx *Context) error {
@@ -98,6 +100,10 @@ func (b StackBranchCmd) String() string {
sb.WriteString(" --trunk ")
sb.WriteString(b.Trunk)
}
if b.Comment != "" {
sb.WriteString(" # ")
sb.WriteString(b.Comment)
}
return sb.String()
}