Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into spelling-3p
Browse files Browse the repository at this point in the history
  • Loading branch information
macneale4 committed Aug 21, 2024
2 parents e2d6b67 + 9785565 commit 34bd5c0
Show file tree
Hide file tree
Showing 78 changed files with 3,515 additions and 584 deletions.
6 changes: 5 additions & 1 deletion go/cmd/dolt/cli/arg_parser_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,11 @@ func CreateMergeArgParser() *argparser.ArgParser {
}

func CreateRebaseArgParser() *argparser.ArgParser {
ap := argparser.NewArgParserWithMaxArgs("merge", 1)
ap := argparser.NewArgParserWithMaxArgs("rebase", 1)
ap.TooManyArgsErrorFunc = func(receivedArgs []string) error {
return errors.New("rebase takes at most one positional argument.")
}
ap.SupportsString(EmptyParam, "", "empty", "How to handle commits that are not empty to start, but which become empty after rebasing. Valid values are: drop (default) or keep")
ap.SupportsFlag(AbortParam, "", "Abort an interactive rebase and return the working set to the pre-rebase state")
ap.SupportsFlag(ContinueFlag, "", "Continue an interactive rebase after adjusting the rebase plan")
ap.SupportsFlag(InteractiveFlag, "i", "Start an interactive rebase")
Expand Down Expand Up @@ -172,6 +173,9 @@ func CreateCheckoutArgParser() *argparser.ArgParser {
func CreateCherryPickArgParser() *argparser.ArgParser {
ap := argparser.NewArgParserWithMaxArgs("cherrypick", 1)
ap.SupportsFlag(AbortParam, "", "Abort the current conflict resolution process, and revert all changes from the in-process cherry-pick operation.")
ap.SupportsFlag(AllowEmptyFlag, "", "Allow empty commits to be cherry-picked. "+
"Note that use of this option only keeps commits that were initially empty. "+
"Commits which become empty, due to a previous commit, will cause cherry-pick to fail.")
ap.TooManyArgsErrorFunc = func(receivedArgs []string) error {
return errors.New("cherry-picking multiple commits is not supported yet.")
}
Expand Down
7 changes: 6 additions & 1 deletion go/cmd/dolt/cli/cli_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ import (

// LateBindQueryist is a function that will be called the first time Queryist is needed for use. Input is a context which
// is appropriate for the call to commence. Output is a Queryist, a sql.Context, a closer function, and an error.
// The closer function is called when the Queryist is no longer needed, typically a defer right after getting it.
//
// The closer function is called when the Queryist is no longer needed, typically a defer right after getting it. If a nil
// closer function is returned, then the caller knows that the queryist returned is being managed by another command. Effectively
// this means you are running in another command's session. This is particularly interesting when running a \checkout in a
// dolt sql session. It makes sense to do so in the context of `dolt sql`, but not in the context of `dolt checkout` when
// connected to a remote server.
type LateBindQueryist func(ctx context.Context) (Queryist, *sql.Context, func(), error)

// CliContexct is used to pass top level command information down to subcommands.
Expand Down
1 change: 1 addition & 0 deletions go/cmd/dolt/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
DeleteForceFlag = "D"
DepthFlag = "depth"
DryRunFlag = "dry-run"
EmptyParam = "empty"
ForceFlag = "force"
GraphFlag = "graph"
HardResetParam = "hard"
Expand Down
2 changes: 1 addition & 1 deletion go/cmd/dolt/cli/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ package cli
const (
// Single variable - the name of the command. `dolt <command>` is how the commandString is formatted in calls to the Exec method
// for dolt commands.
RemoteUnsupportedMsg = "%s can not currently be used when there is a local server running. Please stop your dolt sql-server and try again."
RemoteUnsupportedMsg = "%s can not currently be used when there is a local server running. Please stop your dolt sql-server or connect using `dolt sql` instead."
)
22 changes: 12 additions & 10 deletions go/cmd/dolt/commands/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,17 @@ func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []strin
}
if closeFunc != nil {
defer closeFunc()
}

_, ok := queryEngine.(*engine.SqlEngine)
if !ok {
// Currently checkout does not fully support remote connections. Prevent them from being used until we have better
// CLI session support.
msg := fmt.Sprintf(cli.RemoteUnsupportedMsg, commandStr)
cli.Println(msg)
return 1
// We only check for this case when checkout is the first command in a session. The reason for this is that checkout
// when connected to a remote server will not work as it won't set the branch. But when operating within the context
// of another session, specifically a \checkout in a dolt sql session, this makes sense. Since no closeFunc would be
// returned, we don't need to check for this case.
_, ok := queryEngine.(*engine.SqlEngine)
if !ok {
msg := fmt.Sprintf(cli.RemoteUnsupportedMsg, commandStr)
cli.Println(msg)
return 1
}
}

// Argument validation in the CLI is strictly nice to have. The stored procedure will do the same, but the errors
Expand Down Expand Up @@ -165,8 +167,8 @@ func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []strin
return HandleVErrAndExitCode(errhand.BuildDError("no 'message' field in response from %s", sqlQuery).Build(), usage)
}

var message string
if message, ok = rows[0][1].(string); !ok {
message, ok := rows[0][1].(string)
if !ok {
return HandleVErrAndExitCode(errhand.BuildDError("expected string value for 'message' field in response from %s ", sqlQuery).Build(), usage)
}

Expand Down
10 changes: 4 additions & 6 deletions go/cmd/dolt/commands/cherry-pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import (
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/gocraft/dbr/v2"
"github.com/gocraft/dbr/v2/dialect"
"gopkg.in/src-d/go-errors.v1"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
Expand Down Expand Up @@ -122,11 +120,11 @@ func (cmd CherryPickCmd) Exec(ctx context.Context, commandStr string, args []str
return HandleVErrAndExitCode(errhand.BuildDError("cherry-picking multiple commits is not supported yet").SetPrintUsage().Build(), usage)
}

err = cherryPick(queryist, sqlCtx, apr)
err = cherryPick(queryist, sqlCtx, apr, args)
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

func cherryPick(queryist cli.Queryist, sqlCtx *sql.Context, apr *argparser.ArgParseResults) error {
func cherryPick(queryist cli.Queryist, sqlCtx *sql.Context, apr *argparser.ArgParseResults, args []string) error {
cherryStr := apr.Arg(0)
if len(cherryStr) == 0 {
return fmt.Errorf("error: cannot cherry-pick empty string")
Expand Down Expand Up @@ -154,7 +152,7 @@ hint: commit your changes (dolt commit -am \"<message>\") or reset them (dolt re
return fmt.Errorf("error: failed to set @@dolt_force_transaction_commit: %w", err)
}

q, err := dbr.InterpolateForDialect("call dolt_cherry_pick(?)", []interface{}{cherryStr}, dialect.MySQL)
q, err := interpolateStoredProcedureCall("DOLT_CHERRY_PICK", args)
if err != nil {
return fmt.Errorf("error: failed to interpolate query: %w", err)
}
Expand Down Expand Up @@ -200,7 +198,7 @@ hint: commit your changes (dolt commit -am \"<message>\") or reset them (dolt re
if succeeded {
// on success, print the commit info
commit, err := getCommitInfo(queryist, sqlCtx, commitHash)
if err != nil {
if commit == nil || err != nil {
return fmt.Errorf("error: failed to get commit metadata for ref '%s': %v", commitHash, err)
}

Expand Down
3 changes: 3 additions & 0 deletions go/cmd/dolt/commands/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func logCommits(apr *argparser.ArgParseResults, commitHashes []sql.Row, queryist
for _, hash := range commitHashes {
cmHash := hash[0].(string)
commit, err := getCommitInfo(queryist, sqlCtx, cmHash)
if commit == nil {
return fmt.Errorf("no commits found for ref %s", cmHash)
}
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions go/cmd/dolt/commands/log_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ func printOneLineGraph(graph [][]string, pager *outputpager.Pager, apr *argparse
pager.Writer.Write([]byte("\n"))
}

pager.Writer.Write([]byte(fmt.Sprintf("%s %s ", strings.Join(graph[commits[i].Row], ""), color.YellowString("commit%s ", commits[i].Commit.commitHash))))
pager.Writer.Write([]byte(fmt.Sprintf("%s %s ", strings.Join(graph[commits[i].Row], ""), color.YellowString("commit %s ", commits[i].Commit.commitHash))))
if decoration != "no" {
printRefs(pager, &commits[i].Commit, decoration)
}
Expand Down Expand Up @@ -436,7 +436,7 @@ func printGraphAndCommitsInfo(graph [][]string, pager *outputpager.Pager, apr *a
last_commit_row := commits[len(commits)-1].Row
printCommitMetadata(graph, pager, last_commit_row, len(graph[last_commit_row]), commits[len(commits)-1], decoration)
for _, line := range commits[len(commits)-1].formattedMessage {
pager.Writer.Write([]byte(color.WhiteString("\t", line)))
pager.Writer.Write([]byte(color.WhiteString("\t%s", line)))
pager.Writer.Write([]byte("\n"))
}
}
Expand Down Expand Up @@ -556,7 +556,7 @@ func drawCommitDotsAndBranchPaths(commits []*commitInfoWithChildren, commitsMap
}
for i := col + 1; i < parent.Col-verticalDistance+1; i++ {
if graph[row][i] == " " {
graph[row][i] = branchColor.Sprintf("s-")
graph[row][i] = branchColor.Sprintf("-")
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions go/cmd/dolt/commands/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func (cmd MergeCmd) Exec(ctx context.Context, commandStr string, args []string,
}
if closeFunc != nil {
defer closeFunc()
}

if _, ok := queryist.(*engine.SqlEngine); !ok {
msg := fmt.Sprintf(cli.RemoteUnsupportedMsg, commandStr)
cli.Println(msg)
return 1
if _, ok := queryist.(*engine.SqlEngine); !ok {
msg := fmt.Sprintf(cli.RemoteUnsupportedMsg, commandStr)
cli.Println(msg)
return 1
}
}

ok := validateDoltMergeArgs(apr, usage, cliCtx)
Expand Down
28 changes: 1 addition & 27 deletions go/cmd/dolt/commands/rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"

"github.com/dolthub/go-mysql-server/sql"
"github.com/gocraft/dbr/v2"
"github.com/gocraft/dbr/v2/dialect"

"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
Expand Down Expand Up @@ -102,7 +100,7 @@ func (cmd RebaseCmd) Exec(ctx context.Context, commandStr string, args []string,
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}

query, err := constructInterpolatedDoltRebaseQuery(apr)
query, err := interpolateStoredProcedureCall("DOLT_REBASE", args)
if err != nil {
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
Expand Down Expand Up @@ -181,30 +179,6 @@ func (cmd RebaseCmd) Exec(ctx context.Context, commandStr string, args []string,
return HandleVErrAndExitCode(nil, usage)
}

// constructInterpolatedDoltRebaseQuery generates the sql query necessary to call the DOLT_REBASE() function.
// Also interpolates this query to prevent sql injection.
func constructInterpolatedDoltRebaseQuery(apr *argparser.ArgParseResults) (string, error) {
var params []interface{}
var args []string

if apr.NArg() == 1 {
params = append(params, apr.Arg(0))
args = append(args, "?")
}
if apr.Contains(cli.InteractiveFlag) {
args = append(args, "'--interactive'")
}
if apr.Contains(cli.ContinueFlag) {
args = append(args, "'--continue'")
}
if apr.Contains(cli.AbortParam) {
args = append(args, "'--abort'")
}

query := fmt.Sprintf("CALL DOLT_REBASE(%s);", strings.Join(args, ", "))
return dbr.InterpolateForDialect(query, params, dialect.MySQL)
}

// getRebasePlan opens an editor for users to edit the rebase plan and returns the parsed rebase plan from the editor.
func getRebasePlan(cliCtx cli.CliContext, sqlCtx *sql.Context, queryist cli.Queryist, rebaseBranch, currentBranch string) (*rebase.RebasePlan, error) {
if cli.ExecuteWithStdioRestored == nil {
Expand Down
Loading

0 comments on commit 34bd5c0

Please sign in to comment.