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

Move from av stack branch to av branch #465

Closed
wants to merge 1 commit into from
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
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Join our discord community: [https://discord.gg/TFgtZtN8](https://discord.gg/NFs
Create a new branch and make some changes:

```sh
$ av stack branch feature-1
$ av branch feature-1
$ echo "Hello, world!" > hello.txt
$ git add hello.txt
$ git commit -m "Add hello.txt"
Expand All @@ -54,7 +54,7 @@ Create a new branch and make some changes. Create another PR that depends on the
previous PR:

```sh
$ av stack branch feature-2
$ av branch feature-2
$ echo "Another feature" >> hello.txt
$ git add hello.txt
$ git commit -m "Update hello.txt"
Expand Down Expand Up @@ -224,19 +224,19 @@ Download the binary from the [releases page](https://github.com/aviator-co/av/re

# Example commands

| Command | Description |
| ------------------- | ---------------------------------------------------------- |
| `av stack branch` | Create a new child branch from the current branch. |
| `av stack restack` | Rebase the branches to their parents. |
| `av pr create` | Create or update a PR. |
| `av stack tree` | Visualize the PRs. |
| `av sync --all` | Fetch and rebase all branches. |
| `av stack adopt` | Adopt a branch that is not created from `av stack branch`. |
| `av stack reparent` | Change the parent of the current branch. |
| `av stack switch` | Check out branches interactively. |
| `av stack reorder` | Reorder the branches. |
| `av commit amend` | Amend the last commit and rebase the children. |
| `av commit split` | Split the last commit. |
| Command | Description |
| ------------------- | ---------------------------------------------------- |
| `av branch` | Create a new child branch from the current branch. |
| `av stack restack` | Rebase the branches to their parents. |
| `av pr create` | Create or update a PR. |
| `av stack tree` | Visualize the PRs. |
| `av sync --all` | Fetch and rebase all branches. |
| `av stack adopt` | Adopt a branch that is not created from `av branch`. |
| `av stack reparent` | Change the parent of the current branch. |
| `av stack switch` | Check out branches interactively. |
| `av stack reorder` | Reorder the branches. |
| `av commit amend` | Amend the last commit and rebase the children. |
| `av commit split` | Split the last commit. |

# How it works

Expand Down
46 changes: 23 additions & 23 deletions cmd/av/stack_branch.go → cmd/av/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/spf13/cobra"
)

var stackBranchFlags struct {
var branchFlags struct {
// The parent branch to base the new branch off.
// By default, this is the current branch.
Parent string
Expand All @@ -27,18 +27,18 @@ var stackBranchFlags struct {
// If true, rename the current branch even if a pull request exists.
Force bool
}
var stackBranchCmd = &cobra.Command{
Use: "branch [flags] <branch-name> [<parent-branch>]",
Aliases: []string{"b", "br"},
Short: "Create or rename a branch in the stack",
Long: `Create a new branch that is stacked on the current branch.
var branchCmd = &cobra.Command{
Use: "branch [flags] <branch-name> [<parent-branch>]",
Short: "Create or rename a branch in the stack",
Long: strings.TrimSpace(`
Create a new branch that is stacked on the current branch.

<parent-branch>. If omitted, the new branch bases off the current branch.

If the --rename/-m flag is given, the current branch is renamed to the name
given as the first argument to the command. Branches should only be renamed
with this command (not with git branch -m ...) because av needs to update
internal tracking metadata that defines the order of branches within a stack.`,
internal tracking metadata that defines the order of branches within a stack.`),
Args: cobra.RangeArgs(0, 2),
RunE: func(cmd *cobra.Command, args []string) (reterr error) {
if len(args) == 0 {
Expand All @@ -58,8 +58,8 @@ internal tracking metadata that defines the order of branches within a stack.`,
}

branchName := args[0]
if stackBranchFlags.Rename {
return stackBranchMove(repo, db, branchName, stackBranchFlags.Force)
if branchFlags.Rename {
return branchMove(repo, db, branchName, branchFlags.Force)
}

// Determine important contextual information from Git
Expand All @@ -70,7 +70,7 @@ internal tracking metadata that defines the order of branches within a stack.`,
}

if len(args) == 2 {
stackBranchFlags.Parent = args[1]
branchFlags.Parent = args[1]
}

tx := db.WriteTx()
Expand All @@ -82,8 +82,8 @@ internal tracking metadata that defines the order of branches within a stack.`,

// Determine the parent branch and make sure it's checked out
var parentBranchName string
if stackBranchFlags.Parent != "" {
parentBranchName = stackBranchFlags.Parent
if branchFlags.Parent != "" {
parentBranchName = branchFlags.Parent
} else {
var err error
parentBranchName, err = repo.CurrentBranchName()
Expand Down Expand Up @@ -168,16 +168,16 @@ internal tracking metadata that defines the order of branches within a stack.`,
}

func init() {
stackBranchCmd.Flags().
StringVar(&stackBranchFlags.Parent, "parent", "", "the parent branch to base the new branch off of")
branchCmd.Flags().
StringVar(&branchFlags.Parent, "parent", "", "the parent branch to base the new branch off of")
// NOTE: We use -m as the shorthand here to match `git branch -m ...`.
// See the comment on stackBranchFlags.Rename.
stackBranchCmd.Flags().
BoolVarP(&stackBranchFlags.Rename, "rename", "m", false, "rename the current branch")
stackBranchCmd.Flags().
BoolVar(&stackBranchFlags.Force, "force", false, "force rename the current branch, even if a pull request exists")
// See the comment on branchFlags.Rename.
branchCmd.Flags().
BoolVarP(&branchFlags.Rename, "rename", "m", false, "rename the current branch")
branchCmd.Flags().
BoolVar(&branchFlags.Force, "force", false, "force rename the current branch, even if a pull request exists")

_ = stackBranchCmd.RegisterFlagCompletionFunc(
_ = branchCmd.RegisterFlagCompletionFunc(
"parent",
func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
branches, _ := allBranches()
Expand All @@ -186,7 +186,7 @@ func init() {
)
}

func stackBranchMove(
func branchMove(
repo *git.Repo,
db meta.DB,
newBranch string,
Expand Down Expand Up @@ -233,7 +233,7 @@ func stackBranchMove(

if !force {
if currentMeta.PullRequest != nil {
_, _ = fmt.Fprint(
fmt.Fprint(
os.Stderr,
colors.Failure(
"Cannot rename branch ",
Expand Down Expand Up @@ -272,7 +272,7 @@ func stackBranchMove(
return errors.WrapIff(err, "failed to rename Git branch")
}
} else {
_, _ = fmt.Fprint(
fmt.Fprint(
os.Stderr,
"Branch ",
colors.UserInput(oldBranch),
Expand Down
1 change: 1 addition & 0 deletions cmd/av/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func init() {
)
rootCmd.AddCommand(
branchMetaCmd,
branchCmd,
commitCmd,
fetchCmd,
initCmd,
Expand Down
5 changes: 4 additions & 1 deletion cmd/av/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ var stackCmd = &cobra.Command{
func init() {
deprecatedStackSyncCmd := deprecateCommand(*syncCmd, "av sync", "sync")

deprecatedBranchCmd := deprecateCommand(*branchCmd, "av branch", "branch")
deprecatedBranchCmd.Aliases = []string{"b", "br"}

stackCmd.AddCommand(
deprecatedBranchCmd,
deprecatedStackSyncCmd,
stackAdoptCmd,
stackBranchCmd,
stackBranchCommitCmd,
stackDiffCmd,
stackForEachCmd,
Expand Down
2 changes: 1 addition & 1 deletion demos/stack_adopt/stack_adopt_with_stack_root.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter
Type 'create_commit "my-file" "1b" "Commit 1b"' Enter

Expand Down
6 changes: 3 additions & 3 deletions demos/stack_restack/stack_restack.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter

Type 'av stack branch stack-2' Enter
Type 'av branch stack-2' Enter
Type 'create_commit "my-file" "2a" "Commit 2a"' Enter

Type 'av stack branch stack-3' Enter
Type 'av branch stack-3' Enter
Type 'create_commit "my-file" "3a" "Commit 3a"' Enter

Type 'git switch stack-1' Enter
Expand Down
8 changes: 4 additions & 4 deletions demos/stack_switch/stack_switch.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter

Type 'av stack branch stack-2' Enter
Type 'av branch stack-2' Enter
Type 'create_commit "my-file" "2a" "Commit 2a"' Enter

Type 'av stack branch stack-3' Enter
Type 'av branch stack-3' Enter
Type 'create_commit "my-file" "3a" "Commit 3a"' Enter

Type 'git switch stack-1' Enter

Type 'av stack branch stack-4' Enter
Type 'av branch stack-4' Enter
Type 'create_commit "my-file" "4a" "Commit 4a"' Enter

Type 'git switch stack-1' Enter
Expand Down
8 changes: 4 additions & 4 deletions demos/stack_switch/stack_switch_detached.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter

Type 'av stack branch stack-2' Enter
Type 'av branch stack-2' Enter
Type 'create_commit "my-file" "2a" "Commit 2a"' Enter

Type 'av stack branch stack-3' Enter
Type 'av branch stack-3' Enter
Type 'create_commit "my-file" "3a" "Commit 3a"' Enter

Type 'git switch stack-1' Enter

Type 'av stack branch stack-4' Enter
Type 'av branch stack-4' Enter
Type 'create_commit "my-file" "4a" "Commit 4a"' Enter

Type 'git switch --detach stack-1' Enter
Expand Down
8 changes: 4 additions & 4 deletions demos/stack_switch/stack_switch_non_managed_branch.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter

Type 'av stack branch stack-2' Enter
Type 'av branch stack-2' Enter
Type 'create_commit "my-file" "2a" "Commit 2a"' Enter

Type 'av stack branch stack-3' Enter
Type 'av branch stack-3' Enter
Type 'create_commit "my-file" "3a" "Commit 3a"' Enter

Type 'git switch stack-1' Enter

Type 'av stack branch stack-4' Enter
Type 'av branch stack-4' Enter
Type 'create_commit "my-file" "4a" "Commit 4a"' Enter

Type 'git switch stack-1' Enter
Expand Down
8 changes: 4 additions & 4 deletions demos/stack_switch/stack_switch_trunk.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av branch stack-1' Enter
Type 'create_commit "my-file" "1a" "Commit 1a"' Enter

Type 'av stack branch stack-2' Enter
Type 'av branch stack-2' Enter
Type 'create_commit "my-file" "2a" "Commit 2a"' Enter

Type 'av stack branch stack-3' Enter
Type 'av branch stack-3' Enter
Type 'create_commit "my-file" "3a" "Commit 3a"' Enter

Type 'git switch stack-1' Enter

Type 'av stack branch stack-4' Enter
Type 'av branch stack-4' Enter
Type 'create_commit "my-file" "4a" "Commit 4a"' Enter

Type 'git switch main' Enter
Expand Down
4 changes: 2 additions & 2 deletions demos/stack_tidy/stack_tidy_deleted.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av stack branch stack-2' Enter
Type 'av branch stack-1' Enter
Type 'av branch stack-2' Enter
Type 'git switch main' Enter
Type 'git branch -D stack-2' Enter
Type 'git branch -D stack-1' Enter
Expand Down
4 changes: 2 additions & 2 deletions demos/stack_tidy/stack_tidy_orphaned.tape
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Hide
Type '. ../test_utils.sh' Enter
Type 'new_temp_repo' Enter

Type 'av stack branch stack-1' Enter
Type 'av stack branch stack-2' Enter
Type 'av branch stack-1' Enter
Type 'av branch stack-2' Enter
Type 'git switch main' Enter
Type 'git branch -D stack-1' Enter
Type 'clear' Enter
Expand Down
8 changes: 4 additions & 4 deletions docs/av-stack-branch.1.md → docs/av-branch.1.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# av-stack-branch
# av-branch

## NAME

av-stack-branch - Create or rename a branch in the stack
av-branch - Create or rename a branch in the stack

## SYNOPSIS

`av stack branch [-m | --rename] [--force] [--parent <parent_branch>] <branch-name> [<parent_branch>]`
`av branch [-m | --rename] [--force] [--parent <parent_branch>] <branch-name> [<parent_branch>]`

## DESCRIPTION

Expand All @@ -17,7 +17,7 @@ instead of creating a new branch. Branches should only be renamed with this
command (not with `git branch -m ...`) because av needs to update internal
tracking metadata that defines the order of branches within a stack. If you
renamed a branch with `git branch -m`, you can retroactively update the internal
metadata with `av stack branch --rename <old-branch-name>:<new-branch-name>`.
metadata with `av branch --rename <old-branch-name>:<new-branch-name>`.

## OPTIONS

Expand Down
4 changes: 2 additions & 2 deletions docs/av-git-interaction.7.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ av-git-interaction - av CLI Git Interaction

Typically in Git, a branch is created with `git branch`, `git switch`, or `git
checkout`. Since `av` needs to keep track of the extra information about
branches such as the parent branch, we have `av-stack-branch`(1) to create a new
branches such as the parent branch, we have `av-branch`(1) to create a new
branch and track the necessary information. This metadata is stored in
`.git/av/av.db`. We call the branches that `av` has metadata for as "managed
branches", and the branches that av doesn't have metadata for as "unmanaged
branches".

There is a case where you created a branch without going through
`av-stack-branch`(1). In this case, you can attach the branch metadata by using
`av-branch`(1). In this case, you can attach the branch metadata by using
`av-stack-adopt`(1). The opposite can be done with `av-stack-orphan`(1).

## BRANCH DELETION
Expand Down
2 changes: 1 addition & 1 deletion docs/av.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ av - Aviator CLI
## SUBCOMMANDS

- av-auth(1): Show info about the logged in user
- av-branch(1): Create or rename a branch in the stack
- av-commit-amend(1): Amend a commit
- av-commit-create(1): Record changes to the repository with commits
- av-commit-split(1): Split a commit into multiple commits
Expand All @@ -21,7 +22,6 @@ av - Aviator CLI
- av-pr-status(1): Get the status of the associated pull request
- av-stack-adopt(1): Adopt branches that are not managed by `av`
- av-stack-branch-commit(1): Create a new branch in the stack with the staged changes
- av-stack-branch(1): Create or rename a branch in the stack
- av-stack-diff(1): Show the diff between working tree and parent branch
- av-stack-next(1): Checkout the next branch in the stack
- av-stack-orphan(1): Orphan branches that are managed by `av`
Expand Down
Loading