Merge branch 'jk/repack-leakfix'
[git.git] / t / t5583-push-branches.sh
blobe7e1b6dab66fb31d065c4dc7611c824a7bc1bf5b
1 #!/bin/sh
3 test_description='check the consisitency of behavior of --all and --branches'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 . ./test-lib.sh
10 delete_refs() {
11 dir=$1
12 shift
13 rm -rf deletes
14 for arg in $*
16 echo "delete ${arg}" >>deletes
17 done
18 git -C $dir update-ref --stdin < deletes
21 test_expect_success 'setup bare remote' '
22 git init --bare remote-1 &&
23 git -C remote-1 config gc.auto 0 &&
24 test_commit one &&
25 git push remote-1 HEAD
28 test_expect_success 'setup different types of references' '
29 cat >refs <<-EOF &&
30 update refs/heads/branch-1 HEAD
31 update refs/heads/branch-2 HEAD
32 EOF
34 git tag -a -m "annotated" annotated-1 HEAD &&
35 git tag -a -m "annotated" annotated-2 HEAD &&
36 git update-ref --stdin < refs
39 test_expect_success '--all and --branches have the same behavior' '
40 test_when_finished "delete_refs remote-1 \
41 refs/heads/branch-1 \
42 refs/heads/branch-2" &&
43 git push remote-1 --all &&
44 commit=$(git rev-parse HEAD) &&
45 cat >expect <<-EOF &&
46 $commit refs/heads/branch-1
47 $commit refs/heads/branch-2
48 $commit refs/heads/main
49 EOF
51 git -C remote-1 show-ref --heads >actual.all &&
52 delete_refs remote-1 refs/heads/branch-1 refs/heads/branch-2 &&
53 git push remote-1 --branches &&
54 git -C remote-1 show-ref --heads >actual.branches &&
55 test_cmp actual.all actual.branches &&
56 test_cmp expect actual.all
59 test_expect_success '--all or --branches can not be combined with refspecs' '
60 test_must_fail git push remote-1 --all main >actual.all 2>&1 &&
61 test_must_fail git push remote-1 --branches main >actual.branches 2>&1 &&
62 test_cmp actual.all actual.branches &&
63 grep "be combined with refspecs" actual.all
66 test_expect_success '--all or --branches can not be combined with --mirror' '
67 test_must_fail git push remote-1 --all --mirror >actual.all 2>&1 &&
68 test_must_fail git push remote-1 --branches --mirror >actual.branches 2>&1 &&
69 test_cmp actual.all actual.branches &&
70 grep "cannot be used together" actual.all
73 test_expect_success '--all or --branches can not be combined with --tags' '
74 test_must_fail git push remote-1 --all --tags >actual.all 2>&1 &&
75 test_must_fail git push remote-1 --branches --tags >actual.branches 2>&1 &&
76 test_cmp actual.all actual.branches &&
77 grep "cannot be used together" actual.all
81 test_expect_success '--all or --branches can not be combined with --delete' '
82 test_must_fail git push remote-1 --all --delete >actual.all 2>&1 &&
83 test_must_fail git push remote-1 --branches --delete >actual.branches 2>&1 &&
84 test_cmp actual.all actual.branches &&
85 grep "cannot be used together" actual.all
88 test_expect_success '--all or --branches combines with --follow-tags have same behavior' '
89 test_when_finished "delete_refs remote-1 \
90 refs/heads/branch-1 \
91 refs/heads/branch-2 \
92 refs/tags/annotated-1 \
93 refs/tags/annotated-2" &&
94 git push remote-1 --all --follow-tags &&
95 git -C remote-1 show-ref > actual.all &&
96 cat >expect <<-EOF &&
97 $commit refs/heads/branch-1
98 $commit refs/heads/branch-2
99 $commit refs/heads/main
100 $(git rev-parse annotated-1) refs/tags/annotated-1
101 $(git rev-parse annotated-2) refs/tags/annotated-2
104 delete_refs remote-1 \
105 refs/heads/branch-1 \
106 refs/heads/branch-2 \
107 refs/tags/annotated-1 \
108 refs/tags/annotated-2 &&
109 git push remote-1 --branches --follow-tags &&
110 git -C remote-1 show-ref >actual.branches &&
111 test_cmp actual.all actual.branches &&
112 test_cmp expect actual.all
115 test_done