Linus Torvalds | d09e79c | 2006-11-16 11:47:22 -0800 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='pulling into void' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
Elijah Newren | 3cee923 | 2010-08-12 19:50:49 -0600 | [diff] [blame] | 7 | modify () { |
| 8 | sed -e "$1" <"$2" >"$2.x" && |
| 9 | mv "$2.x" "$2" |
| 10 | } |
| 11 | |
Linus Torvalds | d09e79c | 2006-11-16 11:47:22 -0800 | [diff] [blame] | 12 | D=`pwd` |
| 13 | |
| 14 | test_expect_success setup ' |
| 15 | |
| 16 | echo file >file && |
| 17 | git add file && |
| 18 | git commit -a -m original |
| 19 | |
| 20 | ' |
| 21 | |
| 22 | test_expect_success 'pulling into void' ' |
| 23 | mkdir cloned && |
| 24 | cd cloned && |
Nicolas Pitre | 5c94f87 | 2007-01-12 16:01:46 -0500 | [diff] [blame] | 25 | git init && |
Linus Torvalds | d09e79c | 2006-11-16 11:47:22 -0800 | [diff] [blame] | 26 | git pull .. |
| 27 | ' |
| 28 | |
| 29 | cd "$D" |
| 30 | |
| 31 | test_expect_success 'checking the results' ' |
| 32 | test -f file && |
| 33 | test -f cloned/file && |
Gary V. Vaughan | 4fdf71b | 2010-05-14 09:31:37 +0000 | [diff] [blame] | 34 | test_cmp file cloned/file |
Linus Torvalds | d09e79c | 2006-11-16 11:47:22 -0800 | [diff] [blame] | 35 | ' |
| 36 | |
Junio C Hamano | b0ad11e | 2008-10-14 15:32:20 -0700 | [diff] [blame] | 37 | test_expect_success 'pulling into void using master:master' ' |
| 38 | mkdir cloned-uho && |
| 39 | ( |
| 40 | cd cloned-uho && |
| 41 | git init && |
| 42 | git pull .. master:master |
| 43 | ) && |
| 44 | test -f file && |
| 45 | test -f cloned-uho/file && |
| 46 | test_cmp file cloned-uho/file |
| 47 | ' |
| 48 | |
Jeff King | 4b3ffe5 | 2011-03-25 14:13:31 -0400 | [diff] [blame] | 49 | test_expect_success 'pulling into void does not overwrite untracked files' ' |
| 50 | git init cloned-untracked && |
| 51 | ( |
| 52 | cd cloned-untracked && |
| 53 | echo untracked >file && |
| 54 | test_must_fail git pull .. master && |
| 55 | echo untracked >expect && |
| 56 | test_cmp expect file |
| 57 | ) |
| 58 | ' |
| 59 | |
Paolo Bonzini | 9debc32 | 2007-03-15 09:23:20 +0100 | [diff] [blame] | 60 | test_expect_success 'test . as a remote' ' |
| 61 | |
| 62 | git branch copy master && |
| 63 | git config branch.copy.remote . && |
| 64 | git config branch.copy.merge refs/heads/master && |
| 65 | echo updated >file && |
| 66 | git commit -a -m updated && |
| 67 | git checkout copy && |
| 68 | test `cat file` = file && |
| 69 | git pull && |
| 70 | test `cat file` = updated |
| 71 | ' |
| 72 | |
| 73 | test_expect_success 'the default remote . should not break explicit pull' ' |
| 74 | git checkout -b second master^ && |
| 75 | echo modified >file && |
| 76 | git commit -a -m modified && |
| 77 | git checkout copy && |
| 78 | git reset --hard HEAD^ && |
| 79 | test `cat file` = file && |
| 80 | git pull . second && |
| 81 | test `cat file` = modified |
| 82 | ' |
| 83 | |
Johannes Schindelin | cd67e4d | 2007-11-28 13:11:07 +0000 | [diff] [blame] | 84 | test_expect_success '--rebase' ' |
| 85 | git branch to-rebase && |
| 86 | echo modified again > file && |
| 87 | git commit -m file file && |
| 88 | git checkout to-rebase && |
| 89 | echo new > file2 && |
| 90 | git add file2 && |
| 91 | git commit -m "new file" && |
| 92 | git tag before-rebase && |
| 93 | git pull --rebase . copy && |
| 94 | test $(git rev-parse HEAD^) = $(git rev-parse copy) && |
| 95 | test new = $(git show HEAD:file2) |
| 96 | ' |
Ævar Arnfjörð Bjarmason | 6b37dff | 2011-11-06 10:50:10 +0100 | [diff] [blame] | 97 | test_expect_success 'pull.rebase' ' |
| 98 | git reset --hard before-rebase && |
| 99 | git config --bool pull.rebase true && |
| 100 | test_when_finished "git config --unset pull.rebase" && |
| 101 | git pull . copy && |
| 102 | test $(git rev-parse HEAD^) = $(git rev-parse copy) && |
| 103 | test new = $(git show HEAD:file2) |
| 104 | ' |
Johannes Schindelin | cd67e4d | 2007-11-28 13:11:07 +0000 | [diff] [blame] | 105 | |
| 106 | test_expect_success 'branch.to-rebase.rebase' ' |
| 107 | git reset --hard before-rebase && |
Ævar Arnfjörð Bjarmason | 6b37dff | 2011-11-06 10:50:10 +0100 | [diff] [blame] | 108 | git config --bool branch.to-rebase.rebase true && |
| 109 | test_when_finished "git config --unset branch.to-rebase.rebase" && |
Johannes Schindelin | cd67e4d | 2007-11-28 13:11:07 +0000 | [diff] [blame] | 110 | git pull . copy && |
| 111 | test $(git rev-parse HEAD^) = $(git rev-parse copy) && |
| 112 | test new = $(git show HEAD:file2) |
| 113 | ' |
| 114 | |
Ævar Arnfjörð Bjarmason | 6b37dff | 2011-11-06 10:50:10 +0100 | [diff] [blame] | 115 | test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' |
| 116 | git reset --hard before-rebase && |
| 117 | git config --bool pull.rebase true && |
| 118 | test_when_finished "git config --unset pull.rebase" && |
| 119 | git config --bool branch.to-rebase.rebase false && |
| 120 | test_when_finished "git config --unset branch.to-rebase.rebase" && |
| 121 | git pull . copy && |
| 122 | test $(git rev-parse HEAD^) != $(git rev-parse copy) && |
| 123 | test new = $(git show HEAD:file2) |
| 124 | ' |
| 125 | |
Johannes Schindelin | c85c792 | 2008-01-26 18:04:37 +0000 | [diff] [blame] | 126 | test_expect_success '--rebase with rebased upstream' ' |
| 127 | |
| 128 | git remote add -f me . && |
| 129 | git checkout copy && |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 130 | git tag copy-orig && |
Johannes Schindelin | c85c792 | 2008-01-26 18:04:37 +0000 | [diff] [blame] | 131 | git reset --hard HEAD^ && |
| 132 | echo conflicting modification > file && |
| 133 | git commit -m conflict file && |
| 134 | git checkout to-rebase && |
| 135 | echo file > file2 && |
| 136 | git commit -m to-rebase file2 && |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 137 | git tag to-rebase-orig && |
Johannes Schindelin | c85c792 | 2008-01-26 18:04:37 +0000 | [diff] [blame] | 138 | git pull --rebase me copy && |
| 139 | test "conflicting modification" = "$(cat file)" && |
| 140 | test file = $(cat file2) |
| 141 | |
| 142 | ' |
| 143 | |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 144 | test_expect_success '--rebase with rebased default upstream' ' |
| 145 | |
| 146 | git update-ref refs/remotes/me/copy copy-orig && |
| 147 | git checkout --track -b to-rebase2 me/copy && |
| 148 | git reset --hard to-rebase-orig && |
| 149 | git pull --rebase && |
| 150 | test "conflicting modification" = "$(cat file)" && |
| 151 | test file = $(cat file2) |
| 152 | |
| 153 | ' |
| 154 | |
Santi Béjar | d44e712 | 2009-07-19 09:45:16 +0200 | [diff] [blame] | 155 | test_expect_success 'rebased upstream + fetch + pull --rebase' ' |
Santi Béjar | a418441 | 2009-07-16 02:09:14 +0200 | [diff] [blame] | 156 | |
| 157 | git update-ref refs/remotes/me/copy copy-orig && |
| 158 | git reset --hard to-rebase-orig && |
| 159 | git checkout --track -b to-rebase3 me/copy && |
| 160 | git reset --hard to-rebase-orig && |
| 161 | git fetch && |
Santi Béjar | d44e712 | 2009-07-19 09:45:16 +0200 | [diff] [blame] | 162 | git pull --rebase && |
Santi Béjar | a418441 | 2009-07-16 02:09:14 +0200 | [diff] [blame] | 163 | test "conflicting modification" = "$(cat file)" && |
| 164 | test file = "$(cat file2)" |
| 165 | |
| 166 | ' |
| 167 | |
Johannes Schindelin | f9189cf | 2008-05-21 12:32:16 +0100 | [diff] [blame] | 168 | test_expect_success 'pull --rebase dies early with dirty working directory' ' |
| 169 | |
Santi Béjar | e9460a6 | 2009-06-12 00:39:19 +0200 | [diff] [blame] | 170 | git checkout to-rebase && |
Johannes Schindelin | f9189cf | 2008-05-21 12:32:16 +0100 | [diff] [blame] | 171 | git update-ref refs/remotes/me/copy copy^ && |
| 172 | COPY=$(git rev-parse --verify me/copy) && |
| 173 | git rebase --onto $COPY copy && |
| 174 | git config branch.to-rebase.remote me && |
| 175 | git config branch.to-rebase.merge refs/heads/copy && |
| 176 | git config branch.to-rebase.rebase true && |
| 177 | echo dirty >> file && |
| 178 | git add file && |
| 179 | test_must_fail git pull && |
| 180 | test $COPY = $(git rev-parse --verify me/copy) && |
| 181 | git checkout HEAD -- file && |
| 182 | git pull && |
| 183 | test $COPY != $(git rev-parse --verify me/copy) |
| 184 | |
| 185 | ' |
| 186 | |
Jeff King | 19a7fcb | 2009-08-11 23:27:40 -0400 | [diff] [blame] | 187 | test_expect_success 'pull --rebase works on branch yet to be born' ' |
| 188 | git rev-parse master >expect && |
| 189 | mkdir empty_repo && |
| 190 | (cd empty_repo && |
| 191 | git init && |
| 192 | git pull --rebase .. master && |
| 193 | git rev-parse HEAD >../actual |
| 194 | ) && |
| 195 | test_cmp expect actual |
| 196 | ' |
| 197 | |
Elijah Newren | 3cee923 | 2010-08-12 19:50:49 -0600 | [diff] [blame] | 198 | test_expect_success 'setup for detecting upstreamed changes' ' |
| 199 | mkdir src && |
| 200 | (cd src && |
| 201 | git init && |
| 202 | printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff && |
| 203 | git add stuff && |
| 204 | git commit -m "Initial revision" |
| 205 | ) && |
| 206 | git clone src dst && |
| 207 | (cd src && |
| 208 | modify s/5/43/ stuff && |
| 209 | git commit -a -m "5->43" && |
| 210 | modify s/6/42/ stuff && |
| 211 | git commit -a -m "Make it bigger" |
| 212 | ) && |
| 213 | (cd dst && |
| 214 | modify s/5/43/ stuff && |
| 215 | git commit -a -m "Independent discovery of 5->43" |
| 216 | ) |
| 217 | ' |
| 218 | |
Elijah Newren | cf65426 | 2010-08-12 19:50:50 -0600 | [diff] [blame] | 219 | test_expect_success 'git pull --rebase detects upstreamed changes' ' |
Elijah Newren | 3cee923 | 2010-08-12 19:50:49 -0600 | [diff] [blame] | 220 | (cd dst && |
| 221 | git pull --rebase && |
| 222 | test -z "$(git ls-files -u)" |
| 223 | ) |
| 224 | ' |
| 225 | |
| 226 | test_expect_success 'setup for avoiding reapplying old patches' ' |
| 227 | (cd dst && |
| 228 | test_might_fail git rebase --abort && |
| 229 | git reset --hard origin/master |
| 230 | ) && |
| 231 | git clone --bare src src-replace.git && |
| 232 | rm -rf src && |
| 233 | mv src-replace.git src && |
| 234 | (cd dst && |
| 235 | modify s/2/22/ stuff && |
| 236 | git commit -a -m "Change 2" && |
| 237 | modify s/3/33/ stuff && |
| 238 | git commit -a -m "Change 3" && |
| 239 | modify s/4/44/ stuff && |
| 240 | git commit -a -m "Change 4" && |
| 241 | git push && |
| 242 | |
| 243 | modify s/44/55/ stuff && |
| 244 | git commit --amend -a -m "Modified Change 4" |
| 245 | ) |
| 246 | ' |
| 247 | |
Elijah Newren | cf65426 | 2010-08-12 19:50:50 -0600 | [diff] [blame] | 248 | test_expect_success 'git pull --rebase does not reapply old patches' ' |
Elijah Newren | 3cee923 | 2010-08-12 19:50:49 -0600 | [diff] [blame] | 249 | (cd dst && |
| 250 | test_must_fail git pull --rebase && |
| 251 | test 1 = $(find .git/rebase-apply -name "000*" | wc -l) |
| 252 | ) |
| 253 | ' |
| 254 | |
Martin von Zweigbergk | fe249b4 | 2010-11-13 23:58:22 +0100 | [diff] [blame] | 255 | test_expect_success 'git pull --rebase against local branch' ' |
| 256 | git checkout -b copy2 to-rebase-orig && |
| 257 | git pull --rebase . to-rebase && |
| 258 | test "conflicting modification" = "$(cat file)" && |
| 259 | test file = "$(cat file2)" |
| 260 | ' |
| 261 | |
Linus Torvalds | d09e79c | 2006-11-16 11:47:22 -0800 | [diff] [blame] | 262 | test_done |