From 612774bb0d1ef06e89e2514826f51d4146df92d1 Mon Sep 17 00:00:00 2001 From: James Cor Date: Fri, 24 May 2024 12:00:14 -0700 Subject: [PATCH] Properly add database collation change when using `-a` option in `dolt commit` (#7899) --- go/libraries/doltcore/env/actions/staged.go | 6 +++++- go/libraries/doltcore/sqle/dprocedures/dolt_add.go | 4 ++-- .../doltcore/sqle/dprocedures/dolt_commit.go | 6 +++++- integration-tests/bats/commit.bats | 13 +++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/go/libraries/doltcore/env/actions/staged.go b/go/libraries/doltcore/env/actions/staged.go index 62ed3d64df..42ca278149 100644 --- a/go/libraries/doltcore/env/actions/staged.go +++ b/go/libraries/doltcore/env/actions/staged.go @@ -16,6 +16,7 @@ package actions import ( "context" + "strings" "github.com/dolthub/dolt/go/libraries/doltcore/diff" "github.com/dolthub/dolt/go/libraries/doltcore/doltdb" @@ -46,7 +47,7 @@ func StageAllTables(ctx context.Context, roots doltdb.Roots, filterIgnoredTables return StageTables(ctx, roots, tbls, filterIgnoredTables) } -func StageDatabase(ctx context.Context, roots doltdb.Roots, filterIgnoredTables bool) (doltdb.Roots, error) { +func StageDatabase(ctx context.Context, roots doltdb.Roots) (doltdb.Roots, error) { wColl, err := roots.Working.GetCollation(ctx) if err != nil { return doltdb.Roots{}, err @@ -73,6 +74,9 @@ func StageModifiedAndDeletedTables(ctx context.Context, roots doltdb.Roots) (dol var tbls []string for _, tableDelta := range unstaged { + if strings.HasPrefix(tableDelta.FromName, diff.DBPrefix) { + continue + } if !tableDelta.IsAdd() { tbls = append(tbls, tableDelta.FromName) } diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_add.go b/go/libraries/doltcore/sqle/dprocedures/dolt_add.go index 3381aba436..090cc4feaf 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_add.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_add.go @@ -67,7 +67,7 @@ func doDoltAdd(ctx *sql.Context, args []string) (int, error) { return 1, err } - roots, err = actions.StageDatabase(ctx, roots, !apr.Contains(cli.ForceFlag)) + roots, err = actions.StageDatabase(ctx, roots) if err != nil { return 1, err } @@ -84,7 +84,7 @@ func doDoltAdd(ctx *sql.Context, args []string) (int, error) { } // remove from slice apr.Args = append(apr.Args[:i], apr.Args[i+1:]...) - roots, err = actions.StageDatabase(ctx, roots, !apr.Contains(cli.ForceFlag)) + roots, err = actions.StageDatabase(ctx, roots) if err != nil { return 1, err } diff --git a/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go b/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go index e38402a20b..b07ce1c6cc 100644 --- a/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go +++ b/go/libraries/doltcore/sqle/dprocedures/dolt_commit.go @@ -86,7 +86,7 @@ func doDoltCommit(ctx *sql.Context, args []string) (string, bool, error) { if err != nil { return "", false, fmt.Errorf(err.Error()) } - roots, err = actions.StageDatabase(ctx, roots, true) + roots, err = actions.StageDatabase(ctx, roots) if err != nil { return "", false, fmt.Errorf(err.Error()) } @@ -95,6 +95,10 @@ func doDoltCommit(ctx *sql.Context, args []string) (string, bool, error) { if err != nil { return "", false, fmt.Errorf(err.Error()) } + roots, err = actions.StageDatabase(ctx, roots) + if err != nil { + return "", false, fmt.Errorf(err.Error()) + } } var name, email string diff --git a/integration-tests/bats/commit.bats b/integration-tests/bats/commit.bats index 262fc3dda6..03fc78b0a0 100644 --- a/integration-tests/bats/commit.bats +++ b/integration-tests/bats/commit.bats @@ -63,6 +63,19 @@ teardown() { [[ "$output" =~ "| 1" ]] || false } +@test "commit: --all (-a) adds changed database collation" { + dolt sql -q "create database colldb" + cd colldb + + dolt sql -q "alter database colldb collate utf8mb4_spanish_ci" + dolt commit -a -m "collation" + + run dolt status + [ $status -eq 0 ] + [[ "$output" =~ "On branch main" ]] || false + [[ "$output" =~ "nothing to commit, working tree clean" ]] || false +} + @test "commit: -m sets commit message properly" { dolt sql -q "CREATE table t1 (pk int primary key);" dolt add t1