| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='difference in submodules' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | . "$TEST_DIRECTORY"/lib-diff.sh |
| 7 | |
| 8 | test_expect_success setup ' |
| 9 | test_tick && |
| 10 | test_create_repo sub && |
| 11 | ( |
| 12 | cd sub && |
| 13 | echo hello >world && |
| 14 | git add world && |
| 15 | git commit -m submodule |
| 16 | ) && |
| 17 | |
| 18 | test_tick && |
| 19 | echo frotz >nitfol && |
| 20 | git add nitfol sub && |
| 21 | git commit -m superproject && |
| 22 | |
| 23 | ( |
| 24 | cd sub && |
| 25 | echo goodbye >world && |
| 26 | git add world && |
| 27 | git commit -m "submodule #2" |
| 28 | ) && |
| 29 | |
| 30 | git -C sub rev-list HEAD >revs && |
| 31 | set x $(cat revs) && |
| 32 | echo ":160000 160000 $3 $ZERO_OID M sub" >expect && |
| 33 | subtip=$3 subprev=$2 |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'git diff --raw HEAD' ' |
| 37 | hexsz=$(test_oid hexsz) && |
| 38 | git diff --raw --abbrev=$hexsz HEAD >actual && |
| 39 | test_cmp expect actual |
| 40 | ' |
| 41 | |
| 42 | test_expect_success 'git diff-index --raw HEAD' ' |
| 43 | git diff-index --raw HEAD >actual.index && |
| 44 | test_cmp expect actual.index |
| 45 | ' |
| 46 | |
| 47 | test_expect_success 'git diff-files --raw' ' |
| 48 | git diff-files --raw >actual.files && |
| 49 | test_cmp expect actual.files |
| 50 | ' |
| 51 | |
| 52 | expect_from_to () { |
| 53 | printf "%sSubproject commit %s\n+Subproject commit %s\n" \ |
| 54 | "-" "$1" "$2" |
| 55 | } |
| 56 | |
| 57 | test_expect_success 'git diff HEAD' ' |
| 58 | git diff HEAD >actual && |
| 59 | sed -e "1,/^@@/d" actual >actual.body && |
| 60 | expect_from_to >expect.body $subtip $subprev && |
| 61 | test_cmp expect.body actual.body |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'git diff HEAD with dirty submodule (work tree)' ' |
| 65 | echo >>sub/world && |
| 66 | git diff HEAD >actual && |
| 67 | sed -e "1,/^@@/d" actual >actual.body && |
| 68 | expect_from_to >expect.body $subtip $subprev-dirty && |
| 69 | test_cmp expect.body actual.body |
| 70 | ' |
| 71 | |
| 72 | test_expect_success 'git diff HEAD with dirty submodule (index)' ' |
| 73 | ( |
| 74 | cd sub && |
| 75 | git reset --hard && |
| 76 | echo >>world && |
| 77 | git add world |
| 78 | ) && |
| 79 | git diff HEAD >actual && |
| 80 | sed -e "1,/^@@/d" actual >actual.body && |
| 81 | expect_from_to >expect.body $subtip $subprev-dirty && |
| 82 | test_cmp expect.body actual.body |
| 83 | ' |
| 84 | |
| 85 | test_expect_success 'git diff HEAD with dirty submodule (untracked)' ' |
| 86 | ( |
| 87 | cd sub && |
| 88 | git reset --hard && |
| 89 | git clean -qfdx && |
| 90 | >cruft |
| 91 | ) && |
| 92 | git diff HEAD >actual && |
| 93 | sed -e "1,/^@@/d" actual >actual.body && |
| 94 | expect_from_to >expect.body $subtip $subprev && |
| 95 | test_cmp expect.body actual.body |
| 96 | ' |
| 97 | |
| 98 | test_expect_success 'git diff HEAD with dirty submodule (untracked) (none ignored)' ' |
| 99 | test_config diff.ignoreSubmodules none && |
| 100 | git diff HEAD >actual && |
| 101 | sed -e "1,/^@@/d" actual >actual.body && |
| 102 | expect_from_to >expect.body $subtip $subprev-dirty && |
| 103 | test_cmp expect.body actual.body |
| 104 | ' |
| 105 | |
| 106 | test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)' ' |
| 107 | git commit -m "x" sub && |
| 108 | echo >>sub/world && |
| 109 | git diff HEAD >actual && |
| 110 | sed -e "1,/^@@/d" actual >actual.body && |
| 111 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 112 | test_cmp expect.body actual.body && |
| 113 | git diff --ignore-submodules HEAD >actual2 && |
| 114 | test_must_be_empty actual2 && |
| 115 | git diff --ignore-submodules=untracked HEAD >actual3 && |
| 116 | sed -e "1,/^@@/d" actual3 >actual3.body && |
| 117 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 118 | test_cmp expect.body actual3.body && |
| 119 | git diff --ignore-submodules=dirty HEAD >actual4 && |
| 120 | test_must_be_empty actual4 |
| 121 | ' |
| 122 | |
| 123 | test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match) [.gitmodules]' ' |
| 124 | git config diff.ignoreSubmodules dirty && |
| 125 | git diff HEAD >actual && |
| 126 | test_must_be_empty actual && |
| 127 | git config --add -f .gitmodules submodule.subname.ignore none && |
| 128 | git config --add -f .gitmodules submodule.subname.path sub && |
| 129 | git diff HEAD >actual && |
| 130 | sed -e "1,/^@@/d" actual >actual.body && |
| 131 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 132 | test_cmp expect.body actual.body && |
| 133 | git config -f .gitmodules submodule.subname.ignore all && |
| 134 | git config -f .gitmodules submodule.subname.path sub && |
| 135 | git diff HEAD >actual2 && |
| 136 | test_must_be_empty actual2 && |
| 137 | git config -f .gitmodules submodule.subname.ignore untracked && |
| 138 | git diff HEAD >actual3 && |
| 139 | sed -e "1,/^@@/d" actual3 >actual3.body && |
| 140 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 141 | test_cmp expect.body actual3.body && |
| 142 | git config -f .gitmodules submodule.subname.ignore dirty && |
| 143 | git diff HEAD >actual4 && |
| 144 | test_must_be_empty actual4 && |
| 145 | git config submodule.subname.ignore none && |
| 146 | git config submodule.subname.path sub && |
| 147 | git diff HEAD >actual && |
| 148 | sed -e "1,/^@@/d" actual >actual.body && |
| 149 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 150 | test_cmp expect.body actual.body && |
| 151 | git config --remove-section submodule.subname && |
| 152 | git config --remove-section -f .gitmodules submodule.subname && |
| 153 | git config --unset diff.ignoreSubmodules && |
| 154 | rm .gitmodules |
| 155 | ' |
| 156 | |
| 157 | test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' ' |
| 158 | ( |
| 159 | cd sub && |
| 160 | git reset --hard && |
| 161 | echo >>world && |
| 162 | git add world |
| 163 | ) && |
| 164 | git diff HEAD >actual && |
| 165 | sed -e "1,/^@@/d" actual >actual.body && |
| 166 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 167 | test_cmp expect.body actual.body |
| 168 | ' |
| 169 | |
| 170 | test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)' ' |
| 171 | ( |
| 172 | cd sub && |
| 173 | git reset --hard && |
| 174 | git clean -qfdx && |
| 175 | >cruft |
| 176 | ) && |
| 177 | git diff --ignore-submodules=none HEAD >actual && |
| 178 | sed -e "1,/^@@/d" actual >actual.body && |
| 179 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 180 | test_cmp expect.body actual.body && |
| 181 | git diff --ignore-submodules=all HEAD >actual2 && |
| 182 | test_must_be_empty actual2 && |
| 183 | git diff HEAD >actual3 && |
| 184 | test_must_be_empty actual3 && |
| 185 | git diff --ignore-submodules=dirty HEAD >actual4 && |
| 186 | test_must_be_empty actual4 |
| 187 | ' |
| 188 | |
| 189 | test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match) [.gitmodules]' ' |
| 190 | git config --add -f .gitmodules submodule.subname.ignore all && |
| 191 | git config --add -f .gitmodules submodule.subname.path sub && |
| 192 | git diff HEAD >actual2 && |
| 193 | test_must_be_empty actual2 && |
| 194 | git config -f .gitmodules submodule.subname.ignore untracked && |
| 195 | git diff HEAD >actual3 && |
| 196 | test_must_be_empty actual3 && |
| 197 | git config -f .gitmodules submodule.subname.ignore dirty && |
| 198 | git diff HEAD >actual4 && |
| 199 | test_must_be_empty actual4 && |
| 200 | git config submodule.subname.ignore none && |
| 201 | git config submodule.subname.path sub && |
| 202 | git diff HEAD >actual && |
| 203 | sed -e "1,/^@@/d" actual >actual.body && |
| 204 | expect_from_to >expect.body $subprev $subprev-dirty && |
| 205 | test_cmp expect.body actual.body && |
| 206 | git config --remove-section submodule.subname && |
| 207 | git config --remove-section -f .gitmodules submodule.subname && |
| 208 | rm .gitmodules |
| 209 | ' |
| 210 | |
| 211 | test_expect_success 'git diff between submodule commits' ' |
| 212 | git diff HEAD^..HEAD >actual && |
| 213 | sed -e "1,/^@@/d" actual >actual.body && |
| 214 | expect_from_to >expect.body $subtip $subprev && |
| 215 | test_cmp expect.body actual.body && |
| 216 | git diff --ignore-submodules=dirty HEAD^..HEAD >actual && |
| 217 | sed -e "1,/^@@/d" actual >actual.body && |
| 218 | expect_from_to >expect.body $subtip $subprev && |
| 219 | test_cmp expect.body actual.body && |
| 220 | git diff --ignore-submodules HEAD^..HEAD >actual && |
| 221 | test_must_be_empty actual |
| 222 | ' |
| 223 | |
| 224 | test_expect_success 'git diff between submodule commits [.gitmodules]' ' |
| 225 | git diff HEAD^..HEAD >actual && |
| 226 | sed -e "1,/^@@/d" actual >actual.body && |
| 227 | expect_from_to >expect.body $subtip $subprev && |
| 228 | test_cmp expect.body actual.body && |
| 229 | git config --add -f .gitmodules submodule.subname.ignore dirty && |
| 230 | git config --add -f .gitmodules submodule.subname.path sub && |
| 231 | git diff HEAD^..HEAD >actual && |
| 232 | sed -e "1,/^@@/d" actual >actual.body && |
| 233 | expect_from_to >expect.body $subtip $subprev && |
| 234 | test_cmp expect.body actual.body && |
| 235 | git config -f .gitmodules submodule.subname.ignore all && |
| 236 | git diff HEAD^..HEAD >actual && |
| 237 | test_must_be_empty actual && |
| 238 | git config submodule.subname.ignore dirty && |
| 239 | git config submodule.subname.path sub && |
| 240 | git diff HEAD^..HEAD >actual && |
| 241 | sed -e "1,/^@@/d" actual >actual.body && |
| 242 | expect_from_to >expect.body $subtip $subprev && |
| 243 | git config --remove-section submodule.subname && |
| 244 | git config --remove-section -f .gitmodules submodule.subname && |
| 245 | rm .gitmodules |
| 246 | ' |
| 247 | |
| 248 | test_expect_success 'git diff (empty submodule dir)' ' |
| 249 | rm -rf sub/* sub/.git && |
| 250 | git diff > actual.empty && |
| 251 | test_must_be_empty actual.empty |
| 252 | ' |
| 253 | |
| 254 | test_expect_success 'conflicted submodule setup' ' |
| 255 | c=$(test_oid ff_1) && |
| 256 | ( |
| 257 | echo "000000 $ZERO_OID 0 sub" && |
| 258 | echo "160000 1$c 1 sub" && |
| 259 | echo "160000 2$c 2 sub" && |
| 260 | echo "160000 3$c 3 sub" |
| 261 | ) | git update-index --index-info && |
| 262 | echo >expect.nosub "diff --cc sub |
| 263 | index 2ffffff,3ffffff..0000000 |
| 264 | --- a/sub |
| 265 | +++ b/sub |
| 266 | @@@ -1,1 -1,1 +1,1 @@@ |
| 267 | - Subproject commit 2$c |
| 268 | -Subproject commit 3$c |
| 269 | ++Subproject commit $ZERO_OID" && |
| 270 | |
| 271 | hh=$(git rev-parse HEAD) && |
| 272 | sed -e "s/$ZERO_OID/$hh/" expect.nosub >expect.withsub |
| 273 | |
| 274 | ' |
| 275 | |
| 276 | test_expect_success 'combined (empty submodule)' ' |
| 277 | rm -fr sub && mkdir sub && |
| 278 | git diff >actual && |
| 279 | test_cmp expect.nosub actual |
| 280 | ' |
| 281 | |
| 282 | test_expect_success 'combined (with submodule)' ' |
| 283 | rm -fr sub && |
| 284 | git clone --no-checkout . sub && |
| 285 | git diff >actual && |
| 286 | test_cmp expect.withsub actual |
| 287 | ' |
| 288 | |
| 289 | |
| 290 | |
| 291 | test_done |