Skip to content

Commit 5407764

Browse files
0xd219bgitster
authored andcommitted
receive-pack: purge temporary data if no command is ready to run
When pushing a hidden ref, e.g.: $ git push origin HEAD:refs/hidden/foo "receive-pack" will reject our request with an error message like this: ! [remote rejected] HEAD -> refs/hidden/foo (deny updating a hidden ref) The remote side ("git-receive-pack") will not create the hidden ref as expected, but the pack file sent by "git-send-pack" is left inside the remote repository. I.e. the quarantine directory is not purged as it should be. Add a checkpoint before calling "tmp_objdir_migrate()" and after calling the "pre-receive" hook to purge that temporary data in the quarantine area when there is no command ready to run. The reason we do not add the checkpoint before the "pre-receive" hook, but after it, is that the "pre-receive" hook is called with a switch-off "skip_broken" flag, and all commands, even broken ones, should be fed by calling "feed_receive_hook()". Add a new test case in t5516 as well. Helped-by: Jiang Xin <[email protected]> Helped-by: Teng Long <[email protected]> Signed-off-by: Chen Bojun <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit 5407764

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

builtin/receive-pack.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,6 +1971,15 @@ static void execute_commands(struct command *commands,
19711971
return;
19721972
}
19731973

1974+
/*
1975+
* If there is no command ready to run, should return directly to destroy
1976+
* temporary data in the quarantine area.
1977+
*/
1978+
for (cmd = commands; cmd && cmd->error_string; cmd = cmd->next)
1979+
; /* nothing */
1980+
if (!cmd)
1981+
return;
1982+
19741983
/*
19751984
* Now we'll start writing out refs, which means the objects need
19761985
* to be in their final positions so that other processes can see them.

t/t5516-fetch-push.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,4 +1809,12 @@ test_expect_success 'refuse fetch to current branch of bare repository worktree'
18091809
git -C bare.git fetch -u .. HEAD:wt
18101810
'
18111811

1812+
test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' '
1813+
mk_empty testrepo &&
1814+
git -C testrepo config receive.hiderefs refs/hidden &&
1815+
git -C testrepo config receive.unpackLimit 1 &&
1816+
test_must_fail git push testrepo HEAD:refs/hidden/foo &&
1817+
test_dir_is_empty testrepo/.git/objects/pack
1818+
'
1819+
18121820
test_done

0 commit comments

Comments
 (0)