2023-05-12 15:09:16 +00:00
|
|
|
#!/bin/sh
|
push: introduce '--branches' option
The '--all' option of git-push built-in cmd support to push all branches
(refs under refs/heads) to remote. Under the usage, a user can easlily
work in some scenarios, for example, branches synchronization and batch
upload.
The '--all' was introduced for a long time, meanwhile, git supports to
customize the storage location under "refs/". when a new git user see
the usage like, 'git push origin --all', we might feel like we're
pushing _all_ the refs instead of just branches without looking at the
documents until we found the related description of it or '--mirror'.
To ensure compatibility, we cannot rename '--all' to another name
directly, one way is, we can try to add a new option '--heads' which be
identical with the functionality of '--all' to let the user understand
the meaning of representation more clearly. Actually, We've more or less
named options this way already, for example, in 'git-show-ref' and 'git
ls-remote'.
At the same time, we fix a related issue about the wrong help
information of '--all' option in code and add some test cases in
t5523, t5543 and t5583.
Signed-off-by: Teng Long <dyroneteng@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-05-06 11:34:08 +00:00
|
|
|
|
|
|
|
test_description='check the consisitency of behavior of --all and --branches'
|
|
|
|
|
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
delete_refs() {
|
|
|
|
dir=$1
|
|
|
|
shift
|
|
|
|
rm -rf deletes
|
|
|
|
for arg in $*
|
|
|
|
do
|
|
|
|
echo "delete ${arg}" >>deletes
|
|
|
|
done
|
|
|
|
git -C $dir update-ref --stdin < deletes
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'setup bare remote' '
|
|
|
|
git init --bare remote-1 &&
|
|
|
|
git -C remote-1 config gc.auto 0 &&
|
|
|
|
test_commit one &&
|
|
|
|
git push remote-1 HEAD
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'setup different types of references' '
|
|
|
|
cat >refs <<-EOF &&
|
|
|
|
update refs/heads/branch-1 HEAD
|
|
|
|
update refs/heads/branch-2 HEAD
|
|
|
|
EOF
|
|
|
|
|
|
|
|
git tag -a -m "annotated" annotated-1 HEAD &&
|
|
|
|
git tag -a -m "annotated" annotated-2 HEAD &&
|
|
|
|
git update-ref --stdin < refs
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--all and --branches have the same behavior' '
|
|
|
|
test_when_finished "delete_refs remote-1 \
|
|
|
|
refs/heads/branch-1 \
|
|
|
|
refs/heads/branch-2" &&
|
|
|
|
git push remote-1 --all &&
|
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
$commit refs/heads/branch-1
|
|
|
|
$commit refs/heads/branch-2
|
|
|
|
$commit refs/heads/main
|
|
|
|
EOF
|
|
|
|
|
|
|
|
git -C remote-1 show-ref --heads >actual.all &&
|
|
|
|
delete_refs remote-1 refs/heads/branch-1 refs/heads/branch-2 &&
|
|
|
|
git push remote-1 --branches &&
|
|
|
|
git -C remote-1 show-ref --heads >actual.branches &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
test_cmp expect actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--all or --branches can not be combined with refspecs' '
|
|
|
|
test_must_fail git push remote-1 --all main >actual.all 2>&1 &&
|
|
|
|
test_must_fail git push remote-1 --branches main >actual.branches 2>&1 &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
grep "be combined with refspecs" actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--all or --branches can not be combined with --mirror' '
|
|
|
|
test_must_fail git push remote-1 --all --mirror >actual.all 2>&1 &&
|
|
|
|
test_must_fail git push remote-1 --branches --mirror >actual.branches 2>&1 &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
grep "cannot be used together" actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--all or --branches can not be combined with --tags' '
|
|
|
|
test_must_fail git push remote-1 --all --tags >actual.all 2>&1 &&
|
|
|
|
test_must_fail git push remote-1 --branches --tags >actual.branches 2>&1 &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
grep "cannot be used together" actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
|
|
|
|
test_expect_success '--all or --branches can not be combined with --delete' '
|
|
|
|
test_must_fail git push remote-1 --all --delete >actual.all 2>&1 &&
|
|
|
|
test_must_fail git push remote-1 --branches --delete >actual.branches 2>&1 &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
grep "cannot be used together" actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--all or --branches combines with --follow-tags have same behavior' '
|
|
|
|
test_when_finished "delete_refs remote-1 \
|
|
|
|
refs/heads/branch-1 \
|
|
|
|
refs/heads/branch-2 \
|
|
|
|
refs/tags/annotated-1 \
|
|
|
|
refs/tags/annotated-2" &&
|
|
|
|
git push remote-1 --all --follow-tags &&
|
|
|
|
git -C remote-1 show-ref > actual.all &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
$commit refs/heads/branch-1
|
|
|
|
$commit refs/heads/branch-2
|
|
|
|
$commit refs/heads/main
|
|
|
|
$(git rev-parse annotated-1) refs/tags/annotated-1
|
|
|
|
$(git rev-parse annotated-2) refs/tags/annotated-2
|
|
|
|
EOF
|
|
|
|
|
|
|
|
delete_refs remote-1 \
|
|
|
|
refs/heads/branch-1 \
|
|
|
|
refs/heads/branch-2 \
|
|
|
|
refs/tags/annotated-1 \
|
|
|
|
refs/tags/annotated-2 &&
|
|
|
|
git push remote-1 --branches --follow-tags &&
|
|
|
|
git -C remote-1 show-ref >actual.branches &&
|
|
|
|
test_cmp actual.all actual.branches &&
|
|
|
|
test_cmp expect actual.all
|
|
|
|
'
|
|
|
|
|
|
|
|
test_done
|