Skip to content

Commit 2df9988

Browse files
committed
Merge branch 'bc/receive-pack-stdout-protection'
When "git push" triggered the automatic gc on the receiving end, a message from "git prune" that said it was removing cruft leaked to the standard output, breaking the communication protocol. * bc/receive-pack-stdout-protection: receive-pack: do not leak output from auto-gc to standard output t/t5400: demonstrate breakage caused by informational message from prune
2 parents e6daf0a + 4b7f2fa commit 2df9988

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

builtin/receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,8 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
977977
const char *argv_gc_auto[] = {
978978
"gc", "--auto", "--quiet", NULL,
979979
};
980-
run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
980+
int opt = RUN_GIT_CMD | RUN_COMMAND_STDOUT_TO_STDERR;
981+
run_command_v_opt(argv_gc_auto, opt);
981982
}
982983
if (auto_update_server_info)
983984
update_server_info(0);

t/t5400-send-pack.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,41 @@ test_expect_success 'push --all excludes remote-tracking hierarchy' '
145145
)
146146
'
147147

148+
test_expect_success 'receive-pack runs auto-gc in remote repo' '
149+
rm -rf parent child &&
150+
git init parent &&
151+
(
152+
# Setup a repo with 2 packs
153+
cd parent &&
154+
echo "Some text" >file.txt &&
155+
git add . &&
156+
git commit -m "Initial commit" &&
157+
git repack -adl &&
158+
echo "Some more text" >>file.txt &&
159+
git commit -a -m "Second commit" &&
160+
git repack
161+
) &&
162+
cp -a parent child &&
163+
(
164+
# Set the child to auto-pack if more than one pack exists
165+
cd child &&
166+
git config gc.autopacklimit 1 &&
167+
git branch test_auto_gc &&
168+
# And create a file that follows the temporary object naming
169+
# convention for the auto-gc to remove
170+
: >.git/objects/tmp_test_object &&
171+
test-chmtime =-1209601 .git/objects/tmp_test_object
172+
) &&
173+
(
174+
cd parent &&
175+
echo "Even more text" >>file.txt &&
176+
git commit -a -m "Third commit" &&
177+
git send-pack ../child HEAD:refs/heads/test_auto_gc >output 2>&1 &&
178+
grep "Auto packing the repository for optimum performance." output
179+
) &&
180+
test ! -e child/.git/objects/tmp_test_object
181+
'
182+
148183
rewound_push_setup() {
149184
rm -rf parent child &&
150185
mkdir parent &&

0 commit comments

Comments
 (0)