Better tests & documentatioin & working stash reference

This commit is contained in:
Nathan Gabrielson
2025-06-06 17:52:34 -07:00
parent 406812d1e0
commit f2bb0baf71
10 changed files with 656 additions and 817 deletions
+1 -1
View File
@@ -77,7 +77,7 @@ func (cmd StashClearCmd) Exec(ctx context.Context, commandStr string, args []str
return 1
}
err := dEnv.DoltDB(ctx).RemoveAllStashes(ctx, "dolt-cli")
err := dEnv.DoltDB(ctx).RemoveAllStashes(ctx, DoltCliRef)
if err != nil {
return commands.HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
}
+2 -2
View File
@@ -95,12 +95,12 @@ func (cmd StashDropCmd) Exec(ctx context.Context, commandStr string, args []stri
}
func dropStashAtIdx(ctx context.Context, dEnv *env.DoltEnv, idx int) error {
stashHash, err := dEnv.DoltDB(ctx).GetStashHashAtIdx(ctx, idx, "dolt-cli")
stashHash, err := dEnv.DoltDB(ctx).GetStashHashAtIdx(ctx, idx, DoltCliRef)
if err != nil {
return err
}
err = dEnv.DoltDB(ctx).RemoveStashAtIdx(ctx, idx, "dolt-cli")
err = dEnv.DoltDB(ctx).RemoveStashAtIdx(ctx, idx, DoltCliRef)
if err != nil {
return err
}
+1 -1
View File
@@ -125,7 +125,7 @@ func (cmd StashPopCmd) Exec(ctx context.Context, commandStr string, args []strin
}
func applyStashAtIdx(ctx *sql.Context, dEnv *env.DoltEnv, curWorkingRoot doltdb.RootValue, idx int) (bool, error) {
stashRoot, headCommit, meta, err := dEnv.DoltDB(ctx).GetStashRootAndHeadCommitAtIdx(ctx, idx, "dolt-cli")
stashRoot, headCommit, meta, err := dEnv.DoltDB(ctx).GetStashRootAndHeadCommitAtIdx(ctx, idx, DoltCliRef)
if err != nil {
return false, err
}
+2 -1
View File
@@ -42,6 +42,7 @@ var StashCommands = cli.NewSubCommandHandlerWithUnspecified("stash", "Stash the
const (
IncludeUntrackedFlag = "include-untracked"
AllFlag = "all"
DoltCliRef = "dolt-cli"
)
var stashDocs = cli.CommandDocumentationContent{
@@ -242,7 +243,7 @@ func stashChanges(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
return err
}
err = dEnv.DoltDB(ctx).AddStash(ctx, commit, roots.Staged, datas.NewStashMeta(curBranchName, commitMeta.Description, doltdb.FlattenTableNames(addedTblsToStage)), "dolt-cli")
err = dEnv.DoltDB(ctx).AddStash(ctx, commit, roots.Staged, datas.NewStashMeta(curBranchName, commitMeta.Description, doltdb.FlattenTableNames(addedTblsToStage)), DoltCliRef)
if err != nil {
return err
}
+3 -2
View File
@@ -2213,11 +2213,12 @@ func (ddb *DoltDB) GetStashes(ctx context.Context) ([]*Stash, error) {
}
var stashList []*Stash
for _, stash := range stashRefs {
stashDS, err := ddb.db.GetDataset(ctx, ref.NewStashRef(stash.String()).String())
reference := ref.NewStashRef(stash.String()).String()
stashDS, err := ddb.db.GetDataset(ctx, reference)
if err != nil {
return nil, err
}
newStashes, err := getStashList(ctx, stashDS, ddb.vrw, ddb.NodeStore())
newStashes, err := getStashList(ctx, stashDS, ddb.vrw, ddb.NodeStore(), reference)
if err != nil {
return nil, err
}
+7 -5
View File
@@ -26,14 +26,15 @@ import (
)
type Stash struct {
Name string
BranchName string
Description string
HeadCommit *Commit
Name string
BranchName string
Description string
HeadCommit *Commit
StashReference string
}
// getStashList returns array of Stash objects containing all stash entries in the stash list map.
func getStashList(ctx context.Context, ds datas.Dataset, vrw types.ValueReadWriter, ns tree.NodeStore) ([]*Stash, error) {
func getStashList(ctx context.Context, ds datas.Dataset, vrw types.ValueReadWriter, ns tree.NodeStore, reference string) ([]*Stash, error) {
v, ok := ds.MaybeHead()
if !ok {
return nil, errors.New("stashes not found")
@@ -75,6 +76,7 @@ func getStashList(ctx context.Context, ds datas.Dataset, vrw types.ValueReadWrit
s.HeadCommit = headCommit
s.BranchName = meta.BranchName
s.Description = meta.Description
s.StashReference = reference
sl[i] = &s
}
@@ -79,21 +79,25 @@ func doDoltStash(ctx *sql.Context, args []string) (string, error) {
}
var status string
cmdName := apr.Arg(0)
stashName := apr.Arg(1)
switch apr.Arg(0) {
idx, err := parseStashIndex(apr)
if err != nil {
return "", err
}
switch cmdName {
case "push":
if apr.NArg() > 2 { // Push does not take extra arguments
return "", fmt.Errorf("error: invalid arguments. Push takes only subcommand and stash name=")
}
status, err = doStashPush(ctx, dSess, dbData, roots, apr, stashName)
case "pop":
idx, err := parseStashIndex(apr.Arg(2))
if err != nil {
return "", err
}
status, err = doStashPop(ctx, dbData, stashName, idx)
case "drop":
idx, err := parseStashIndex(apr.Arg(2))
var idx int
idx, err = parseStashIndex(apr)
if err != nil {
return "", err
}
@@ -104,7 +108,7 @@ func doDoltStash(ctx *sql.Context, args []string) (string, error) {
}
err = doStashClear(ctx, dbData, stashName)
default:
return "", fmt.Errorf("unknown stash subcommand %s", apr.Arg(0))
return "", fmt.Errorf("unknown stash subcommand %s", cmdName)
}
if err != nil {
@@ -151,7 +155,7 @@ func doStashPush(ctx *sql.Context, dSess *dsess.DoltSession, dbData env.DbData[*
return "", err
}
err = dbData.Ddb.AddStash(ctx, commit, roots.Staged, datas.NewStashMeta(curBranchName, commitMeta.Description, doltdb.FlattenTableNames(addedTblsToStage)), apr.Arg(1))
err = dbData.Ddb.AddStash(ctx, commit, roots.Staged, datas.NewStashMeta(curBranchName, commitMeta.Description, doltdb.FlattenTableNames(addedTblsToStage)), stashName)
if err != nil {
return "", err
}
@@ -402,12 +406,18 @@ func updateWorkingSetFromRoots(ctx *sql.Context, dbData env.DbData[*sql.Context]
return nil
}
func parseStashIndex(stashID string) (int, error) {
var idx = 0
stashID = strings.TrimSuffix(strings.TrimPrefix(stashID, "stash@{"), "}")
idx, err := strconv.Atoi(stashID)
if err != nil {
return 0, fmt.Errorf("error: %s is not a valid reference", stashID)
func parseStashIndex(apr *argparser.ArgParseResults) (int, error) {
idx := 0
if apr.NArg() > 2 {
stashID := apr.Arg(2)
var err error
stashID = strings.TrimSuffix(strings.TrimPrefix(stashID, "stash@{"), "}")
idx, err = strconv.Atoi(stashID)
if err != nil {
return 0, fmt.Errorf("error: %s is not a valid reference", stashID)
}
}
return idx, nil
@@ -462,6 +472,8 @@ func updateWorkingRoot(ctx *sql.Context, dbData env.DbData[*sql.Context], newRoo
return nil
}
// gatherCommitData is a helper function that returns the commit and commit metadata associated with the current head
// reference as well as the current branch in the form of a string.
func gatherCommitData(ctx *sql.Context, dbData env.DbData[*sql.Context]) (*doltdb.Commit, *datas.CommitMeta, string, error) {
curHeadRef, err := dbData.Rsr.CWBHeadRef(ctx)
if err != nil {
@@ -30,10 +30,6 @@ import (
const stashesDefaultRowCount = 5
var _ sql.Table = (*StashesTable)(nil)
var _ sql.UpdatableTable = (*StashesTable)(nil)
var _ sql.DeletableTable = (*StashesTable)(nil)
var _ sql.InsertableTable = (*StashesTable)(nil)
var _ sql.ReplaceableTable = (*StashesTable)(nil)
var _ sql.StatisticsTable = (*StashesTable)(nil)
type StashesTable struct {
@@ -94,26 +90,6 @@ func (st *StashesTable) PartitionRows(ctx *sql.Context, part sql.Partition) (sql
return NewStashItr(ctx, st.ddb)
}
func (st *StashesTable) Updater(ctx *sql.Context) sql.RowUpdater {
return stashWriter{st}
}
func (st *StashesTable) Inserter(*sql.Context) sql.RowInserter {
return stashWriter{st}
}
// Deleter returns a RowDeleter for this table. The RowDeleter will get one call to Delete for each row to be deleted,
// and will end with a call to Close() to finalize the delete operation.
func (st *StashesTable) Deleter(*sql.Context) sql.RowDeleter {
return stashWriter{st}
}
// Replacer returns a RowReplacer for this table. The RowReplacer will have Insert and optionally Delete called once
// for each row, followed by a call to Close() when all rows have been processed.
func (st *StashesTable) Replacer(ctx *sql.Context) sql.RowReplacer {
return stashWriter{st}
}
type StashItr struct {
stashes []*doltdb.Stash
idx int
@@ -157,7 +133,7 @@ func (itr *StashItr) Next(ctx *sql.Context) (sql.Row, error) {
if err != nil {
return nil, err
}
return sql.NewRow("stashes/stashes", stash.Name, stash.BranchName, commitHash.String(), stash.Description), nil
return sql.NewRow(stash.StashReference, stash.Name, stash.BranchName, commitHash.String(), stash.Description), nil
}
// Close closes the iterator.
@@ -8142,769 +8142,3 @@ end;
},
},
}
var DoltStashTests = []queries.ScriptTest{
{
Name: "DOLT_STASH() subcommands error on empty space.",
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
ExpectedErrStr: "no local changes to save",
},
{
Query: "CREATE TABLE test (i int)",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
ExpectedErrStr: "no local changes to save",
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "No stash entries found.",
},
{
Query: "CALL DOLT_STASH('drop', 'myStash');",
ExpectedErrStr: "No stash entries found.",
},
{
Query: "CALL DOLT_STASH('clear','myStash');",
Expected: []sql.Row{},
},
},
},
{
Name: "Simple push and pop with DOLT_STASH()",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "SELECT * FROM test",
Expected: []sql.Row{{1, 'a'}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES",
Expected: []sql.Row{},
},
},
},
{
Name: "Clearing stash removes all entries in stash list",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a')",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b')",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'anotherStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (3, 'c')",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'anotherStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_stashes;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
{"stashes/anotherStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
{"stashes/anotherStash", "stash@{1}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('clear', 'anotherStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_stashes;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Clearing and stashing again",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('clear', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Popping specific stashes",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (3, 'c');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
}, {
Query: "INSERT INTO test VALUES (4, 'd');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_STASH('pop', 'myStash', 'stash@{3}')",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_STASH('pop', 'myStash', 'stash@{1}');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM test",
Expected: []sql.Row{
{1, 'a'},
{4, 'd'},
},
},
},
},
{
Name: "Stashing on different branches",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'br1');",
Expected: []sql.Row{{0, "Switched to branch 'br1'"}},
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/br1", doltCommit, "Created table"},
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Popping stash onto different branch",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES();",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'br1');",
Expected: []sql.Row{{0, "Switched to branch 'br1'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM TEST;",
Expected: []sql.Row{
{1, 'a'},
},
},
},
},
{
Name: "Can drop specific stash",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_COMMIT('-a', '-m', 'Added 2 b');",
Expected: []sql.Row{{doltCommit}},
},
{
Query: "INSERT INTO test VALUES (3, 'c');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES();",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/br1", doltCommit, "Added 2 b"},
{"stashes/myStash", "stash@{1}", "refs/heads/br1", doltCommit, "Created table"},
},
},
{
Query: "INSERT INTO test VALUES (4, 'd');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_COMMIT('-a','-m', 'Added 4 d');",
Expected: []sql.Row{{doltCommit}},
},
{
Query: "INSERT INTO test VALUES (5, 'c');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_STASH('drop', 'myStash', 'stash@{1}');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES();",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/br1", doltCommit, "Added 4 d"},
{"stashes/myStash", "stash@{1}", "refs/heads/br1", doltCommit, "Created table"},
},
},
},
},
{
Name: "Can pop into dirty working set without conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM test",
Expected: []sql.Row{
{1, 'a'},
{2, 'b'},
},
},
},
},
{
Name: "Can't pop into dirty working set with conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (1, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "error: Your local changes to the following tables would be overwritten by applying stash 0:\n\t{'test'}\n" +
"Please commit your changes or stash them before you merge.\nAborting\n",
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/br1", doltCommit, "Created table"},
},
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{
{1, 'a'},
},
},
},
},
{
Name: "Can stash modified staged and working set of changes",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_ADD('.')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"t", true, "modified"},
{"t", false, "modified"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"t", false, "modified"},
{"t", false, "modified"},
},
},
},
},
{
Name: "Can use --all and --include-untracked on push",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CREATE TABLE new(id int primary key)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", true, "new table"},
{"new", false, "new table"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash', '--include-untracked');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{
{"test", true, "new table"},
{"new", false, "new table"},
},
},
},
},
{
Name: "Stash with tracked and untracked tables",
SetUpScript: []string{
"CREATE TABLE new(i INT PRIMARY KEY)",
"CALL DOLT_ADD('.')",
"INSERT INTO new VALUES (1),(2)",
"CREATE TABLE test(id INT)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"new", true, "new table"},
{"test", false, "new table"},
{"new", false, "modified"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", false, "new table"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"new", true, "new table"},
{"test", false, "new table"},
},
},
},
},
{
Name: "stashing working set with deleted table and popping it",
SetUpScript: []string{
"CREATE TABLE new_tab(id INT PRIMARY KEY)",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-A', '-m', 'Created table')",
"DROP TABLE new_tab",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STATUS;",
Expected: []sql.Row{
{"new_tab", false, "deleted"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SHOW TABLES;",
Expected: []sql.Row{
{"new_tab"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SHOW TABLES;",
Expected: []sql.Row{},
},
},
},
{
Name: "simple stashing and popping stash after running GC",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{
{1, 'a'},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_GC();",
Expected: []sql.Row{{1}},
},
{
Query: "SELECT * FROM DOLT_STASHES",
Expected: []sql.Row{
{"stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
Expected: []sql.Row{},
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{
{1, 'a'},
{2, 'b'},
},
},
},
},
{
Name: "popping stash with deleted table that is deleted already on current head",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1');",
"CALL DOLT_CHECKOUT('-b', 'branch2');",
"DROP TABLE test;",
"CALL DOLT_COMMIT('A','-m','Dropped test');",
"CALL DOLT_CHECKOUT('branch1');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SHOW TABLES;",
Expected: []sql.Row{
{"test"},
},
},
{
Query: "DROP TABLE test;",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
},
},
{
Name: "popping stash with deleted table that the same table exists on current head",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1');",
"CALL DOLT_BRANCH('branch2');",
"CALL DOLT_CHECKOUT('branch1');",
"DROP TABLE test;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", false, "deleted"},
},
},
},
},
{
Name: "popping stash with deleted table that different table with same name on current head gives conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1')",
"CALL DOLT_BRANCH('branch2')",
"CALL DOLT_CHECKOUT('branch1')",
"DROP TABLE test;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push, 'myStash')",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "DROP TABLE test;",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CREATE TABLE test (id BIGINT PRIMARY KEY);",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "merge aborted: schema conflict found for table t\n " +
"please resolve schema conflicts before merging:\n" +
"\ttable was modified in one branch and deleted in the other",
},
},
},
{
Name: "popping stash with added table with PK on current head with the exact same table is added already",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1')",
"CALL DOLT_CHECKOUT('-b', 'branch2')",
"CREATE TABLE new_test(id INT PRIMARY KEY)",
"INSERT INTO new_test VALUES (1)",
"CALL DOLT_COMMIT('-A', '-m', 'Created new_test')",
"CALL DOLT_CHECKOUT('branch1')",
"CREATE TABLE new_test(id INT PRIMARY KEY)",
"INSERT INTO new_test VALUES (1)",
"CALL DOLT_ADD('.')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
},
},
}
@@ -0,0 +1,613 @@
// Copyright 2025 Dolthub, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package enginetest
import (
"github.com/dolthub/go-mysql-server/enginetest/queries"
"github.com/dolthub/go-mysql-server/sql"
"github.com/dolthub/go-mysql-server/sql/types"
)
var DoltStashTests = []queries.ScriptTest{
{
Name: "DOLT_STASH() subcommands error on empty space.",
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
ExpectedErrStr: "no local changes to save",
},
{
Query: "CREATE TABLE test (i int)",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
ExpectedErrStr: "no local changes to save",
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "No stash entries found.",
},
{
Query: "CALL DOLT_STASH('drop', 'myStash');",
ExpectedErrStr: "No stash entries found.",
},
{
Query: "CALL DOLT_STASH('clear','myStash');",
Expected: []sql.Row{{""}},
},
},
},
{
Name: "Simple push and pop with DOLT_STASH()",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES",
Expected: []sql.Row{},
},
},
},
{
Name: "Clearing stash removes all entries in stash list",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'stash1')",
"INSERT INTO test VALUES (2, 'b')",
"CALL DOLT_STASH('push', 'stash2')",
" INSERT INTO test VALUES (3, 'c')",
"CALL DOLT_STASH('push', 'stash2')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM dolt_stashes;",
Expected: []sql.Row{
{"refs/stashes/stash1", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
{"refs/stashes/stash2", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
{"refs/stashes/stash2", "stash@{1}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('clear', 'stash2');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_stashes;",
Expected: []sql.Row{
{"refs/stashes/stash1", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Clearing and stashing again",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('clear', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Popping specific stashes",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (2, 'b')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (3, 'c')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (4, 'd')",
"CALL DOLT_STASH('push', 'myStash')",
"CALL DOLT_STASH('pop', 'myStash', 'stash@{3}')",
"CALL DOLT_STASH('pop', 'myStash', 'stash@{1}')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM test",
Expected: []sql.Row{
{1, "a"},
{3, "c"},
},
},
},
},
{
Name: "Stashing on different branches",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "INSERT INTO test VALUES (1, 'a');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('-b', 'br1');",
Expected: []sql.Row{{0, "Switched to branch 'br1'"}},
},
{
Query: "INSERT INTO test VALUES (2, 'b');",
Expected: []sql.Row{{types.NewOkResult(1)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/br1", doltCommit, "Created table"},
{"refs/stashes/myStash", "stash@{1}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Popping stash onto different branch",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
"CALL DOLT_CHECKOUT('-b', 'br1')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM TEST;",
Expected: []sql.Row{
{1, "a"},
},
},
},
},
{
Name: "Can drop specific stash",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (2, 'b')",
"CALL DOLT_COMMIT('-a', '-m', 'Added 2 b')",
"INSERT INTO test VALUES (3, 'c')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (4, 'd')",
"CALL DOLT_COMMIT('-a','-m', 'Added 4 d')",
"INSERT INTO test VALUES (5, 'c')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Added 2 b"},
{"refs/stashes/myStash", "stash@{1}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_STASH('drop', 'myStash', 'stash@{1}');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Added 4 d"},
{"refs/stashes/myStash", "stash@{1}", "refs/heads/main", doltCommit, "Created table"},
},
},
},
},
{
Name: "Can pop into dirty working set without conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (2, 'b')",
"CALL DOLT_STASH('pop', 'myStash')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM test",
Expected: []sql.Row{
{1, "a"},
{2, "b"},
},
},
},
},
{
Name: "Can't pop into dirty working set with conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_STASH('push', 'myStash')",
"INSERT INTO test VALUES (1, 'b')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "error: Your local changes to the following tables would be overwritten by applying stash 0:\n\t{'test'}\n" +
"Please commit your changes or stash them before you merge.\nAborting\n",
},
{
Query: "SELECT * FROM DOLT_STASHES;",
Expected: []sql.Row{
{"refs/stashes/myStash", "stash@{0}", "refs/heads/main", doltCommit, "Created table"},
},
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{
{1, "b"},
},
},
},
},
{
Name: "Can stash modified staged and working set of changes",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"INSERT INTO test VALUES (1, 'a')",
"CALL DOLT_ADD('.')",
"INSERT INTO test VALUES (2, 'b')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", true, "modified"},
{"test", false, "modified"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM test;",
Expected: []sql.Row{},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"test", false, "modified"},
},
},
},
},
{
Name: "Can use --include-untracked on push",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CREATE TABLE new(id int primary key)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", true, "new table"},
{"new", false, "new table"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash', '--include-untracked');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM dolt_status;",
Expected: []sql.Row{
{"test", true, "new table"},
{"new", false, "new table"},
},
},
},
},
{
Name: "Stash with tracked and untracked tables",
SetUpScript: []string{
"CREATE TABLE new(i INT PRIMARY KEY)",
"CALL DOLT_ADD('.')",
"INSERT INTO new VALUES (1),(2)",
"CREATE TABLE test(id INT)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"new", true, "new table"},
{"test", false, "new table"},
{"new", false, "modified"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash')",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", false, "new table"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"new", true, "new table"},
{"test", false, "new table"},
},
},
},
},
{
Name: "stashing working set with deleted table and popping it",
SetUpScript: []string{
"CREATE TABLE new_tab(id INT PRIMARY KEY)",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-A', '-m', 'Created table')",
"DROP TABLE new_tab",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SELECT * FROM DOLT_STATUS;",
Expected: []sql.Row{
{"new_tab", false, "deleted"},
},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SHOW TABLES;",
Expected: []sql.Row{
{"new_tab"},
},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SHOW TABLES;",
Expected: []sql.Row{},
},
},
},
{
Name: "popping stash with deleted table that is deleted already on current head",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1');",
"CALL DOLT_CHECKOUT('-b', 'branch2');",
"DROP TABLE test;",
"CALL DOLT_COMMIT('-A','-m','Dropped test');",
"CALL DOLT_CHECKOUT('branch1');",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SHOW TABLES;",
Expected: []sql.Row{
{"test"},
},
},
{
Query: "DROP TABLE test;",
Expected: []sql.Row{{types.NewOkResult(0)}},
},
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
},
},
{
Name: "popping stash with deleted table that the same table exists on current head",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1');",
"CALL DOLT_BRANCH('branch2');",
"CALL DOLT_CHECKOUT('branch1');",
"DROP TABLE test;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{
{"test", false, "deleted"},
},
},
},
},
{
Name: "popping stash with deleted table that different table with same name on current head gives conflict",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1')",
"CALL DOLT_BRANCH('branch2')",
"CALL DOLT_CHECKOUT('branch1')",
"DROP TABLE test",
"CALL DOLT_STASH('push', 'myStash')",
"CALL DOLT_CHECKOUT('branch2')",
"DROP TABLE test",
"CREATE TABLE test (id BIGINT PRIMARY KEY)",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
ExpectedErrStr: "merge aborted: schema conflict found for table test \n " +
"please resolve schema conflicts before merging: \n" +
"\ttable was modified in one branch and deleted in the other",
},
},
},
{
Name: "popping stash with added table with PK on current head with the exact same table is added already",
SetUpScript: []string{
"CREATE TABLE test(pk BIGINT PRIMARY KEY, v varchar(10))",
"CALL DOLT_ADD('.')",
"CALL DOLT_COMMIT('-m', 'Created table')",
"CALL DOLT_BRANCH('branch1')",
"CALL DOLT_CHECKOUT('-b', 'branch2')",
"CREATE TABLE new_test(id INT PRIMARY KEY)",
"INSERT INTO new_test VALUES (1)",
"CALL DOLT_COMMIT('-A', '-m', 'Created new_test')",
"CALL DOLT_CHECKOUT('branch1')",
"CREATE TABLE new_test(id INT PRIMARY KEY)",
"INSERT INTO new_test VALUES (1)",
"CALL DOLT_ADD('.')",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "CALL DOLT_STASH('push', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "CALL DOLT_CHECKOUT('branch2');",
Expected: []sql.Row{{0, "Switched to branch 'branch2'"}},
},
{
Query: "CALL DOLT_STASH('pop', 'myStash');",
SkipResultsCheck: true,
},
{
Query: "SELECT * FROM DOLT_STATUS",
Expected: []sql.Row{},
},
},
},
}