Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='See why rewinding head breaks send-pack |
| 7 | |
| 8 | ' |
| 9 | . ./test-lib.sh |
| 10 | |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 11 | cnt=64 |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 12 | test_expect_success setup ' |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 13 | test_tick && |
| 14 | mkdir mozart mozart/is && |
| 15 | echo "Commit #0" >mozart/is/pink && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 16 | git update-index --add mozart/is/pink && |
| 17 | tree=$(git write-tree) && |
| 18 | commit=$(echo "Commit #0" | git commit-tree $tree) && |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 19 | zero=$commit && |
| 20 | parent=$zero && |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 21 | i=0 && |
| 22 | while test $i -le $cnt |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 23 | do |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 24 | i=$(($i+1)) && |
| 25 | test_tick && |
| 26 | echo "Commit #$i" >mozart/is/pink && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 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 && |
Pavel Roskin | 4d9d62f | 2005-08-10 23:56:21 -0400 | [diff] [blame] | 31 | parent=$commit || return 1 |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 32 | done && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 33 | git update-ref HEAD "$commit" && |
Nanako Shiraishi | 3604e7c | 2008-09-03 17:59:29 +0900 | [diff] [blame] | 34 | git clone ./. victim && |
Junio C Hamano | acd2a45 | 2009-02-11 02:28:03 -0800 | [diff] [blame] | 35 | ( cd victim && git config receive.denyCurrentBranch warn && git log ) && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 36 | git update-ref HEAD "$zero" && |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 37 | parent=$zero && |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 38 | i=0 && |
| 39 | while test $i -le $cnt |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 40 | do |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 41 | i=$(($i+1)) && |
| 42 | test_tick && |
| 43 | echo "Rebase #$i" >mozart/is/pink && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 44 | git update-index --add mozart/is/pink && |
| 45 | tree=$(git write-tree) && |
| 46 | commit=$(echo "Rebase #$i" | git commit-tree $tree -p $parent) && |
| 47 | git update-ref refs/tags/rebase$i $commit && |
Pavel Roskin | 4d9d62f | 2005-08-10 23:56:21 -0400 | [diff] [blame] | 48 | parent=$commit || return 1 |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 49 | done && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 50 | git update-ref HEAD "$commit" && |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 51 | echo Rebase && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 52 | git log' |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 53 | |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 54 | test_expect_success 'pack the source repository' ' |
| 55 | git repack -a -d && |
Junio C Hamano | 026aa93 | 2007-01-21 21:29:44 -0800 | [diff] [blame] | 56 | git prune |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 57 | ' |
| 58 | |
| 59 | test_expect_success 'pack the destination repository' ' |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 60 | ( |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 61 | cd victim && |
| 62 | git repack -a -d && |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 63 | git prune |
| 64 | ) |
Junio C Hamano | 0450973 | 2006-12-29 02:25:04 -0800 | [diff] [blame] | 65 | ' |
| 66 | |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 67 | test_expect_success 'refuse pushing rewound head without --force' ' |
| 68 | pushed_head=$(git rev-parse --verify master) && |
| 69 | victim_orig=$(cd victim && git rev-parse --verify master) && |
| 70 | test_must_fail git send-pack ./victim master && |
| 71 | victim_head=$(cd victim && git rev-parse --verify master) && |
| 72 | test "$victim_head" = "$victim_orig" && |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 73 | # this should update |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 74 | git send-pack --force ./victim master && |
| 75 | victim_head=$(cd victim && git rev-parse --verify master) && |
| 76 | test "$victim_head" = "$pushed_head" |
Linus Torvalds | bdf2514 | 2005-07-26 20:04:22 -0700 | [diff] [blame] | 77 | ' |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 78 | |
Junio C Hamano | d4f694b | 2006-11-24 00:26:49 -0800 | [diff] [blame] | 79 | test_expect_success \ |
| 80 | 'push can be used to delete a ref' ' |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 81 | ( cd victim && git branch extra master ) && |
| 82 | git send-pack ./victim :extra master && |
| 83 | ( cd victim && |
| 84 | test_must_fail git rev-parse --verify extra ) |
Junio C Hamano | d4f694b | 2006-11-24 00:26:49 -0800 | [diff] [blame] | 85 | ' |
| 86 | |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 87 | test_expect_success 'refuse deleting push with denyDeletes' ' |
| 88 | ( |
| 89 | cd victim && |
| 90 | ( git branch -D extra || : ) && |
| 91 | git config receive.denyDeletes true && |
| 92 | git branch extra master |
| 93 | ) && |
| 94 | test_must_fail git send-pack ./victim :extra master |
Johannes Schindelin | 199a921 | 2006-09-21 02:10:30 +0200 | [diff] [blame] | 95 | ' |
| 96 | |
Jonathan Nieder | 655e8d9 | 2010-08-24 01:41:14 -0500 | [diff] [blame] | 97 | test_expect_success 'cannot override denyDeletes with git -c send-pack' ' |
| 98 | ( |
| 99 | cd victim && |
| 100 | test_might_fail git branch -D extra && |
| 101 | git config receive.denyDeletes true && |
| 102 | git branch extra master |
| 103 | ) && |
| 104 | test_must_fail git -c receive.denyDeletes=false \ |
| 105 | send-pack ./victim :extra master |
| 106 | ' |
| 107 | |
| 108 | test_expect_success 'override denyDeletes with git -c receive-pack' ' |
| 109 | ( |
| 110 | cd victim && |
| 111 | test_might_fail git branch -D extra && |
| 112 | git config receive.denyDeletes true && |
| 113 | git branch extra master |
| 114 | ) && |
| 115 | git send-pack \ |
| 116 | --receive-pack="git -c receive.denyDeletes=false receive-pack" \ |
| 117 | ./victim :extra master |
| 118 | ' |
| 119 | |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 120 | test_expect_success 'denyNonFastforwards trumps --force' ' |
| 121 | ( |
| 122 | cd victim && |
| 123 | ( git branch -D extra || : ) && |
| 124 | git config receive.denyNonFastforwards true |
| 125 | ) && |
| 126 | victim_orig=$(cd victim && git rev-parse --verify master) && |
| 127 | test_must_fail git send-pack --force ./victim master^:master && |
| 128 | victim_head=$(cd victim && git rev-parse --verify master) && |
| 129 | test "$victim_orig" = "$victim_head" |
| 130 | ' |
| 131 | |
Matthieu Moy | 60109d0 | 2010-11-02 16:31:21 +0100 | [diff] [blame] | 132 | test_expect_success 'push --all excludes remote-tracking hierarchy' ' |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 133 | mkdir parent && |
| 134 | ( |
| 135 | cd parent && |
| 136 | git init && : >file && git add file && git commit -m add |
| 137 | ) && |
| 138 | git clone parent child && |
| 139 | ( |
| 140 | cd child && git push --all |
| 141 | ) && |
| 142 | ( |
| 143 | cd parent && |
| 144 | test -z "$(git for-each-ref refs/remotes/origin)" |
| 145 | ) |
Jeff King | 5c633a4 | 2007-09-18 04:15:34 -0400 | [diff] [blame] | 146 | ' |
| 147 | |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 148 | rewound_push_setup() { |
| 149 | rm -rf parent child && |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 150 | mkdir parent && |
| 151 | ( |
| 152 | cd parent && |
| 153 | git init && |
| 154 | echo one >file && git add file && git commit -m one && |
Junio C Hamano | acd2a45 | 2009-02-11 02:28:03 -0800 | [diff] [blame] | 155 | git config receive.denyCurrentBranch warn && |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 156 | echo two >file && git commit -a -m two |
| 157 | ) && |
| 158 | git clone parent child && |
| 159 | ( |
| 160 | cd child && git reset --hard HEAD^ |
| 161 | ) |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | rewound_push_succeeded() { |
| 165 | cmp ../parent/.git/refs/heads/master .git/refs/heads/master |
| 166 | } |
| 167 | |
| 168 | rewound_push_failed() { |
| 169 | if rewound_push_succeeded |
| 170 | then |
| 171 | false |
| 172 | else |
| 173 | true |
| 174 | fi |
| 175 | } |
| 176 | |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 177 | test_expect_success 'pushing explicit refspecs respects forcing' ' |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 178 | rewound_push_setup && |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 179 | parent_orig=$(cd parent && git rev-parse --verify master) && |
| 180 | ( |
| 181 | cd child && |
| 182 | test_must_fail git send-pack ../parent \ |
| 183 | refs/heads/master:refs/heads/master |
| 184 | ) && |
| 185 | parent_head=$(cd parent && git rev-parse --verify master) && |
| 186 | test "$parent_orig" = "$parent_head" && |
| 187 | ( |
| 188 | cd child && |
| 189 | git send-pack ../parent \ |
| 190 | +refs/heads/master:refs/heads/master |
| 191 | ) && |
| 192 | parent_head=$(cd parent && git rev-parse --verify master) && |
| 193 | child_head=$(cd parent && git rev-parse --verify master) && |
| 194 | test "$parent_head" = "$child_head" |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 195 | ' |
| 196 | |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 197 | test_expect_success 'pushing wildcard refspecs respects forcing' ' |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 198 | rewound_push_setup && |
Junio C Hamano | 2f33415 | 2009-02-09 13:39:52 -0800 | [diff] [blame] | 199 | parent_orig=$(cd parent && git rev-parse --verify master) && |
| 200 | ( |
| 201 | cd child && |
| 202 | test_must_fail git send-pack ../parent \ |
| 203 | "refs/heads/*:refs/heads/*" |
| 204 | ) && |
| 205 | parent_head=$(cd parent && git rev-parse --verify master) && |
| 206 | test "$parent_orig" = "$parent_head" && |
| 207 | ( |
| 208 | cd child && |
| 209 | git send-pack ../parent \ |
| 210 | "+refs/heads/*:refs/heads/*" |
| 211 | ) && |
| 212 | parent_head=$(cd parent && git rev-parse --verify master) && |
| 213 | child_head=$(cd parent && git rev-parse --verify master) && |
| 214 | test "$parent_head" = "$child_head" |
Jeff King | 5eb7358 | 2007-10-19 05:04:00 -0400 | [diff] [blame] | 215 | ' |
| 216 | |
Junio C Hamano | 375881f | 2009-02-09 00:19:46 -0800 | [diff] [blame] | 217 | test_expect_success 'deny pushing to delete current branch' ' |
Junio C Hamano | 747ca24 | 2009-02-08 22:31:21 -0800 | [diff] [blame] | 218 | rewound_push_setup && |
| 219 | ( |
| 220 | cd child && |
Junio C Hamano | 375881f | 2009-02-09 00:19:46 -0800 | [diff] [blame] | 221 | test_must_fail git send-pack ../parent :refs/heads/master 2>errs |
Junio C Hamano | 747ca24 | 2009-02-08 22:31:21 -0800 | [diff] [blame] | 222 | ) |
| 223 | ' |
| 224 | |
Pavel Roskin | da7bc9b | 2005-08-10 22:15:02 -0400 | [diff] [blame] | 225 | test_done |