mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-22 19:43:51 -05:00
Changing the default commit author to be the SQL user
This commit is contained in:
@@ -87,26 +87,10 @@ func doDoltCommit(ctx *sql.Context, args []string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
} else {
|
||||
value, err := ctx.GetSessionVariable(ctx, dsess.DoltSqlUserIsCommitter)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
sqlUserIsCommitter, err := types.ConvertToBool(value)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// If @@dolt_sql_user_is_committer is enabled, then we want to use the current SQL user as the commit author,
|
||||
// instead of the `dolt config` configured values. We won't have an email address for the SQL user though, so
|
||||
// instead just use the standard MySQL user@address notation.
|
||||
if sqlUserIsCommitter {
|
||||
name = ctx.Client().User
|
||||
email = fmt.Sprintf("%s@%s", ctx.Client().User, ctx.Client().Address)
|
||||
} else {
|
||||
name = dSess.Username()
|
||||
email = dSess.Email()
|
||||
}
|
||||
// In SQL mode, use the current SQL user as the commit author, instead of the `dolt config` configured values.
|
||||
// We won't have an email address for the SQL user though, so instead use the MySQL user@address notation.
|
||||
name = ctx.Client().User
|
||||
email = fmt.Sprintf("%s@%s", ctx.Client().User, ctx.Client().Address)
|
||||
}
|
||||
|
||||
amend := apr.Contains(cli.AmendFlag)
|
||||
|
||||
@@ -34,7 +34,6 @@ const (
|
||||
// General system variables
|
||||
const (
|
||||
DoltCommitOnTransactionCommit = "dolt_transaction_commit"
|
||||
DoltSqlUserIsCommitter = "dolt_sql_user_is_committer"
|
||||
TransactionsDisabledSysVar = "dolt_transactions_disabled"
|
||||
ForceTransactionCommit = "dolt_force_transaction_commit"
|
||||
CurrentBatchModeKey = "batch_mode"
|
||||
|
||||
@@ -2560,15 +2560,15 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit2, commit_hash = @Commit1, committer, email, message from dolt_log();",
|
||||
Expected: []sql.Row{
|
||||
{true, false, "billy bob", "bigbillieb@fake.horse", "inserting into t"},
|
||||
{false, true, "billy bob", "bigbillieb@fake.horse", "creating table t"},
|
||||
{false, false, "billy bob", "bigbillieb@fake.horse", "checkpoint enginetest database mydb"},
|
||||
{true, false, "root", "root@localhost", "inserting into t"},
|
||||
{false, true, "root", "root@localhost", "creating table t"},
|
||||
{false, false, "root", "root@localhost", "checkpoint enginetest database mydb"},
|
||||
{false, false, "billy bob", "bigbillieb@fake.horse", "Initialize data repository"},
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit2, committer, email, message from dolt_log('main') limit 1;",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit3, committer, email, message from dolt_log('new-branch') limit 1;",
|
||||
@@ -2576,7 +2576,7 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit1, committer, email, message from dolt_log(@Commit1) limit 1;",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "creating table t"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "creating table t"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -2628,7 +2628,7 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, commit_hash = @Commit4, commit_hash = @Commit3, committer, email, message from dolt_log('main...new-branch');",
|
||||
Expected: []sql.Row{
|
||||
{true, false, false, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"},
|
||||
{true, false, false, "root", "root@localhost", "inserting into t 5"},
|
||||
{false, true, false, "John Doe", "johndoe@example.com", "inserting into t 4"},
|
||||
{false, false, true, "John Doe", "johndoe@example.com", "inserting into t 3"},
|
||||
},
|
||||
@@ -2649,7 +2649,7 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^new-branch', 'main');",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * from dolt_log('^main', 'main');",
|
||||
@@ -2657,11 +2657,11 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^main~', 'main');",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log( 'main', '--not', 'main~');",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit3, committer, email, message from dolt_log('^main', @Commit3);",
|
||||
@@ -2673,11 +2673,11 @@ var LogTableFunctionScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log('^new-branch', @Commit5);",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash = @Commit5, committer, email, message from dolt_log(@Commit5, '--not', @Commit4);",
|
||||
Expected: []sql.Row{{true, "billy bob", "bigbillieb@fake.horse", "inserting into t 5"}},
|
||||
Expected: []sql.Row{{true, "root", "root@localhost", "inserting into t 5"}},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -3457,11 +3457,11 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
Expected: []sql.Row{{3}},
|
||||
},
|
||||
{
|
||||
Query: "SELECT * FROM DOLT_DIFF WHERE commit_hash = @Commit1 AND committer <> 'billy bob';",
|
||||
Query: "SELECT * FROM DOLT_DIFF WHERE commit_hash = @Commit1 AND committer <> 'root';",
|
||||
Expected: []sql.Row{},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash, committer FROM DOLT_DIFF WHERE commit_hash <> @Commit1 AND committer = 'billy bob' AND commit_hash NOT IN ('WORKING','STAGED');",
|
||||
Query: "SELECT commit_hash, committer FROM DOLT_DIFF WHERE commit_hash <> @Commit1 AND committer = 'root' AND commit_hash NOT IN ('WORKING','STAGED');",
|
||||
Expected: []sql.Row{},
|
||||
},
|
||||
{
|
||||
@@ -3472,7 +3472,7 @@ var UnscopedDiffSystemTableScriptTests = []queries.ScriptTest{
|
||||
},
|
||||
},
|
||||
{
|
||||
Query: "SELECT commit_hash, table_name FROM DOLT_DIFF WHERE commit_hash <> @Commit1 OR committer <> 'billy bob' ORDER BY table_name;",
|
||||
Query: "SELECT commit_hash, table_name FROM DOLT_DIFF WHERE commit_hash <> @Commit1 OR committer <> 'root' ORDER BY table_name;",
|
||||
Expected: []sql.Row{
|
||||
{"STAGED", "addedTable"},
|
||||
{"STAGED", "droppedTable"},
|
||||
|
||||
@@ -102,14 +102,6 @@ func AddDoltSystemVariables() {
|
||||
Type: types.NewSystemBoolType(dsess.DoltCommitOnTransactionCommit),
|
||||
Default: int8(0),
|
||||
},
|
||||
{ // If true, causes the SQL user to be the author of Dolt commits
|
||||
Name: dsess.DoltSqlUserIsCommitter,
|
||||
Scope: sql.SystemVariableScope_Both,
|
||||
Dynamic: true,
|
||||
SetVarHintApplies: false,
|
||||
Type: types.NewSystemBoolType(dsess.DoltSqlUserIsCommitter),
|
||||
Default: int8(0),
|
||||
},
|
||||
{
|
||||
Name: dsess.TransactionsDisabledSysVar,
|
||||
Scope: sql.SystemVariableScope_Session,
|
||||
|
||||
@@ -240,43 +240,6 @@ teardown() {
|
||||
dolt sql -q "CALL DOLT_COMMIT('-a', '-m', 'updated stuff')"
|
||||
}
|
||||
|
||||
@test "config: DOLT_COMMIT uses default values when user.name or user.email is unset." {
|
||||
dolt config --global --add user.name "bats tester"
|
||||
dolt config --global --add user.email "joshn@doe.com"
|
||||
|
||||
dolt init
|
||||
dolt sql -q "
|
||||
CREATE TABLE test (
|
||||
pk int primary key
|
||||
)"
|
||||
dolt add .
|
||||
|
||||
dolt config --global --unset user.name
|
||||
dolt config --global --unset user.email
|
||||
|
||||
run dolt sql -q "call dolt_commit('-a', '-m', 'created table test')"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt log -n 1
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Dolt System Account" ]] || false
|
||||
[[ "$output" =~ "created table test" ]] || false
|
||||
|
||||
dolt sql -q "create table test2 (pk int primary key)"
|
||||
dolt add .
|
||||
|
||||
dolt config --global --add user.name "bats tester"
|
||||
|
||||
run dolt sql -q "call dolt_commit('-a', '-m', 'created table test2')"
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt log -n 1
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "bats tester" ]] || false
|
||||
[[ "$output" =~ "doltuser@dolthub.com" ]] || false
|
||||
[[ "$output" =~ "created table test2" ]] || false
|
||||
}
|
||||
|
||||
@test "config: Set default init branch" {
|
||||
dolt config --global --add user.name "bats tester"
|
||||
dolt config --global --add user.email "joshn@doe.com"
|
||||
|
||||
@@ -32,27 +32,14 @@ teardown() {
|
||||
done
|
||||
}
|
||||
|
||||
@test "sql-server: committer is sql users when @@dolt_sql_user_is_committer is enabled" {
|
||||
@test "sql-server: committer is sql user" {
|
||||
# Start a SQL-server and add a new user "user1"
|
||||
cd repo1
|
||||
start_sql_server
|
||||
dolt sql-client -P $PORT -u dolt --use-db 'repo1' -q "create user user1@'%';"
|
||||
dolt sql-client -P $PORT -u dolt --use-db 'repo1' -q "grant all privileges on *.* to user1@'%';"
|
||||
|
||||
# By default, commits will be authored by the user running the sql-server (bats@email.fake)
|
||||
dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "create table t1(pk int primary key);"
|
||||
dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "call dolt_commit('-Am', 'committing as bats@email.fake');"
|
||||
run dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "select committer, email, message from dolt_log limit 1;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "| Bats Tests | bats@email.fake | committing as bats@email.fake |" ]] || false
|
||||
|
||||
# Turn on dolt_sql_user_is_committer
|
||||
dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "SET @@global.dolt_sql_user_is_committer = 1;"
|
||||
run dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "SELECT @@session.dolt_sql_user_is_committer;"
|
||||
[ $status -eq 0 ]
|
||||
[[ $output =~ "| 1 " ]] || false
|
||||
|
||||
# Commits should now show up as the sql user (user1)
|
||||
# By default, commits will be authored by the current sql user (user1)
|
||||
dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "create table t2(pk int primary key);"
|
||||
dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "call dolt_commit('-Am', 'committing as user1');"
|
||||
run dolt sql-client -P $PORT -u user1 --use-db 'repo1' -q "select committer, email, message from dolt_log limit 1;"
|
||||
|
||||
Reference in New Issue
Block a user