2005-07-27 05:04:22 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2005 Junio C Hamano
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='See why rewinding head breaks send-pack
|
|
|
|
|
|
|
|
'
|
2020-11-19 00:44:29 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2005-07-27 05:04:22 +02:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
2006-12-29 11:25:04 +01:00
|
|
|
cnt=64
|
2005-07-27 05:04:22 +02:00
|
|
|
test_expect_success setup '
|
2006-12-29 11:25:04 +01:00
|
|
|
test_tick &&
|
|
|
|
mkdir mozart mozart/is &&
|
|
|
|
echo "Commit #0" >mozart/is/pink &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-index --add mozart/is/pink &&
|
|
|
|
tree=$(git write-tree) &&
|
|
|
|
commit=$(echo "Commit #0" | git commit-tree $tree) &&
|
2005-07-27 05:04:22 +02:00
|
|
|
zero=$commit &&
|
|
|
|
parent=$zero &&
|
2006-12-29 11:25:04 +01:00
|
|
|
i=0 &&
|
|
|
|
while test $i -le $cnt
|
2005-07-27 05:04:22 +02:00
|
|
|
do
|
2020-11-09 01:09:23 +01:00
|
|
|
i=$(($i+1)) &&
|
|
|
|
test_tick &&
|
|
|
|
echo "Commit #$i" >mozart/is/pink &&
|
|
|
|
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 &&
|
|
|
|
parent=$commit || return 1
|
2005-07-27 05:04:22 +02:00
|
|
|
done &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-ref HEAD "$commit" &&
|
2008-09-03 10:59:29 +02:00
|
|
|
git clone ./. victim &&
|
2009-02-11 11:28:03 +01:00
|
|
|
( cd victim && git config receive.denyCurrentBranch warn && git log ) &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-ref HEAD "$zero" &&
|
2005-07-27 05:04:22 +02:00
|
|
|
parent=$zero &&
|
2006-12-29 11:25:04 +01:00
|
|
|
i=0 &&
|
|
|
|
while test $i -le $cnt
|
2005-07-27 05:04:22 +02:00
|
|
|
do
|
2020-11-09 01:09:23 +01:00
|
|
|
i=$(($i+1)) &&
|
|
|
|
test_tick &&
|
|
|
|
echo "Rebase #$i" >mozart/is/pink &&
|
|
|
|
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 &&
|
|
|
|
parent=$commit || return 1
|
2005-07-27 05:04:22 +02:00
|
|
|
done &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git update-ref HEAD "$commit" &&
|
2005-07-27 05:04:22 +02:00
|
|
|
echo Rebase &&
|
2007-07-03 07:52:14 +02:00
|
|
|
git log'
|
2005-07-27 05:04:22 +02:00
|
|
|
|
2006-12-29 11:25:04 +01:00
|
|
|
test_expect_success 'pack the source repository' '
|
|
|
|
git repack -a -d &&
|
2007-01-22 06:29:44 +01:00
|
|
|
git prune
|
2006-12-29 11:25:04 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'pack the destination repository' '
|
2020-11-09 01:09:23 +01:00
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
git repack -a -d &&
|
|
|
|
git prune
|
|
|
|
)
|
2006-12-29 11:25:04 +01:00
|
|
|
'
|
|
|
|
|
2009-02-09 22:39:52 +01:00
|
|
|
test_expect_success 'refuse pushing rewound head without --force' '
|
2020-11-19 00:44:29 +01:00
|
|
|
pushed_head=$(git rev-parse --verify main) &&
|
|
|
|
victim_orig=$(cd victim && git rev-parse --verify main) &&
|
|
|
|
test_must_fail git send-pack ./victim main &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$victim_head" = "$victim_orig" &&
|
2005-07-27 05:04:22 +02:00
|
|
|
# this should update
|
2020-11-19 00:44:29 +01:00
|
|
|
git send-pack --force ./victim main &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$victim_head" = "$pushed_head"
|
2005-07-27 05:04:22 +02:00
|
|
|
'
|
2005-08-11 04:15:02 +02:00
|
|
|
|
2014-12-16 04:58:07 +01:00
|
|
|
test_expect_success 'push can be used to delete a ref' '
|
2020-11-19 00:44:29 +01:00
|
|
|
( cd victim && git branch extra main ) &&
|
|
|
|
git send-pack ./victim :extra main &&
|
2009-02-09 22:39:52 +01:00
|
|
|
( cd victim &&
|
|
|
|
test_must_fail git rev-parse --verify extra )
|
2006-11-24 09:26:49 +01:00
|
|
|
'
|
|
|
|
|
2009-02-09 22:39:52 +01:00
|
|
|
test_expect_success 'refuse deleting push with denyDeletes' '
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd victim &&
|
|
|
|
test_might_fail git branch -D extra &&
|
|
|
|
git config receive.denyDeletes true &&
|
2020-11-19 00:44:29 +01:00
|
|
|
git branch extra main
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
test_must_fail git send-pack ./victim :extra main
|
2008-11-01 15:42:16 +01:00
|
|
|
'
|
|
|
|
|
2010-08-24 08:41:14 +02: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 &&
|
2020-11-19 00:44:29 +01:00
|
|
|
git branch extra main
|
2010-08-24 08:41:14 +02:00
|
|
|
) &&
|
|
|
|
test_must_fail git -c receive.denyDeletes=false \
|
2020-11-19 00:44:29 +01:00
|
|
|
send-pack ./victim :extra main
|
2010-08-24 08:41:14 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'override denyDeletes with git -c receive-pack' '
|
|
|
|
(
|
|
|
|
cd victim &&
|
|
|
|
test_might_fail git branch -D extra &&
|
|
|
|
git config receive.denyDeletes true &&
|
2020-11-19 00:44:29 +01:00
|
|
|
git branch extra main
|
2010-08-24 08:41:14 +02:00
|
|
|
) &&
|
|
|
|
git send-pack \
|
|
|
|
--receive-pack="git -c receive.denyDeletes=false receive-pack" \
|
2020-11-19 00:44:29 +01:00
|
|
|
./victim :extra main
|
2010-08-24 08:41:14 +02:00
|
|
|
'
|
|
|
|
|
2009-02-09 22:39:52 +01:00
|
|
|
test_expect_success 'denyNonFastforwards trumps --force' '
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd victim &&
|
|
|
|
test_might_fail git branch -D extra &&
|
|
|
|
git config receive.denyNonFastforwards true
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
victim_orig=$(cd victim && git rev-parse --verify main) &&
|
|
|
|
test_must_fail git send-pack --force ./victim main^:main &&
|
|
|
|
victim_head=$(cd victim && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$victim_orig" = "$victim_head"
|
2006-09-21 02:10:30 +02:00
|
|
|
'
|
|
|
|
|
2016-03-31 15:55:09 +02: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 16:31:21 +01:00
|
|
|
test_expect_success 'push --all excludes remote-tracking hierarchy' '
|
2009-02-09 22:39:52 +01:00
|
|
|
mkdir parent &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd parent &&
|
|
|
|
git init && : >file && git add file && git commit -m add
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
|
|
|
git clone parent child &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child && git push --all
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd parent &&
|
|
|
|
test -z "$(git for-each-ref refs/remotes/origin)"
|
2009-02-09 22:39:52 +01:00
|
|
|
)
|
2007-09-18 10:15:34 +02:00
|
|
|
'
|
|
|
|
|
2012-08-07 07:31:10 +02:00
|
|
|
test_expect_success 'receive-pack runs auto-gc in remote repo' '
|
2012-08-07 07:01:48 +02:00
|
|
|
rm -rf parent child &&
|
|
|
|
git init parent &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
# 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-08-07 07:01:48 +02:00
|
|
|
) &&
|
2012-10-08 10:08:01 +02:00
|
|
|
cp -R parent child &&
|
2012-08-07 07:01:48 +02:00
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
# Set the child to auto-pack if more than one pack exists
|
|
|
|
cd child &&
|
|
|
|
git config gc.autopacklimit 1 &&
|
|
|
|
git config gc.autodetach false &&
|
|
|
|
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-tool chmtime =-1209601 .git/objects/tmp_test_object
|
2012-08-07 07:01:48 +02:00
|
|
|
) &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd parent &&
|
|
|
|
echo "Even more text" >>file.txt &&
|
|
|
|
git commit -a -m "Third commit" &&
|
|
|
|
git send-pack ../child HEAD:refs/heads/test_auto_gc
|
2012-08-07 07:01:48 +02:00
|
|
|
) &&
|
|
|
|
test ! -e child/.git/objects/tmp_test_object
|
|
|
|
'
|
|
|
|
|
2007-10-19 11:04:00 +02:00
|
|
|
rewound_push_setup() {
|
|
|
|
rm -rf parent child &&
|
2009-02-09 22:39:52 +01:00
|
|
|
mkdir parent &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd parent &&
|
|
|
|
git init &&
|
|
|
|
echo one >file && git add file && git commit -m one &&
|
|
|
|
git config receive.denyCurrentBranch warn &&
|
|
|
|
echo two >file && git commit -a -m two
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
|
|
|
git clone parent child &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child && git reset --hard HEAD^
|
2009-02-09 22:39:52 +01:00
|
|
|
)
|
2007-10-19 11:04:00 +02:00
|
|
|
}
|
|
|
|
|
2009-02-09 22:39:52 +01:00
|
|
|
test_expect_success 'pushing explicit refspecs respects forcing' '
|
2007-10-19 11:04:00 +02:00
|
|
|
rewound_push_setup &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_orig=$(cd parent && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child &&
|
|
|
|
test_must_fail git send-pack ../parent \
|
2020-11-19 00:44:29 +01:00
|
|
|
refs/heads/main:refs/heads/main
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_head=$(cd parent && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$parent_orig" = "$parent_head" &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child &&
|
|
|
|
git send-pack ../parent \
|
2020-11-19 00:44:29 +01:00
|
|
|
+refs/heads/main:refs/heads/main
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_head=$(cd parent && git rev-parse --verify main) &&
|
|
|
|
child_head=$(cd child && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$parent_head" = "$child_head"
|
2007-10-19 11:04:00 +02:00
|
|
|
'
|
|
|
|
|
2009-02-09 22:39:52 +01:00
|
|
|
test_expect_success 'pushing wildcard refspecs respects forcing' '
|
2007-10-19 11:04:00 +02:00
|
|
|
rewound_push_setup &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_orig=$(cd parent && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child &&
|
|
|
|
test_must_fail git send-pack ../parent \
|
|
|
|
"refs/heads/*:refs/heads/*"
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_head=$(cd parent && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$parent_orig" = "$parent_head" &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child &&
|
|
|
|
git send-pack ../parent \
|
|
|
|
"+refs/heads/*:refs/heads/*"
|
2009-02-09 22:39:52 +01:00
|
|
|
) &&
|
2020-11-19 00:44:29 +01:00
|
|
|
parent_head=$(cd parent && git rev-parse --verify main) &&
|
|
|
|
child_head=$(cd child && git rev-parse --verify main) &&
|
2009-02-09 22:39:52 +01:00
|
|
|
test "$parent_head" = "$child_head"
|
2007-10-19 11:04:00 +02:00
|
|
|
'
|
|
|
|
|
2009-02-09 09:19:46 +01:00
|
|
|
test_expect_success 'deny pushing to delete current branch' '
|
2009-02-09 07:31:21 +01:00
|
|
|
rewound_push_setup &&
|
|
|
|
(
|
2020-11-09 01:09:23 +01:00
|
|
|
cd child &&
|
2020-11-19 00:44:29 +01:00
|
|
|
test_must_fail git send-pack ../parent :refs/heads/main 2>errs
|
2009-02-09 07:31:21 +01:00
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2017-02-08 21:53:19 +01: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 &&
|
2020-11-19 00:44:29 +01:00
|
|
|
$local refs/heads/main
|
2017-02-08 21:53:19 +01:00
|
|
|
$local refs/remotes/origin/HEAD
|
2020-11-19 00:44:29 +01:00
|
|
|
$local refs/remotes/origin/main
|
2017-02-08 21:53:19 +01:00
|
|
|
$shared .have
|
|
|
|
EOF
|
|
|
|
|
2019-12-24 02:01:10 +01:00
|
|
|
GIT_TRACE_PACKET=$(pwd)/trace GIT_TEST_PROTOCOL_VERSION=0 \
|
2020-11-09 01:09:23 +01:00
|
|
|
git push \
|
2017-05-18 07:02:09 +02:00
|
|
|
--receive-pack="unset GIT_TRACE_PACKET; git-receive-pack" \
|
|
|
|
fork HEAD:foo &&
|
2017-02-08 21:53:19 +01:00
|
|
|
extract_ref_advertisement <trace >refs &&
|
|
|
|
test_cmp expect refs
|
|
|
|
'
|
|
|
|
|
2005-08-11 04:15:02 +02:00
|
|
|
test_done
|