2005-07-27 11:04:22 +08:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='See why rewinding head breaks send-pack
|
|
|
|
|
|
|
|
'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2006-12-29 18:25:04 +08:00
|
|
|
cnt=64
|
2005-07-27 11:04:22 +08:00
|
|
|
test_expect_success setup '
|
2006-12-29 18:25:04 +08:00
|
|
|
test_tick &&
|
|
|
|
mkdir mozart mozart/is &&
|
|
|
|
echo "Commit #0" >mozart/is/pink &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-index --add mozart/is/pink &&
|
|
|
|
tree=$(git write-tree) &&
|
|
|
|
commit=$(echo "Commit #0" | git commit-tree $tree) &&
|
2005-07-27 11:04:22 +08:00
|
|
|
zero=$commit &&
|
|
|
|
parent=$zero &&
|
2006-12-29 18:25:04 +08:00
|
|
|
i=0 &&
|
|
|
|
while test $i -le $cnt
|
2005-07-27 11:04:22 +08:00
|
|
|
do
|
2006-12-29 18:25:04 +08:00
|
|
|
i=$(($i+1)) &&
|
|
|
|
test_tick &&
|
|
|
|
echo "Commit #$i" >mozart/is/pink &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-index --add mozart/is/pink &&
|
|
|
|
tree=$(git write-tree) &&
|
|
|
|
commit=$(echo "Commit #$i" | git commit-tree $tree -p $parent) &&
|
|
|
|
git update-ref refs/tags/commit$i $commit &&
|
2005-08-11 11:56:21 +08:00
|
|
|
parent=$commit || return 1
|
2005-07-27 11:04:22 +08:00
|
|
|
done &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-ref HEAD "$commit" &&
|
2008-09-03 16:59:29 +08:00
|
|
|
git clone ./. victim &&
|
2009-02-11 18:28:03 +08:00
|
|
|
( cd victim && git config receive.denyCurrentBranch warn && git log ) &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-ref HEAD "$zero" &&
|
2005-07-27 11:04:22 +08:00
|
|
|
parent=$zero &&
|
2006-12-29 18:25:04 +08:00
|
|
|
i=0 &&
|
|
|
|
while test $i -le $cnt
|
2005-07-27 11:04:22 +08:00
|
|
|
do
|
2006-12-29 18:25:04 +08:00
|
|
|
i=$(($i+1)) &&
|
|
|
|
test_tick &&
|
|
|
|
echo "Rebase #$i" >mozart/is/pink &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-index --add mozart/is/pink &&
|
|
|
|
tree=$(git write-tree) &&
|
|
|
|
commit=$(echo "Rebase #$i" | git commit-tree $tree -p $parent) &&
|
|
|
|
git update-ref refs/tags/rebase$i $commit &&
|
2005-08-11 11:56:21 +08:00
|
|
|
parent=$commit || return 1
|
2005-07-27 11:04:22 +08:00
|
|
|
done &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git update-ref HEAD "$commit" &&
|
2005-07-27 11:04:22 +08:00
|
|
|
echo Rebase &&
|
2007-07-03 13:52:14 +08:00
|
|
|
git log'
|
2005-07-27 11:04:22 +08:00
|
|
|
|
2006-12-29 18:25:04 +08:00
|
|
|
test_expect_success 'pack the source repository' '
|
|
|
|
git repack -a -d &&
|
2007-01-22 13:29:44 +08:00
|
|
|
git prune
|
2006-12-29 18:25:04 +08:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pack the destination repository' '
|
2009-02-10 05:39:52 +08:00
|
|
|
(
|
2006-12-29 18:25:04 +08:00
|
|
|
cd victim &&
|
|
|
|
git repack -a -d &&
|
2009-02-10 05:39:52 +08:00
|
|
|
git prune
|
|
|
|
)
|
2006-12-29 18:25:04 +08:00
|
|
|
'
|
|
|
|
|
2009-02-10 05:39:52 +08:00
|
|
|
test_expect_success 'refuse pushing rewound head without --force' '
|
|
|
|
pushed_head=$(git rev-parse --verify master) &&
|
|
|
|
victim_orig=$(cd victim && git rev-parse --verify master) &&
|
|
|
|
test_must_fail git send-pack ./victim master &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
|
|
|
test "$victim_head" = "$victim_orig" &&
|
2005-07-27 11:04:22 +08:00
|
|
|
# this should update
|
2009-02-10 05:39:52 +08:00
|
|
|
git send-pack --force ./victim master &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
|
|
|
test "$victim_head" = "$pushed_head"
|
2005-07-27 11:04:22 +08:00
|
|
|
'
|
2005-08-11 10:15:02 +08:00
|
|
|
|
2014-12-16 11:58:07 +08:00
|
|
|
test_expect_success 'push can be used to delete a ref' '
|
2009-02-10 05:39:52 +08:00
|
|
|
( cd victim && git branch extra master ) &&
|
|
|
|
git send-pack ./victim :extra master &&
|
|
|
|
( cd victim &&
|
|
|
|
test_must_fail git rev-parse --verify extra )
|
2006-11-24 16:26:49 +08:00
|
|
|
'
|
|
|
|
|
2009-02-10 05:39:52 +08:00
|
|
|
test_expect_success 'refuse deleting push with denyDeletes' '
|
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
( git branch -D extra || : ) &&
|
|
|
|
git config receive.denyDeletes true &&
|
|
|
|
git branch extra master
|
|
|
|
) &&
|
|
|
|
test_must_fail git send-pack ./victim :extra master
|
2008-11-01 22:42:16 +08:00
|
|
|
'
|
|
|
|
|
2010-08-24 14:41:14 +08:00
|
|
|
test_expect_success 'cannot override denyDeletes with git -c send-pack' '
|
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
test_might_fail git branch -D extra &&
|
|
|
|
git config receive.denyDeletes true &&
|
|
|
|
git branch extra master
|
|
|
|
) &&
|
|
|
|
test_must_fail git -c receive.denyDeletes=false \
|
|
|
|
send-pack ./victim :extra master
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'override denyDeletes with git -c receive-pack' '
|
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
test_might_fail git branch -D extra &&
|
|
|
|
git config receive.denyDeletes true &&
|
|
|
|
git branch extra master
|
|
|
|
) &&
|
|
|
|
git send-pack \
|
|
|
|
--receive-pack="git -c receive.denyDeletes=false receive-pack" \
|
|
|
|
./victim :extra master
|
|
|
|
'
|
|
|
|
|
2009-02-10 05:39:52 +08:00
|
|
|
test_expect_success 'denyNonFastforwards trumps --force' '
|
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
( git branch -D extra || : ) &&
|
|
|
|
git config receive.denyNonFastforwards true
|
|
|
|
) &&
|
|
|
|
victim_orig=$(cd victim && git rev-parse --verify master) &&
|
|
|
|
test_must_fail git send-pack --force ./victim master^:master &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify master) &&
|
|
|
|
test "$victim_orig" = "$victim_head"
|
2006-09-21 08:10:30 +08:00
|
|
|
'
|
|
|
|
|
2016-03-31 21:55:09 +08:00
|
|
|
test_expect_success 'send-pack --all sends all branches' '
|
|
|
|
# make sure we have at least 2 branches with different
|
|
|
|
# values, just to be thorough
|
|
|
|
git branch other-branch HEAD^ &&
|
|
|
|
|
|
|
|
git init --bare all.git &&
|
|
|
|
git send-pack --all all.git &&
|
|
|
|
git for-each-ref refs/heads >expect &&
|
|
|
|
git -C all.git for-each-ref refs/heads >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-11-02 23:31:21 +08:00
|
|
|
test_expect_success 'push --all excludes remote-tracking hierarchy' '
|
2009-02-10 05:39:52 +08:00
|
|
|
mkdir parent &&
|
|
|
|
(
|
|
|
|
cd parent &&
|
|
|
|
git init && : >file && git add file && git commit -m add
|
|
|
|
) &&
|
|
|
|
git clone parent child &&
|
|
|
|
(
|
|
|
|
cd child && git push --all
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd parent &&
|
|
|
|
test -z "$(git for-each-ref refs/remotes/origin)"
|
|
|
|
)
|
2007-09-18 16:15:34 +08:00
|
|
|
'
|
|
|
|
|
2012-08-07 13:31:10 +08:00
|
|
|
test_expect_success 'receive-pack runs auto-gc in remote repo' '
|
2012-08-07 13:01:48 +08:00
|
|
|
rm -rf parent child &&
|
|
|
|
git init parent &&
|
|
|
|
(
|
|
|
|
# Setup a repo with 2 packs
|
|
|
|
cd parent &&
|
|
|
|
echo "Some text" >file.txt &&
|
|
|
|
git add . &&
|
|
|
|
git commit -m "Initial commit" &&
|
|
|
|
git repack -adl &&
|
|
|
|
echo "Some more text" >>file.txt &&
|
|
|
|
git commit -a -m "Second commit" &&
|
|
|
|
git repack
|
|
|
|
) &&
|
2012-10-08 16:08:01 +08:00
|
|
|
cp -R parent child &&
|
2012-08-07 13:01:48 +08:00
|
|
|
(
|
|
|
|
# Set the child to auto-pack if more than one pack exists
|
|
|
|
cd child &&
|
|
|
|
git config gc.autopacklimit 1 &&
|
2014-02-08 15:08:52 +08:00
|
|
|
git config gc.autodetach false &&
|
2012-08-07 13:01:48 +08:00
|
|
|
git branch test_auto_gc &&
|
|
|
|
# And create a file that follows the temporary object naming
|
|
|
|
# convention for the auto-gc to remove
|
|
|
|
: >.git/objects/tmp_test_object &&
|
|
|
|
test-chmtime =-1209601 .git/objects/tmp_test_object
|
|
|
|
) &&
|
|
|
|
(
|
|
|
|
cd parent &&
|
|
|
|
echo "Even more text" >>file.txt &&
|
|
|
|
git commit -a -m "Third commit" &&
|
2012-09-24 10:40:24 +08:00
|
|
|
git send-pack ../child HEAD:refs/heads/test_auto_gc
|
2012-08-07 13:01:48 +08:00
|
|
|
) &&
|
|
|
|
test ! -e child/.git/objects/tmp_test_object
|
|
|
|
'
|
|
|
|
|
2007-10-19 17:04:00 +08:00
|
|
|
rewound_push_setup() {
|
|
|
|
rm -rf parent child &&
|
2009-02-10 05:39:52 +08:00
|
|
|
mkdir parent &&
|
|
|
|
(
|
|
|
|
cd parent &&
|
|
|
|
git init &&
|
|
|
|
echo one >file && git add file && git commit -m one &&
|
2009-02-11 18:28:03 +08:00
|
|
|
git config receive.denyCurrentBranch warn &&
|
2009-02-10 05:39:52 +08:00
|
|
|
echo two >file && git commit -a -m two
|
|
|
|
) &&
|
|
|
|
git clone parent child &&
|
|
|
|
(
|
|
|
|
cd child && git reset --hard HEAD^
|
|
|
|
)
|
2007-10-19 17:04:00 +08:00
|
|
|
}
|
|
|
|
|
2009-02-10 05:39:52 +08:00
|
|
|
test_expect_success 'pushing explicit refspecs respects forcing' '
|
2007-10-19 17:04:00 +08:00
|
|
|
rewound_push_setup &&
|
2009-02-10 05:39:52 +08:00
|
|
|
parent_orig=$(cd parent && git rev-parse --verify master) &&
|
|
|
|
(
|
|
|
|
cd child &&
|
|
|
|
test_must_fail git send-pack ../parent \
|
|
|
|
refs/heads/master:refs/heads/master
|
|
|
|
) &&
|
|
|
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
|
|
|
test "$parent_orig" = "$parent_head" &&
|
|
|
|
(
|
|
|
|
cd child &&
|
|
|
|
git send-pack ../parent \
|
|
|
|
+refs/heads/master:refs/heads/master
|
|
|
|
) &&
|
|
|
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
2011-05-14 00:43:29 +08:00
|
|
|
child_head=$(cd child && git rev-parse --verify master) &&
|
2009-02-10 05:39:52 +08:00
|
|
|
test "$parent_head" = "$child_head"
|
2007-10-19 17:04:00 +08:00
|
|
|
'
|
|
|
|
|
2009-02-10 05:39:52 +08:00
|
|
|
test_expect_success 'pushing wildcard refspecs respects forcing' '
|
2007-10-19 17:04:00 +08:00
|
|
|
rewound_push_setup &&
|
2009-02-10 05:39:52 +08:00
|
|
|
parent_orig=$(cd parent && git rev-parse --verify master) &&
|
|
|
|
(
|
|
|
|
cd child &&
|
|
|
|
test_must_fail git send-pack ../parent \
|
|
|
|
"refs/heads/*:refs/heads/*"
|
|
|
|
) &&
|
|
|
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
|
|
|
test "$parent_orig" = "$parent_head" &&
|
|
|
|
(
|
|
|
|
cd child &&
|
|
|
|
git send-pack ../parent \
|
|
|
|
"+refs/heads/*:refs/heads/*"
|
|
|
|
) &&
|
|
|
|
parent_head=$(cd parent && git rev-parse --verify master) &&
|
2011-05-14 00:43:29 +08:00
|
|
|
child_head=$(cd child && git rev-parse --verify master) &&
|
2009-02-10 05:39:52 +08:00
|
|
|
test "$parent_head" = "$child_head"
|
2007-10-19 17:04:00 +08:00
|
|
|
'
|
|
|
|
|
2009-02-09 16:19:46 +08:00
|
|
|
test_expect_success 'deny pushing to delete current branch' '
|
2009-02-09 14:31:21 +08:00
|
|
|
rewound_push_setup &&
|
|
|
|
(
|
|
|
|
cd child &&
|
2009-02-09 16:19:46 +08:00
|
|
|
test_must_fail git send-pack ../parent :refs/heads/master 2>errs
|
2009-02-09 14:31:21 +08:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-02-09 04:53:19 +08:00
|
|
|
extract_ref_advertisement () {
|
|
|
|
perl -lne '
|
|
|
|
# \\ is there to skip capabilities after \0
|
|
|
|
/push< ([^\\]+)/ or next;
|
|
|
|
exit 0 if $1 eq "0000";
|
|
|
|
print $1;
|
|
|
|
'
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'receive-pack de-dupes .have lines' '
|
|
|
|
git init shared &&
|
|
|
|
git -C shared commit --allow-empty -m both &&
|
|
|
|
git clone -s shared fork &&
|
|
|
|
(
|
|
|
|
cd shared &&
|
|
|
|
git checkout -b only-shared &&
|
|
|
|
git commit --allow-empty -m only-shared &&
|
|
|
|
git update-ref refs/heads/foo HEAD
|
|
|
|
) &&
|
|
|
|
|
|
|
|
# Notable things in this expectation:
|
|
|
|
# - local refs are not de-duped
|
|
|
|
# - .have does not duplicate locals
|
|
|
|
# - .have does not duplicate itself
|
|
|
|
local=$(git -C fork rev-parse HEAD) &&
|
|
|
|
shared=$(git -C shared rev-parse only-shared) &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
$local refs/heads/master
|
|
|
|
$local refs/remotes/origin/HEAD
|
|
|
|
$local refs/remotes/origin/master
|
|
|
|
$shared .have
|
|
|
|
EOF
|
|
|
|
|
2017-05-18 13:02:09 +08:00
|
|
|
GIT_TRACE_PACKET=$(pwd)/trace \
|
|
|
|
git push \
|
|
|
|
--receive-pack="unset GIT_TRACE_PACKET; git-receive-pack" \
|
|
|
|
fork HEAD:foo &&
|
2017-02-09 04:53:19 +08:00
|
|
|
extract_ref_advertisement <trace >refs &&
|
|
|
|
test_cmp expect refs
|
|
|
|
'
|
|
|
|
|
2005-08-11 10:15:02 +08:00
|
|
|
test_done
|