]> git.ipfire.org Git - thirdparty/git.git/commitdiff
receive-pack: purge temporary data if no command is ready to run
authorChen Bojun <bojun.cbj@alibaba-inc.com>
Sat, 29 Jan 2022 06:35:38 +0000 (14:35 +0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 1 Feb 2022 22:51:36 +0000 (14:51 -0800)
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 <zhiyou.jx@alibaba-inc.com>
Helped-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Chen Bojun <bojun.cbj@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/receive-pack.c
t/t5516-fetch-push.sh

index 9f4a0b816cf9b6acd077a10a728a83e4048b9b5e..a0b193ab3f4a58eda61590cbbf033388cc3cea08 100644 (file)
@@ -1971,6 +1971,15 @@ static void execute_commands(struct command *commands,
                return;
        }
 
+       /*
+        * If there is no command ready to run, should return directly to destroy
+        * temporary data in the quarantine area.
+        */
+       for (cmd = commands; cmd && cmd->error_string; cmd = cmd->next)
+               ; /* nothing */
+       if (!cmd)
+               return;
+
        /*
         * Now we'll start writing out refs, which means the objects need
         * to be in their final positions so that other processes can see them.
index 2f04cf9a1c7700c599237cee93c3877a0f9f649e..da70c45857295d4d5fc8a8518bc289148e72d126 100755 (executable)
@@ -1809,4 +1809,12 @@ test_expect_success 'refuse fetch to current branch of bare repository worktree'
        git -C bare.git fetch -u .. HEAD:wt
 '
 
+test_expect_success 'refuse to push a hidden ref, and make sure do not pollute the repository' '
+       mk_empty testrepo &&
+       git -C testrepo config receive.hiderefs refs/hidden &&
+       git -C testrepo config receive.unpackLimit 1 &&
+       test_must_fail git push testrepo HEAD:refs/hidden/foo &&
+       test_dir_is_empty testrepo/.git/objects/pack
+'
+
 test_done