Skip to content

Commit 10a604e

Browse files
authored
feat(cmd): improve adopt command ergonomics (#8)
1 parent c08e781 commit 10a604e

3 files changed

Lines changed: 18 additions & 19 deletions

File tree

cmd/adopt.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ import (
1212
)
1313

1414
var adoptCmd = &cobra.Command{
15-
Use: "adopt [branch]",
15+
Use: "adopt <parent>",
1616
Short: "Start tracking an existing branch",
17-
Long: `Start tracking an existing branch by setting its parent.`,
18-
Args: cobra.MaximumNArgs(1),
19-
RunE: runAdopt,
17+
Long: `Start tracking an existing branch by setting its parent.
18+
19+
By default, adopts the current branch. Use --branch to specify a different branch.`,
20+
Args: cobra.ExactArgs(1),
21+
RunE: runAdopt,
2022
}
2123

22-
var adoptParentFlag string
24+
var adoptBranchFlag string
2325

2426
func init() {
25-
adoptCmd.Flags().StringVar(&adoptParentFlag, "parent", "", "parent branch")
27+
adoptCmd.Flags().StringVar(&adoptBranchFlag, "branch", "", "branch to adopt (default: current branch)")
2628
rootCmd.AddCommand(adoptCmd)
2729
}
2830

@@ -39,10 +41,13 @@ func runAdopt(cmd *cobra.Command, args []string) error {
3941

4042
g := git.New(cwd)
4143

42-
// Determine branch to adopt
44+
// Parent is the required positional argument
45+
parent := args[0]
46+
47+
// Determine branch to adopt (from flag or current branch)
4348
var branchName string
44-
if len(args) > 0 {
45-
branchName = args[0]
49+
if adoptBranchFlag != "" {
50+
branchName = adoptBranchFlag
4651
} else {
4752
branchName, err = g.CurrentBranch()
4853
if err != nil {
@@ -60,12 +65,6 @@ func runAdopt(cmd *cobra.Command, args []string) error {
6065
return fmt.Errorf("branch %q is already tracked", branchName)
6166
}
6267

63-
// Determine parent
64-
parent := adoptParentFlag
65-
if parent == "" {
66-
return fmt.Errorf("--parent is required")
67-
}
68-
6968
// Validate parent is trunk or tracked
7069
trunk, err := cfg.GetTrunk()
7170
if err != nil {

e2e/adopt_orphan_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ func TestAdoptExistingBranch(t *testing.T) {
1111
env.Git("checkout", "-b", "external-branch")
1212
env.CreateCommit("external work")
1313

14-
// Adopt it with explicit parent
15-
env.MustRun("adopt", "external-branch", "--parent", "main")
14+
// Adopt it (current branch with main as parent)
15+
env.MustRun("adopt", "main")
1616

1717
env.AssertStackParent("external-branch", "main")
1818
}

e2e/chaos_manual_git_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ func TestManualBranchCreate(t *testing.T) {
3838
t.Errorf("manual branch should not be tracked, got parent %q", parent)
3939
}
4040

41-
// Can adopt it into the stack
42-
env.MustRun("adopt", "manual-branch", "--parent", "main")
41+
// Can adopt it into the stack (current branch with main as parent)
42+
env.MustRun("adopt", "main")
4343
env.AssertStackParent("manual-branch", "main")
4444

4545
// Now it shows in log

0 commit comments

Comments
 (0)