]> rtime.felk.cvut.cz Git - git.git/commitdiff
Merge branch 'jn/maint-amend-missing-name'
authorJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:52 +0000 (11:20 -0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 13 Jun 2010 18:20:52 +0000 (11:20 -0700)
* jn/maint-amend-missing-name:
  commit --amend: cope with missing display name

builtin/commit.c
t/t7509-commit.sh

index ddf77e48e1d9fa1e6db0ac49008857b85a9b5e41..a4e4966319651c03a3bb933795c502b24b2324d4 100644 (file)
@@ -462,15 +462,21 @@ static void determine_author_info(void)
                if (!a)
                        die("invalid commit: %s", use_message);
 
-               lb = strstr(a + 8, " <");
-               rb = strstr(a + 8, "> ");
-               eol = strchr(a + 8, '\n');
-               if (!lb || !rb || !eol)
+               lb = strchrnul(a + strlen("\nauthor "), '<');
+               rb = strchrnul(lb, '>');
+               eol = strchrnul(rb, '\n');
+               if (!*lb || !*rb || !*eol)
                        die("invalid commit: %s", use_message);
 
-               name = xstrndup(a + 8, lb - (a + 8));
-               email = xstrndup(lb + 2, rb - (lb + 2));
-               date = xstrndup(rb + 2, eol - (rb + 2));
+               if (lb == a + strlen("\nauthor "))
+                       /* \nauthor <foo@example.com> */
+                       name = xcalloc(1, 1);
+               else
+                       name = xmemdupz(a + strlen("\nauthor "),
+                                       (lb - strlen(" ") -
+                                        (a + strlen("\nauthor "))));
+               email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<")));
+               date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> ")));
        }
 
        if (force_author) {
index d52c060b061b3e0af9d9779366f4cc85a8009851..3ea33db6c73df763c22ccfab9f0cdcb2bbaef4d7 100755 (executable)
@@ -83,6 +83,52 @@ test_expect_success '--amend option copies authorship' '
        test_cmp expect actual
 '
 
+sha1_file() {
+       echo "$*" | sed "s#..#.git/objects/&/#"
+}
+remove_object() {
+       rm -f $(sha1_file "$*")
+}
+no_reflog() {
+       cp .git/config .git/config.saved &&
+       echo "[core] logallrefupdates = false" >>.git/config &&
+       test_when_finished "mv -f .git/config.saved .git/config" &&
+
+       if test -e .git/logs
+       then
+               mv .git/logs . &&
+               test_when_finished "mv logs .git/"
+       fi
+}
+
+test_expect_success '--amend option with empty author' '
+       git cat-file commit Initial >tmp &&
+       sed "s/author [^<]* </author  </" tmp >empty-author &&
+       no_reflog &&
+       sha=$(git hash-object -t commit -w empty-author) &&
+       test_when_finished "remove_object $sha" &&
+       git checkout $sha &&
+       test_when_finished "git checkout Initial" &&
+       echo "Empty author test" >>foo &&
+       test_tick &&
+       ! git commit -a -m "empty author" --amend 2>err &&
+       grep "empty ident" err
+'
+
+test_expect_success '--amend option with missing author' '
+       git cat-file commit Initial >tmp &&
+       sed "s/author [^<]* </author </" tmp >malformed &&
+       no_reflog &&
+       sha=$(git hash-object -t commit -w malformed) &&
+       test_when_finished "remove_object $sha" &&
+       git checkout $sha &&
+       test_when_finished "git checkout Initial" &&
+       echo "Missing author test" >>foo &&
+       test_tick &&
+       ! git commit -a -m "malformed author" --amend 2>err &&
+       grep "empty ident" err
+'
+
 test_expect_success '--reset-author makes the commit ours even with --amend option' '
        git checkout Initial &&
        echo "Test 6" >>foo &&