3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='See why rewinding head breaks send-pack
12 test_expect_success setup
'
14 mkdir mozart mozart/is &&
15 echo "Commit #0" >mozart/is/pink &&
16 git update-index --add mozart/is/pink &&
17 tree=$(git write-tree) &&
18 commit=$(echo "Commit #0" | git commit-tree $tree) &&
22 while test $i -le $cnt
26 echo "Commit #$i" >mozart/is/pink &&
27 git update-index --add mozart/is/pink &&
28 tree=$(git write-tree) &&
29 commit=$(echo "Commit #$i" | git commit-tree $tree -p $parent) &&
30 git update-ref refs/tags/commit$i $commit &&
31 parent=$commit || return 1
33 git update-ref HEAD "$commit" &&
34 git-clone ./. victim &&
38 git update-ref HEAD "$zero" &&
41 while test $i -le $cnt
45 echo "Rebase #$i" >mozart/is/pink &&
46 git update-index --add mozart/is/pink &&
47 tree=$(git write-tree) &&
48 commit=$(echo "Rebase #$i" | git commit-tree $tree -p $parent) &&
49 git update-ref refs/tags/rebase$i $commit &&
50 parent=$commit || return 1
52 git update-ref HEAD "$commit" &&
56 test_expect_success
'pack the source repository' '
61 test_expect_success
'pack the destination repository' '
69 'pushing rewound head should not barf but require --force' '
70 # should not fail but refuse to update.
71 if git-send-pack ./victim/.git/ master
73 # now it should fail with Pasky patch
74 echo >&2 Gaah, it should have failed.
77 echo >&2 Thanks, it correctly failed.
80 if cmp victim/.git/refs/heads/master .git/refs/heads/master
82 # should have been left as it was!
88 git-send-pack --force ./victim/.git/ master &&
89 cmp victim/.git/refs/heads/master .git/refs/heads/master
93 'push can be used to delete a ref' '
95 git branch extra master &&
97 test -f victim/.git/refs/heads/extra &&
98 git-send-pack ./victim/.git/ :extra master &&
99 ! test -f victim/.git/refs/heads/extra
102 unset GIT_CONFIG GIT_CONFIG_LOCAL
103 HOME
=`pwd`/no-such-directory
104 export HOME
;# this way we force the victim/.git/config to be used.
106 test_expect_success \
107 'pushing with --force should be denied with denyNonFastforwards' '
109 git config receive.denyNonFastforwards true &&
111 git update-ref refs/heads/master master^ || return 1
112 git-send-pack --force ./victim/.git/ master && return 1
113 ! test_cmp .git/refs/heads/master victim/.git/refs/heads/master
116 test_expect_success \
117 'pushing does not include non-head refs' '
118 mkdir parent && cd parent &&
119 git-init && touch file && git-add file && git-commit -m add &&
121 git-clone parent child && cd child && git-push --all &&
123 git-branch -a >branches && ! grep origin/master branches
126 rewound_push_setup
() {
127 rm -rf parent child
&&
128 mkdir parent
&& cd parent
&&
129 git-init
&& echo one
>file && git-add
file && git-commit
-m one
&&
130 echo two
>file && git-commit
-a -m two
&&
132 git-clone parent child
&& cd child
&& git-reset
--hard HEAD^
135 rewound_push_succeeded
() {
136 cmp ..
/parent
/.git
/refs
/heads
/master .git
/refs
/heads
/master
139 rewound_push_failed
() {
140 if rewound_push_succeeded
148 test_expect_success \
149 'pushing explicit refspecs respects forcing' '
150 rewound_push_setup &&
151 if git-send-pack ../parent/.git refs/heads/master:refs/heads/master
156 fi && rewound_push_failed &&
157 git-send-pack ../parent/.git +refs/heads/master:refs/heads/master &&
158 rewound_push_succeeded
161 test_expect_success \
162 'pushing wildcard refspecs respects forcing' '
163 rewound_push_setup &&
164 if git-send-pack ../parent/.git refs/heads/*:refs/heads/*
169 fi && rewound_push_failed &&
170 git-send-pack ../parent/.git +refs/heads/*:refs/heads/* &&
171 rewound_push_succeeded