diff --git a/cmd/adopt.go b/cmd/adopt.go index d8601e3..4b38c6a 100644 --- a/cmd/adopt.go +++ b/cmd/adopt.go @@ -12,17 +12,19 @@ import ( ) var adoptCmd = &cobra.Command{ - Use: "adopt [branch]", + Use: "adopt ", Short: "Start tracking an existing branch", - Long: `Start tracking an existing branch by setting its parent.`, - Args: cobra.MaximumNArgs(1), - RunE: runAdopt, + Long: `Start tracking an existing branch by setting its parent. + +By default, adopts the current branch. Use --branch to specify a different branch.`, + Args: cobra.ExactArgs(1), + RunE: runAdopt, } -var adoptParentFlag string +var adoptBranchFlag string func init() { - adoptCmd.Flags().StringVar(&adoptParentFlag, "parent", "", "parent branch") + adoptCmd.Flags().StringVar(&adoptBranchFlag, "branch", "", "branch to adopt (default: current branch)") rootCmd.AddCommand(adoptCmd) } @@ -39,10 +41,13 @@ func runAdopt(cmd *cobra.Command, args []string) error { g := git.New(cwd) - // Determine branch to adopt + // Parent is the required positional argument + parent := args[0] + + // Determine branch to adopt (from flag or current branch) var branchName string - if len(args) > 0 { - branchName = args[0] + if adoptBranchFlag != "" { + branchName = adoptBranchFlag } else { branchName, err = g.CurrentBranch() if err != nil { @@ -60,12 +65,6 @@ func runAdopt(cmd *cobra.Command, args []string) error { return fmt.Errorf("branch %q is already tracked", branchName) } - // Determine parent - parent := adoptParentFlag - if parent == "" { - return fmt.Errorf("--parent is required") - } - // Validate parent is trunk or tracked trunk, err := cfg.GetTrunk() if err != nil { diff --git a/e2e/adopt_orphan_test.go b/e2e/adopt_orphan_test.go index 3d069fe..83e8ff9 100644 --- a/e2e/adopt_orphan_test.go +++ b/e2e/adopt_orphan_test.go @@ -11,8 +11,8 @@ func TestAdoptExistingBranch(t *testing.T) { env.Git("checkout", "-b", "external-branch") env.CreateCommit("external work") - // Adopt it with explicit parent - env.MustRun("adopt", "external-branch", "--parent", "main") + // Adopt it (current branch with main as parent) + env.MustRun("adopt", "main") env.AssertStackParent("external-branch", "main") } diff --git a/e2e/chaos_manual_git_test.go b/e2e/chaos_manual_git_test.go index f7708b6..f432aca 100644 --- a/e2e/chaos_manual_git_test.go +++ b/e2e/chaos_manual_git_test.go @@ -38,8 +38,8 @@ func TestManualBranchCreate(t *testing.T) { t.Errorf("manual branch should not be tracked, got parent %q", parent) } - // Can adopt it into the stack - env.MustRun("adopt", "manual-branch", "--parent", "main") + // Can adopt it into the stack (current branch with main as parent) + env.MustRun("adopt", "main") env.AssertStackParent("manual-branch", "main") // Now it shows in log