improve error message due to malformed `author' in got.conf tweak and ok stsp@
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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
diff --git a/got/got.c b/got/got.c
index 16b939d..03281c0 100644
--- a/got/got.c
+++ b/got/got.c
@@ -596,6 +596,26 @@ import_progress(void *arg, const char *path)
return NULL;
}
+static int
+valid_author(const char *author)
+{
+ /*
+ * Really dumb email address check; we're only doing this to
+ * avoid git's object parser breaking on commits we create.
+ */
+ while (*author && *author != '<')
+ author++;
+ if (*author != '<')
+ return 0;
+ while (*author && *author != '@')
+ author++;
+ if (*author != '@')
+ return 0;
+ while (*author && *author != '>')
+ author++;
+ return *author == '>';
+}
+
static const struct got_error *
get_author(char **author, struct got_repository *repo,
struct got_worktree *worktree)
@@ -653,28 +673,8 @@ get_author(char **author, struct got_repository *repo,
if (*author == NULL)
return got_error_from_errno("strdup");
- /*
- * Really dumb email address check; we're only doing this to
- * avoid git's object parser breaking on commits we create.
- */
- while (*got_author && *got_author != '<')
- got_author++;
- if (*got_author != '<') {
- err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
- goto done;
- }
- while (*got_author && *got_author != '@')
- got_author++;
- if (*got_author != '@') {
- err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
- goto done;
- }
- while (*got_author && *got_author != '>')
- got_author++;
- if (*got_author != '>')
- err = got_error(GOT_ERR_COMMIT_NO_EMAIL);
-done:
- if (err) {
+ if (!valid_author(*author)) {
+ err = got_error_fmt(GOT_ERR_COMMIT_NO_EMAIL, "%s", *author);
free(*author);
*author = NULL;
}
diff --git a/include/got_error.h b/include/got_error.h
index 78a5edb..bfdc8fa 100644
--- a/include/got_error.h
+++ b/include/got_error.h
@@ -287,9 +287,8 @@ static const struct got_error {
{ GOT_ERR_STAGED_PATHS, "work tree contains files with staged "
"changes; these changes must be committed or unstaged first" },
{ GOT_ERR_PATCH_CHOICE, "invalid patch choice" },
- { GOT_ERR_COMMIT_NO_EMAIL,"GOT_AUTHOR environment variable contains "
- "no email address; an email address is required for compatibility "
- "with Git" },
+ { GOT_ERR_COMMIT_NO_EMAIL, "commit author's email address is required "
+ "for compatibility with Git" },
{ GOT_ERR_TAG_EXISTS,"specified tag already exists" },
{ GOT_ERR_GIT_REPO_FORMAT,"unknown git repository format version" },
{ GOT_ERR_REBASE_REQUIRED,"specified branch must be rebased first" },
diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh
index 34d74d2..d878260 100755
--- a/regress/cmdline/commit.sh
+++ b/regress/cmdline/commit.sh
@@ -649,11 +649,10 @@ test_commit_no_email() {
got commit -m 'test no email' > $testroot/stdout \
2> $testroot/stderr)
- echo -n "got: GOT_AUTHOR environment variable contains no email " \
+ echo -n "got: :flan_hacker:: commit author's email address " \
> $testroot/stderr.expected
- echo -n "address; an email address is required for compatibility "\
+ echo "is required for compatibility with Git" \
>> $testroot/stderr.expected
- echo "with Git" >> $testroot/stderr.expected
cmp -s $testroot/stderr.expected $testroot/stderr
ret="$?"
if [ "$ret" != "0" ]; then