Skip to content

Commit ef7e93d

Browse files
Clemens Buchachergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0482e8 commit ef7e93d

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

builtin/receive-pack.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -623,8 +623,10 @@ static void check_aliased_updates(struct command *commands)
623623
}
624624
sort_string_list(&ref_list);
625625

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+
}
628630

629631
string_list_clear(&ref_list, 0);
630632
}
@@ -688,18 +690,26 @@ static void execute_commands(struct command *commands, const char *unpacker_erro
688690
set_connectivity_errors(commands);
689691

690692
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+
}
693697
return;
694698
}
695699

696700
check_aliased_updates(commands);
697701

698702
head_name = resolve_ref("HEAD", sha1, 0, NULL);
699703

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+
}
703713
}
704714

705715
static struct command *read_head_info(void)

t/t5504-fetch-receive-strict.sh

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ test_expect_success 'fetch with transfer.fsckobjects' '
5858
)
5959
'
6060

61+
cat >exp <<EOF
62+
To dst
63+
! refs/heads/master:refs/heads/test [remote rejected] (missing necessary objects)
64+
EOF
65+
6166
test_expect_success 'push without strict' '
6267
rm -rf dst &&
6368
git init dst &&
@@ -66,7 +71,8 @@ test_expect_success 'push without strict' '
6671
git config fetch.fsckobjects false &&
6772
git config transfer.fsckobjects false
6873
) &&
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
7076
'
7177

7278
test_expect_success 'push with !receive.fsckobjects' '
@@ -77,9 +83,15 @@ test_expect_success 'push with !receive.fsckobjects' '
7783
git config receive.fsckobjects false &&
7884
git config transfer.fsckobjects true
7985
) &&
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
8188
'
8289

90+
cat >exp <<EOF
91+
To dst
92+
! refs/heads/master:refs/heads/test [remote rejected] (n/a (unpacker error))
93+
EOF
94+
8395
test_expect_success 'push with receive.fsckobjects' '
8496
rm -rf dst &&
8597
git init dst &&
@@ -88,7 +100,8 @@ test_expect_success 'push with receive.fsckobjects' '
88100
git config receive.fsckobjects true &&
89101
git config transfer.fsckobjects false
90102
) &&
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
92105
'
93106

94107
test_expect_success 'push with transfer.fsckobjects' '
@@ -98,7 +111,8 @@ test_expect_success 'push with transfer.fsckobjects' '
98111
cd dst &&
99112
git config transfer.fsckobjects true
100113
) &&
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
102116
'
103117

104118
test_done

0 commit comments

Comments
 (0)