Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added disclaimer for branch checkout #8957

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions go/libraries/doltcore/sqle/dprocedures/dolt_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ package dprocedures
import (
"errors"
"fmt"

"os"
"strings"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"

"github.com/fatih/color"
"github.com/dolthub/dolt/go/cmd/dolt/cli"
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
Expand All @@ -34,6 +35,7 @@ import (
)

var ErrEmptyBranchName = errors.New("error: cannot checkout empty string")
var os_args=os.Args[1:]

var doltCheckoutSchema = []*sql.Column{
{
Expand Down Expand Up @@ -176,6 +178,10 @@ func doDoltCheckout(ctx *sql.Context, args []string) (statusCode int, successMes
if err != nil {
return 1, "", err
}
terminal_command:=strings.Join(os_args, " ")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to be a bit more clever here. I think we need to check and make sure that call dolt_checkout() with the -b option is the only sql statement being run.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timsehn
Okay but what if the user calls the command like dolt sql --q "call dolt_checkout('myBranch2');" i.e. without the -b option.
I believe this also needs to be handled.

if strings.Contains(terminal_command, "sql") {
cli.PrintErrln(color.YellowString("WARNING: The checked out branch is only changed for this current session."))
}
return 0, generateSuccessMessage(branchName, ""), nil
}

Expand Down
Loading