t / t4041-diff-submodule-option.shon commit gitweb/Makefile: Add 'test' and 'test-installed' targets (958a846)
   1#!/bin/sh
   2#
   3# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
   4#
   5
   6test_description='Support for verbose submodule differences in git diff
   7
   8This test tries to verify the sanity of the --submodule option of git diff.
   9'
  10
  11. ./test-lib.sh
  12
  13add_file () {
  14        sm=$1
  15        shift
  16        owd=$(pwd)
  17        cd "$sm"
  18        for name; do
  19                echo "$name" > "$name" &&
  20                git add "$name" &&
  21                test_tick &&
  22                git commit -m "Add $name"
  23        done >/dev/null
  24        git rev-parse --verify HEAD | cut -c1-7
  25        cd "$owd"
  26}
  27commit_file () {
  28        test_tick &&
  29        git commit "$@" -m "Commit $*" >/dev/null
  30}
  31
  32test_create_repo sm1 &&
  33add_file . foo >/dev/null
  34
  35head1=$(add_file sm1 foo1 foo2)
  36
  37test_expect_success 'added submodule' "
  38        git add sm1 &&
  39        git diff-index -p --submodule=log HEAD >actual &&
  40        diff actual - <<-EOF
  41Submodule sm1 0000000...$head1 (new submodule)
  42EOF
  43"
  44
  45commit_file sm1 &&
  46head2=$(add_file sm1 foo3)
  47
  48test_expect_success 'modified submodule(forward)' "
  49        git diff-index -p --submodule=log HEAD >actual &&
  50        diff actual - <<-EOF
  51Submodule sm1 $head1..$head2:
  52  > Add foo3
  53EOF
  54"
  55
  56test_expect_success 'modified submodule(forward)' "
  57        git diff --submodule=log >actual &&
  58        diff actual - <<-EOF
  59Submodule sm1 $head1..$head2:
  60  > Add foo3
  61EOF
  62"
  63
  64test_expect_success 'modified submodule(forward) --submodule' "
  65        git diff --submodule >actual &&
  66        diff actual - <<-EOF
  67Submodule sm1 $head1..$head2:
  68  > Add foo3
  69EOF
  70"
  71
  72fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
  73fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
  74test_expect_success 'modified submodule(forward) --submodule=short' "
  75        git diff --submodule=short >actual &&
  76        diff actual - <<-EOF
  77diff --git a/sm1 b/sm1
  78index $head1..$head2 160000
  79--- a/sm1
  80+++ b/sm1
  81@@ -1 +1 @@
  82-Subproject commit $fullhead1
  83+Subproject commit $fullhead2
  84EOF
  85"
  86
  87commit_file sm1 &&
  88head3=$(
  89        cd sm1 &&
  90        git reset --hard HEAD~2 >/dev/null &&
  91        git rev-parse --verify HEAD | cut -c1-7
  92)
  93
  94test_expect_success 'modified submodule(backward)' "
  95        git diff-index -p --submodule=log HEAD >actual &&
  96        diff actual - <<-EOF
  97Submodule sm1 $head2..$head3 (rewind):
  98  < Add foo3
  99  < Add foo2
 100EOF
 101"
 102
 103head4=$(add_file sm1 foo4 foo5) &&
 104head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
 105test_expect_success 'modified submodule(backward and forward)' "
 106        git diff-index -p --submodule=log HEAD >actual &&
 107        diff actual - <<-EOF
 108Submodule sm1 $head2...$head4:
 109  > Add foo5
 110  > Add foo4
 111  < Add foo3
 112  < Add foo2
 113EOF
 114"
 115
 116commit_file sm1 &&
 117mv sm1 sm1-bak &&
 118echo sm1 >sm1 &&
 119head5=$(git hash-object sm1 | cut -c1-7) &&
 120git add sm1 &&
 121rm -f sm1 &&
 122mv sm1-bak sm1
 123
 124test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 125        git diff --submodule=log --cached >actual &&
 126        diff actual - <<-EOF
 127Submodule sm1 41fbea9...0000000 (submodule deleted)
 128diff --git a/sm1 b/sm1
 129new file mode 100644
 130index 0000000..9da5fb8
 131--- /dev/null
 132+++ b/sm1
 133@@ -0,0 +1 @@
 134+sm1
 135EOF
 136"
 137
 138test_expect_success 'typechanged submodule(submodule->blob)' "
 139        git diff --submodule=log >actual &&
 140        diff actual - <<-EOF
 141diff --git a/sm1 b/sm1
 142deleted file mode 100644
 143index 9da5fb8..0000000
 144--- a/sm1
 145+++ /dev/null
 146@@ -1 +0,0 @@
 147-sm1
 148Submodule sm1 0000000...$head4 (new submodule)
 149EOF
 150"
 151
 152rm -rf sm1 &&
 153git checkout-index sm1
 154test_expect_success 'typechanged submodule(submodule->blob)' "
 155        git diff-index -p --submodule=log HEAD >actual &&
 156        diff actual - <<-EOF
 157Submodule sm1 $head4...0000000 (submodule deleted)
 158diff --git a/sm1 b/sm1
 159new file mode 100644
 160index 0000000..$head5
 161--- /dev/null
 162+++ b/sm1
 163@@ -0,0 +1 @@
 164+sm1
 165EOF
 166"
 167
 168rm -f sm1 &&
 169test_create_repo sm1 &&
 170head6=$(add_file sm1 foo6 foo7)
 171fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
 172test_expect_success 'nonexistent commit' "
 173        git diff-index -p --submodule=log HEAD >actual &&
 174        diff actual - <<-EOF
 175Submodule sm1 $head4...$head6 (commits not present)
 176EOF
 177"
 178
 179commit_file
 180test_expect_success 'typechanged submodule(blob->submodule)' "
 181        git diff-index -p --submodule=log HEAD >actual &&
 182        diff actual - <<-EOF
 183diff --git a/sm1 b/sm1
 184deleted file mode 100644
 185index $head5..0000000
 186--- a/sm1
 187+++ /dev/null
 188@@ -1 +0,0 @@
 189-sm1
 190Submodule sm1 0000000...$head6 (new submodule)
 191EOF
 192"
 193
 194commit_file sm1 &&
 195test_expect_success 'submodule is up to date' "
 196        git diff-index -p --submodule=log HEAD >actual &&
 197        diff actual - <<-EOF
 198EOF
 199"
 200
 201test_expect_success 'submodule contains untracked content' "
 202        echo new > sm1/new-file &&
 203        git diff-index -p --submodule=log HEAD >actual &&
 204        diff actual - <<-EOF
 205Submodule sm1 contains untracked content
 206EOF
 207"
 208
 209test_expect_success 'submodule contains untracked content (untracked ignored)' "
 210        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 211        ! test -s actual
 212"
 213
 214test_expect_success 'submodule contains untracked content (dirty ignored)' "
 215        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 216        ! test -s actual
 217"
 218
 219test_expect_success 'submodule contains untracked content (all ignored)' "
 220        git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
 221        ! test -s actual
 222"
 223
 224test_expect_success 'submodule contains untracked and modifed content' "
 225        echo new > sm1/foo6 &&
 226        git diff-index -p --submodule=log HEAD >actual &&
 227        diff actual - <<-EOF
 228Submodule sm1 contains untracked content
 229Submodule sm1 contains modified content
 230EOF
 231"
 232
 233test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
 234        echo new > sm1/foo6 &&
 235        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 236        diff actual - <<-EOF
 237Submodule sm1 contains modified content
 238EOF
 239"
 240
 241test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
 242        echo new > sm1/foo6 &&
 243        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 244        ! test -s actual
 245"
 246
 247test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
 248        echo new > sm1/foo6 &&
 249        git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
 250        ! test -s actual
 251"
 252
 253test_expect_success 'submodule contains modifed content' "
 254        rm -f sm1/new-file &&
 255        git diff-index -p --submodule=log HEAD >actual &&
 256        diff actual - <<-EOF
 257Submodule sm1 contains modified content
 258EOF
 259"
 260
 261(cd sm1; git commit -mchange foo6 >/dev/null) &&
 262head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
 263test_expect_success 'submodule is modified' "
 264        git diff-index -p --submodule=log HEAD >actual &&
 265        diff actual - <<-EOF
 266Submodule sm1 $head6..$head8:
 267  > change
 268EOF
 269"
 270
 271test_expect_success 'modified submodule contains untracked content' "
 272        echo new > sm1/new-file &&
 273        git diff-index -p --submodule=log HEAD >actual &&
 274        diff actual - <<-EOF
 275Submodule sm1 contains untracked content
 276Submodule sm1 $head6..$head8:
 277  > change
 278EOF
 279"
 280
 281test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
 282        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 283        diff actual - <<-EOF
 284Submodule sm1 $head6..$head8:
 285  > change
 286EOF
 287"
 288
 289test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
 290        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 291        diff actual - <<-EOF
 292Submodule sm1 $head6..$head8:
 293  > change
 294EOF
 295"
 296
 297test_expect_success 'modified submodule contains untracked content (all ignored)' "
 298        git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
 299        ! test -s actual
 300"
 301
 302test_expect_success 'modified submodule contains untracked and modifed content' "
 303        echo modification >> sm1/foo6 &&
 304        git diff-index -p --submodule=log HEAD >actual &&
 305        diff actual - <<-EOF
 306Submodule sm1 contains untracked content
 307Submodule sm1 contains modified content
 308Submodule sm1 $head6..$head8:
 309  > change
 310EOF
 311"
 312
 313test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
 314        echo modification >> sm1/foo6 &&
 315        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 316        diff actual - <<-EOF
 317Submodule sm1 contains modified content
 318Submodule sm1 $head6..$head8:
 319  > change
 320EOF
 321"
 322
 323test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
 324        echo modification >> sm1/foo6 &&
 325        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 326        diff actual - <<-EOF
 327Submodule sm1 $head6..$head8:
 328  > change
 329EOF
 330"
 331
 332test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
 333        echo modification >> sm1/foo6 &&
 334        git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
 335        ! test -s actual
 336"
 337
 338test_expect_success 'modified submodule contains modifed content' "
 339        rm -f sm1/new-file &&
 340        git diff-index -p --submodule=log HEAD >actual &&
 341        diff actual - <<-EOF
 342Submodule sm1 contains modified content
 343Submodule sm1 $head6..$head8:
 344  > change
 345EOF
 346"
 347
 348rm -rf sm1
 349test_expect_success 'deleted submodule' "
 350        git diff-index -p --submodule=log HEAD >actual &&
 351        diff actual - <<-EOF
 352Submodule sm1 $head6...0000000 (submodule deleted)
 353EOF
 354"
 355
 356test_create_repo sm2 &&
 357head7=$(add_file sm2 foo8 foo9) &&
 358git add sm2
 359
 360test_expect_success 'multiple submodules' "
 361        git diff-index -p --submodule=log HEAD >actual &&
 362        diff actual - <<-EOF
 363Submodule sm1 $head6...0000000 (submodule deleted)
 364Submodule sm2 0000000...$head7 (new submodule)
 365EOF
 366"
 367
 368test_expect_success 'path filter' "
 369        git diff-index -p --submodule=log HEAD sm2 >actual &&
 370        diff actual - <<-EOF
 371Submodule sm2 0000000...$head7 (new submodule)
 372EOF
 373"
 374
 375commit_file sm2
 376test_expect_success 'given commit' "
 377        git diff-index -p --submodule=log HEAD^ >actual &&
 378        diff actual - <<-EOF
 379Submodule sm1 $head6...0000000 (submodule deleted)
 380Submodule sm2 0000000...$head7 (new submodule)
 381EOF
 382"
 383
 384test_expect_success 'given commit --submodule' "
 385        git diff-index -p --submodule HEAD^ >actual &&
 386        diff actual - <<-EOF
 387Submodule sm1 $head6...0000000 (submodule deleted)
 388Submodule sm2 0000000...$head7 (new submodule)
 389EOF
 390"
 391
 392fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
 393
 394test_expect_success 'given commit --submodule=short' "
 395        git diff-index -p --submodule=short HEAD^ >actual &&
 396        diff actual - <<-EOF
 397diff --git a/sm1 b/sm1
 398deleted file mode 160000
 399index $head6..0000000
 400--- a/sm1
 401+++ /dev/null
 402@@ -1 +0,0 @@
 403-Subproject commit $fullhead6
 404diff --git a/sm2 b/sm2
 405new file mode 160000
 406index 0000000..$head7
 407--- /dev/null
 408+++ b/sm2
 409@@ -0,0 +1 @@
 410+Subproject commit $fullhead7
 411EOF
 412"
 413
 414test_expect_success 'setup .git file for sm2' '
 415        (cd sm2 &&
 416         REAL="$(pwd)/../.real" &&
 417         mv .git "$REAL"
 418         echo "gitdir: $REAL" >.git)
 419'
 420
 421test_expect_success 'diff --submodule with .git file' '
 422        git diff --submodule HEAD^ >actual &&
 423        diff actual - <<-EOF
 424Submodule sm1 $head6...0000000 (submodule deleted)
 425Submodule sm2 0000000...$head7 (new submodule)
 426EOF
 427'
 428
 429test_done