Properly add database collation change when using -a option in dolt commit (#7899)

This commit is contained in:
James Cor
2024-05-24 12:00:14 -07:00
committed by GitHub
parent a4c2561dd8
commit 612774bb0d
4 changed files with 25 additions and 4 deletions

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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

View File

@@ -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