require GOT_AUTHOR environment variable
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
diff --git a/got/got.c b/got/got.c
index 77eeffb..e4684d9 100644
--- a/got/got.c
+++ b/got/got.c
@@ -2088,6 +2088,7 @@ cmd_commit(int argc, char *argv[])
char *cwd = NULL, *path = NULL, *id_str = NULL;
struct got_object_id *id = NULL;
const char *logmsg = "<no log message was specified>";
+ const char *got_author = getenv("GOT_AUTHOR");
int ch;
while ((ch = getopt(argc, argv, "m:")) != -1) {
@@ -2113,6 +2114,11 @@ cmd_commit(int argc, char *argv[])
} else if (argc != 0)
usage_commit();
+ if (got_author == NULL) {
+ /* TODO: Look current user up in password database */
+ error = got_error(GOT_ERR_COMMIT_NO_AUTHOR);
+ goto done;
+ }
cwd = getcwd(NULL, 0);
if (cwd == NULL) {
@@ -2132,9 +2138,8 @@ cmd_commit(int argc, char *argv[])
if (error)
goto done;
- error = got_worktree_commit(&id, worktree, path,
- "Stefan Sperling <stsp@stsp.name>", NULL, logmsg,
- print_status, NULL, repo);
+ error = got_worktree_commit(&id, worktree, path, got_author, NULL,
+ logmsg, print_status, NULL, repo);
if (error)
goto done;
diff --git a/include/got_error.h b/include/got_error.h
index c3c1b5a..52d7a09 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -84,6 +84,7 @@
#define GOT_ERR_FILE_STATUS 68
#define GOT_ERR_COMMIT_CONFLICT 69
#define GOT_ERR_BAD_REF_TYPE 70
+#define GOT_ERR_COMMIT_NO_AUTHOR 71
static const struct got_error {
int code;
@@ -159,6 +160,7 @@ static const struct got_error {
{ GOT_ERR_FILE_STATUS, "file has unexpected status" },
{ GOT_ERR_COMMIT_CONFLICT,"cannot commit file in conflicted status" },
{ GOT_ERR_BAD_REF_TYPE, "bad reference type" },
+ { GOT_ERR_COMMIT_NO_AUTHOR,"GOT_AUTHOR environment variable is not set" },
};
/*
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index 3b59e83..e378888 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -16,6 +16,9 @@
. ./common.sh
+name=$(getent passwd $USER | cut -d: -f5)
+export GOT_AUTHOR="$name <$(whoami)@$(hostname)>"
+
function test_commit_basic {
local testroot=`test_init commit_basic`