Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2007 Lars Hjemli |
| 4 | # |
| 5 | |
| 6 | test_description='Basic porcelain support for submodules |
| 7 | |
| 8 | This test tries to verify basic sanity of the init, update and status |
| 9 | subcommands of git-submodule. |
| 10 | ' |
| 11 | |
| 12 | . ./test-lib.sh |
| 13 | |
| 14 | # |
| 15 | # Test setup: |
| 16 | # -create a repository in directory lib |
| 17 | # -add a couple of files |
| 18 | # -add directory lib to 'superproject', this creates a DIRLINK entry |
| 19 | # -add a couple of regular files to enable testing of submodule filtering |
| 20 | # -mv lib subrepo |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 21 | # -add an entry to .gitmodules for submodule 'example' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 22 | # |
| 23 | test_expect_success 'Prepare submodule testing' ' |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 24 | : > t && |
| 25 | git-add t && |
| 26 | git-commit -m "initial commit" && |
| 27 | git branch initial HEAD && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 28 | mkdir lib && |
| 29 | cd lib && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 30 | git init && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 31 | echo a >a && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 32 | git add a && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 33 | git-commit -m "submodule commit 1" && |
| 34 | git-tag -a -m "rev-1" rev-1 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 35 | rev1=$(git rev-parse HEAD) && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 36 | if test -z "$rev1" |
| 37 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 38 | echo "[OOPS] submodule git rev-parse returned nothing" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 39 | false |
| 40 | fi && |
| 41 | cd .. && |
| 42 | echo a >a && |
| 43 | echo z >z && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 44 | git add a lib z && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 45 | git-commit -m "super commit 1" && |
| 46 | mv lib .subrepo && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 47 | GIT_CONFIG=.gitmodules git config submodule.example.url git://example.com/lib.git |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 48 | ' |
| 49 | |
| 50 | test_expect_success 'status should fail for unmapped paths' ' |
| 51 | if git-submodule status |
| 52 | then |
| 53 | echo "[OOPS] submodule status succeeded" |
| 54 | false |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 55 | elif ! GIT_CONFIG=.gitmodules git config submodule.example.path lib |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 56 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 57 | echo "[OOPS] git config failed to update .gitmodules" |
Lars Hjemli | 941987a | 2007-06-11 21:12:24 +0200 | [diff] [blame] | 58 | false |
| 59 | fi |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 60 | ' |
| 61 | |
| 62 | test_expect_success 'status should only print one line' ' |
| 63 | lines=$(git-submodule status | wc -l) && |
| 64 | test $lines = 1 |
| 65 | ' |
| 66 | |
| 67 | test_expect_success 'status should initially be "missing"' ' |
| 68 | git-submodule status | grep "^-$rev1" |
| 69 | ' |
| 70 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 71 | test_expect_success 'init should register submodule url in .git/config' ' |
| 72 | git-submodule init && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 73 | url=$(git config submodule.example.url) && |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 74 | if test "$url" != "git://example.com/lib.git" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 75 | then |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 76 | echo "[OOPS] init succeeded but submodule url is wrong" |
| 77 | false |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 78 | elif ! git config submodule.example.url ./.subrepo |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 79 | then |
| 80 | echo "[OOPS] init succeeded but update of url failed" |
| 81 | false |
| 82 | fi |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'update should fail when path is used by a file' ' |
| 86 | echo "hello" >lib && |
| 87 | if git-submodule update |
| 88 | then |
| 89 | echo "[OOPS] update should have failed" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 90 | false |
Lars Hjemli | b10ee76 | 2007-06-11 21:12:21 +0200 | [diff] [blame] | 91 | elif test "$(cat lib)" != "hello" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 92 | then |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 93 | echo "[OOPS] update failed but lib file was molested" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 94 | false |
| 95 | else |
| 96 | rm lib |
| 97 | fi |
| 98 | ' |
| 99 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 100 | test_expect_success 'update should fail when path is used by a nonempty directory' ' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 101 | mkdir lib && |
| 102 | echo "hello" >lib/a && |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 103 | if git-submodule update |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 104 | then |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 105 | echo "[OOPS] update should have failed" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 106 | false |
| 107 | elif test "$(cat lib/a)" != "hello" |
| 108 | then |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 109 | echo "[OOPS] update failed but lib/a was molested" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 110 | false |
| 111 | else |
| 112 | rm lib/a |
| 113 | fi |
| 114 | ' |
| 115 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 116 | test_expect_success 'update should work when path is an empty dir' ' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 117 | rm -rf lib && |
| 118 | mkdir lib && |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 119 | git-submodule update && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 120 | head=$(cd lib && git rev-parse HEAD) && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 121 | if test -z "$head" |
| 122 | then |
| 123 | echo "[OOPS] Failed to obtain submodule head" |
| 124 | false |
| 125 | elif test "$head" != "$rev1" |
| 126 | then |
| 127 | echo "[OOPS] Submodule head is $head but should have been $rev1" |
| 128 | false |
| 129 | fi |
| 130 | ' |
| 131 | |
Lars Hjemli | 211b7f1 | 2007-06-06 11:13:02 +0200 | [diff] [blame] | 132 | test_expect_success 'status should be "up-to-date" after update' ' |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 133 | git-submodule status | grep "^ $rev1" |
| 134 | ' |
| 135 | |
| 136 | test_expect_success 'status should be "modified" after submodule commit' ' |
| 137 | cd lib && |
| 138 | echo b >b && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 139 | git add b && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 140 | git-commit -m "submodule commit 2" && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 141 | rev2=$(git rev-parse HEAD) && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 142 | cd .. && |
| 143 | if test -z "$rev2" |
| 144 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 145 | echo "[OOPS] submodule git rev-parse returned nothing" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 146 | false |
| 147 | fi && |
| 148 | git-submodule status | grep "^+$rev2" |
| 149 | ' |
| 150 | |
| 151 | test_expect_success 'the --cached sha1 should be rev1' ' |
| 152 | git-submodule --cached status | grep "^+$rev1" |
| 153 | ' |
| 154 | |
| 155 | test_expect_success 'update should checkout rev1' ' |
| 156 | git-submodule update && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 157 | head=$(cd lib && git rev-parse HEAD) && |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 158 | if test -z "$head" |
| 159 | then |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 160 | echo "[OOPS] submodule git rev-parse returned nothing" |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 161 | false |
| 162 | elif test "$head" != "$rev1" |
| 163 | then |
| 164 | echo "[OOPS] init did not checkout correct head" |
| 165 | false |
| 166 | fi |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'status should be "up-to-date" after update' ' |
| 170 | git-submodule status | grep "^ $rev1" |
| 171 | ' |
| 172 | |
Sven Verdoolaege | 0cf7375 | 2007-07-17 20:28:28 +0200 | [diff] [blame] | 173 | test_expect_success 'checkout superproject with subproject already present' ' |
| 174 | git-checkout initial && |
| 175 | git-checkout master |
| 176 | ' |
| 177 | |
Sven Verdoolaege | e06c5a6 | 2007-08-15 19:22:09 +0200 | [diff] [blame] | 178 | test_expect_success 'apply submodule diff' ' |
| 179 | git branch second && |
| 180 | ( |
| 181 | cd lib && |
| 182 | echo s >s && |
| 183 | git add s && |
| 184 | git commit -m "change subproject" |
| 185 | ) && |
| 186 | git update-index --add lib && |
| 187 | git-commit -m "change lib" && |
| 188 | git-format-patch -1 --stdout >P.diff && |
| 189 | git checkout second && |
| 190 | git apply --index P.diff && |
| 191 | D=$(git diff --cached master) && |
| 192 | test -z "$D" |
| 193 | ' |
| 194 | |
Lars Hjemli | 88961ef | 2007-06-02 03:27:42 +0200 | [diff] [blame] | 195 | test_done |