@@ -12,17 +12,19 @@ import (
1212)
1313
1414var 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
2426func 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 {
0 commit comments