commit 3d47d5be9ccd92b00e99622770fc369f20e57514 from: Stefan Sperling via: Thomas Adam date: Mon Oct 31 17:41:54 2022 UTC require space between commit author name and email, for Git compatibility Allowing such author fields breaks 'got send' towards Github for affected commits because git-index-pack --strict will error out on the server: $ git index-pack --strict pack-de791fb6a3a1961e44ac5d98d72fd533bf9277c8.pack error: object 5d6bde9eaaf27f41ae8fa7112bb45e489d3c16b9: missingSpaceBeforeEmail: invalid author/committer line - missing space before email fatal: fsck error in packed object problem encountered by landry@ ok op@ commit - c0876f4c1ecc4e8ccd484a059314ce6de9bdda50 commit + 3d47d5be9ccd92b00e99622770fc369f20e57514 blob - f0e209ed820c0ff4be4e992216a38276d65b9e19 blob + 92305bb9b56b9b54b804829349aee33cc4fac93f --- got/got.c +++ got/got.c @@ -562,6 +562,9 @@ valid_author(const char *author) while (*author && *author != '\n' && *author != '<' && *author != '>') author++; + if (author != email && *author == '<' && *(author - 1) != ' ') + return got_error_fmt(GOT_ERR_COMMIT_BAD_AUTHOR, "%s: space " + "between author name and email required", email); if (*author++ != '<') return got_error_fmt(GOT_ERR_COMMIT_NO_EMAIL, "%s", email); while (*author && *author != '\n' && *author != '<' && *author != '>') blob - 7663fb46b1a2ece5aeb1e9796b95f6ad66d67abf blob + 402de7d527bf413bd0c66dbf155fd68c7d6ef586 --- include/got_error.h +++ include/got_error.h @@ -183,6 +183,7 @@ #define GOT_ERR_REFS_PROTECTED 163 #define GOT_ERR_REF_PROTECTED 164 #define GOT_ERR_REF_BUSY 165 +#define GOT_ERR_COMMIT_BAD_AUTHOR 166 struct got_error { int code; blob - d59feabb14594cdf847e500c2dbe058d377fa414 blob + 70e4070cea9cffbc893e8e23a355207fa4c15bd3 --- lib/error.c +++ lib/error.c @@ -239,6 +239,8 @@ static const struct got_error got_errors[] = { { GOT_ERR_REFS_PROTECTED, "reference namespace may not be modified" }, { GOT_ERR_REF_PROTECTED," reference may not be modified" }, { GOT_ERR_REF_BUSY, "reference cannot be updated; please try again" }, + { GOT_ERR_COMMIT_BAD_AUTHOR, "commit author formatting would " + "make Git unhappy" }, }; static struct got_custom_error { blob - a62a12556a4f4fd09459de4290d9f368de04dcab blob + 3fe1c5f4253b474876351c2558d385123355ff8f --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -1688,8 +1688,45 @@ test_commit_gitignore() { test_done "$testroot" "$ret" } + +test_commit_bad_author() { + local testroot=`test_init commit_bad_author` + + got checkout $testroot/repo $testroot/wt > /dev/null + ret=$? + if [ $ret -ne 0 ]; then + test_done "$testroot" $ret + return 1 + fi + + echo "modified alpha" > $testroot/wt/alpha + + (cd $testroot/wt && got commit \ + -A "${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>" -m 'edit alpha') \ + > /dev/null 2> $testroot/stderr + ret=$? + if [ $ret -eq 0 ]; then + test_done "$testroot" 1 + return 1 + fi + echo -n "got: ${GIT_AUTHOR_NAME}<${GIT_AUTHOR_EMAIL}>: " \ + > $testroot/stderr.expected + echo -n 'space between author name and email required: ' \ + >> $testroot/stderr.expected + echo 'commit author formatting would make Git unhappy' \ + >> $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr + ret=$? + if [ $ret -ne 0 ]; then + diff -u $testroot/stderr.expected $testroot/stderr + test_done "$testroot" $ret + return 1 + fi + test_done "$testroot" 0 +} + test_parseargs "$@" run_test test_commit_basic run_test test_commit_new_subdir @@ -1719,3 +1756,4 @@ run_test test_commit_fix_bad_symlink run_test test_commit_prepared_logmsg run_test test_commit_large_file run_test test_commit_gitignore +run_test test_commit_bad_author