This commit is contained in:
Zach Musgrave
2024-05-24 14:26:42 -07:00
parent a72ae35310
commit ce0eb4b2d2
2 changed files with 40 additions and 22 deletions

View File

@@ -96,9 +96,10 @@ func doDoltAdd(ctx *sql.Context, args []string) (int, error) {
// doesn't belong in Dolt, but because we resolve table names out of band at execution time like this, we don't
// have much of a choice.
unqualifiedTableNames := apr.Args
tableNames := make([]doltdb.TableName, len(unqualifiedTableNames))
var missingTables []string
var tableNames []doltdb.TableName
if resolve.UseSearchPath {
var missingTables []string
tableNames = make([]doltdb.TableName, len(unqualifiedTableNames))
for i, name := range unqualifiedTableNames {
tblName, _, ok, err := resolve.TableWithSearchPath(ctx, roots.Working, name)
if err != nil {
@@ -117,7 +118,7 @@ func doDoltAdd(ctx *sql.Context, args []string) (int, error) {
return 1, actions.NewTblNotExistError(missingTables)
}
} else {
doltdb.ToTableNames(unqualifiedTableNames, doltdb.DefaultSchemaName)
tableNames = doltdb.ToTableNames(unqualifiedTableNames, doltdb.DefaultSchemaName)
}
roots, err = actions.StageTables(ctx, roots, tableNames, !apr.Contains(cli.ForceFlag))

View File

@@ -148,32 +148,49 @@ func TestSingleScript(t *testing.T) {
var scripts = []queries.ScriptTest{
{
Name: "table changes - commit history",
Name: "test hashof",
SetUpScript: []string{
"create table modifiedTable (a int primary key, b int);",
"insert into modifiedTable values (1, 2), (2, 3);",
"create table droppedTable (a int primary key, b int);",
"insert into droppedTable values (1, 2), (2, 3);",
"create table renamedTable (a int primary key, b int);",
"call dolt_add('.')",
"call dolt_commit('-am', 'creating tables');",
"update modifiedTable set b = 5 where a = 1;",
"drop table droppedTable;",
"rename table renamedTable to newRenamedTable;",
"create table addedTable (a int primary key, b int);",
"call dolt_add('.')",
"call dolt_commit('-am', 'make table changes');",
"CREATE TABLE hashof_test (pk int primary key, c1 int)",
"INSERT INTO hashof_test values (1,1), (2,2), (3,3)",
"CALL DOLT_ADD('hashof_test')",
"CALL DOLT_COMMIT('-a', '-m', 'first commit')",
"SET @Commit1 = (SELECT commit_hash FROM DOLT_LOG() LIMIT 1)",
"INSERT INTO hashof_test values (4,4), (5,5), (6,6)",
"CALL DOLT_COMMIT('-a', '-m', 'second commit')",
"SET @Commit2 = (SELECT commit_hash from DOLT_LOG() LIMIT 1)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT table_name, column_name, diff_type FROM DOLT_COLUMN_DIFF WHERE table_name = 'modifiedTable';",
Query: "SELECT (hashof(@Commit1) = hashof(@Commit2))",
Expected: []sql.Row{{false}},
},
{
Query: "SELECT (hashof(@Commit1) = hashof('HEAD~1'))",
Expected: []sql.Row{
{"modifiedTable", "a", "added"},
{"modifiedTable", "b", "added"},
{"modifiedTable", "b", "modified"},
{true},
},
},
{
Query: "SELECT (hashof(@Commit2) = hashof('HEAD'))",
Expected: []sql.Row{
{true},
},
},
{
Query: "SELECT (hashof(@Commit2) = hashof('main'))",
Expected: []sql.Row{
{true},
},
},
{
Query: "SELECT hashof('non_branch')",
ExpectedErrStr: "invalid ref spec",
},
{
// Test that a short commit is invalid. This may change in the future.
Query: "SELECT hashof(left(@Commit2,30))",
ExpectedErrStr: "invalid ref spec",
},
},
},
}