do not override receive-pack errors

Receive runs rev-list --verify-objects in order to detect missing objects. However, such errors are ignored and overridden later. Instead, consequently ignore all update commands for which an error has already been detected. Some tests in t5504 are obsoleted by this change, because invalid objects are detected even if fsck is not enabled. Instead, they now test for different error messages depending on whether or not fsck is turned on. A better fix would be to force a corruption that will be detected by fsck but not by rev-list. Signed-off-by: Clemens Buchacher <drizzd@aon.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Clemens Buchacher committed Feb 13, 2012 at 21:17 UTC ef7e93d90866e91bba5ff7f274c49dc44427a8ff
2 files changed +35 -11
builtin/receive-pack.c
+17 -7
@@ -623,8 +623,10 @@ static void check_aliased_updates(struct command *commands)
623 }
624 sort_string_list(&ref_list);
625
626 - for (cmd = commands; cmd; cmd = cmd->next)
627 - check_aliased_update(cmd, &ref_list);
626 + for (cmd = commands; cmd; cmd = cmd->next) {
627 + if (!cmd->error_string)
628 + check_aliased_update(cmd, &ref_list);
629 + }
630
631 string_list_clear(&ref_list, 0);
632 }
@@ -688,8 +690,10 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
690 set_connectivity_errors(commands);
691
692 if (run_receive_hook(commands, pre_receive_hook, 0)) {
691 - for (cmd = commands; cmd; cmd = cmd->next)
692 - cmd->error_string = "pre-receive hook declined";
693 + for (cmd = commands; cmd; cmd = cmd->next) {
694 + if (!cmd->error_string)
695 + cmd->error_string = "pre-receive hook declined";
696 + }
697 return;
698 }
699
@@ -697,9 +701,15 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
701
702 head_name = resolve_ref("HEAD", sha1, 0, NULL);
703
700 - for (cmd = commands; cmd; cmd = cmd->next)
701 - if (!cmd->skip_update)
702 - cmd->error_string = update(cmd);
704 + for (cmd = commands; cmd; cmd = cmd->next) {
705 + if (cmd->error_string)
706 + continue;
707 +
708 + if (cmd->skip_update)
709 + continue;
710 +
711 + cmd->error_string = update(cmd);
712 + }
713 }
714
715 static struct command *read_head_info(void)
t/t5504-fetch-receive-strict.sh
+18 -4
@@ -58,6 +58,11 @@ test_expect_success 'fetch with transfer.fsckobjects' '
58 )
59 '
60
61 +cat >exp <<EOF
62 +To dst
63 +! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
64 +EOF
65 +
66 test_expect_success 'push without strict' '
67 rm -rf dst &&
68 git init dst &&
@@ -66,7 +71,8 @@ test_expect_success 'push without strict' '
71 git config fetch.fsckobjects false &&
72 git config transfer.fsckobjects false
73 ) &&
69 - git push dst master:refs/heads/test
74 + test_must_fail git push --porcelain dst master:refs/heads/test >act &&
75 + test_cmp exp act
76 '
77
78 test_expect_success 'push with !receive.fsckobjects' '
@@ -77,9 +83,15 @@ test_expect_success 'push with !receive.fsckobjects' '
83 git config receive.fsckobjects false &&
84 git config transfer.fsckobjects true
85 ) &&
80 - git push dst master:refs/heads/test
86 + test_must_fail git push --porcelain dst master:refs/heads/test >act &&
87 + test_cmp exp act
88 '
89
90 +cat >exp <<EOF
91 +To dst
92 +! refs/heads/master:refs/heads/test [remote rejected] (n/a (unpacker error))
93 +EOF
94 +
95 test_expect_success 'push with receive.fsckobjects' '
96 rm -rf dst &&
97 git init dst &&
@@ -88,7 +100,8 @@ test_expect_success 'push with receive.fsckobjects' '
100 git config receive.fsckobjects true &&
101 git config transfer.fsckobjects false
102 ) &&
91 - test_must_fail git push dst master:refs/heads/test
103 + test_must_fail git push --porcelain dst master:refs/heads/test >act &&
104 + test_cmp exp act
105 '
106
107 test_expect_success 'push with transfer.fsckobjects' '
@@ -98,7 +111,8 @@ test_expect_success 'push with transfer.fsckobjects' '
111 cd dst &&
112 git config transfer.fsckobjects true
113 ) &&
101 - test_must_fail git push dst master:refs/heads/test
114 + test_must_fail git push --porcelain dst master:refs/heads/test >act &&
115 + test_cmp exp act
116 '
117
118 test_done