Commit 35bd8fed48e5c647869cdc1b3144be70101c9e0b

Stefan Sperling 2019-05-09T14:57:06

require GOT_AUTHOR environment variable

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`