mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 19:49:43 -05:00
Implement --branch flag for dolt_add stored procedure
- Add supportsBranchFlag parameter to CreateAddArgParser - Update CLI usages to use CreateAddArgParser(false) - Update stored procedure to use CreateAddArgParser(true) - Add branch handling logic using revision-qualified database names - Add proper error handling for invalid branch names 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -137,11 +137,14 @@ func CreatePushArgParser() *argparser.ArgParser {
|
||||
return ap
|
||||
}
|
||||
|
||||
func CreateAddArgParser() *argparser.ArgParser {
|
||||
func CreateAddArgParser(supportsBranchFlag bool) *argparser.ArgParser {
|
||||
ap := argparser.NewArgParserWithVariableArgs("add")
|
||||
ap.ArgListHelp = append(ap.ArgListHelp, [2]string{"table", "Working table(s) to add to the list tables staged to be committed. The abbreviation '.' can be used to add all tables."})
|
||||
ap.SupportsFlag(AllFlag, "A", "Stages any and all changes (adds, deletes, and modifications) except for ignored tables.")
|
||||
ap.SupportsFlag(ForceFlag, "f", "Allow adding otherwise ignored tables.")
|
||||
if supportsBranchFlag {
|
||||
ap.SupportsString(BranchParam, "", "branch", "Add to the specified branch instead of the current branch.")
|
||||
}
|
||||
|
||||
return ap
|
||||
}
|
||||
|
||||
@@ -70,12 +70,12 @@ func (cmd AddCmd) Description() string {
|
||||
}
|
||||
|
||||
func (cmd AddCmd) Docs() *cli.CommandDocumentation {
|
||||
ap := cli.CreateAddArgParser()
|
||||
ap := cli.CreateAddArgParser(false)
|
||||
return cli.NewCommandDocumentation(addDocs, ap)
|
||||
}
|
||||
|
||||
func (cmd AddCmd) ArgParser() *argparser.ArgParser {
|
||||
return cli.CreateAddArgParser()
|
||||
return cli.CreateAddArgParser(false)
|
||||
}
|
||||
|
||||
// generateAddSql returns the query that will call the `DOLT_ADD` stored proceudre.
|
||||
@@ -111,7 +111,7 @@ func generateAddSql(apr *argparser.ArgParseResults) string {
|
||||
|
||||
// Exec executes the command
|
||||
func (cmd AddCmd) Exec(ctx context.Context, commandStr string, args []string, _ *env.DoltEnv, cliCtx cli.CliContext) int {
|
||||
ap := cli.CreateAddArgParser()
|
||||
ap := cli.CreateAddArgParser(false)
|
||||
|
||||
// This flag is only supported in a CLI context, not the in the dolt procedure.
|
||||
ap.SupportsFlag(cli.PatchFlag, "p", "Interactively select changes to add to the staged set.")
|
||||
|
||||
@@ -48,22 +48,28 @@ func doDoltAdd(ctx *sql.Context, args []string) (int, error) {
|
||||
return 1, err
|
||||
}
|
||||
|
||||
apr, err := cli.CreateAddArgParser().Parse(args)
|
||||
apr, err := cli.CreateAddArgParser(true).Parse(args)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
}
|
||||
|
||||
targetBranch, branchSpecified := apr.GetValue(cli.BranchParam)
|
||||
if branchSpecified {
|
||||
// Use revision-qualified database name for the target branch. This will enable you to add
|
||||
// to branches other than the current branch.
|
||||
dbName = fmt.Sprintf("%s/%s", dbName, targetBranch)
|
||||
}
|
||||
|
||||
allFlag := apr.Contains(cli.AllFlag)
|
||||
|
||||
dSess := dsess.DSessFromSess(ctx.Session)
|
||||
roots, ok := dSess.GetRoots(ctx, dbName)
|
||||
if !ok {
|
||||
return 1, fmt.Errorf("Could not load database %s", dbName)
|
||||
}
|
||||
if apr.NArg() == 0 && !allFlag {
|
||||
return 1, fmt.Errorf("Nothing specified, nothing added. Maybe you wanted to say 'dolt add .'?")
|
||||
} else if allFlag || apr.NArg() == 1 && apr.Arg(0) == "." {
|
||||
if !ok {
|
||||
return 1, fmt.Errorf("db session not found")
|
||||
}
|
||||
|
||||
roots, err = actions.StageAllTables(ctx, roots, !apr.Contains(cli.ForceFlag))
|
||||
if err != nil {
|
||||
return 1, err
|
||||
|
||||
Reference in New Issue
Block a user