t / t4041-diff-submodule-option.shon commit Add global and system-wide gitattributes (6df42ab)
   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 &&
  88cd sm1 &&
  89git reset --hard HEAD~2 >/dev/null &&
  90head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
  91cd ..
  92
  93test_expect_success 'modified submodule(backward)' "
  94        git diff-index -p --submodule=log HEAD >actual &&
  95        diff actual - <<-EOF
  96Submodule sm1 $head2..$head3 (rewind):
  97  < Add foo3
  98  < Add foo2
  99EOF
 100"
 101
 102head4=$(add_file sm1 foo4 foo5) &&
 103head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
 104test_expect_success 'modified submodule(backward and forward)' "
 105        git diff-index -p --submodule=log HEAD >actual &&
 106        diff actual - <<-EOF
 107Submodule sm1 $head2...$head4:
 108  > Add foo5
 109  > Add foo4
 110  < Add foo3
 111  < Add foo2
 112EOF
 113"
 114
 115commit_file sm1 &&
 116mv sm1 sm1-bak &&
 117echo sm1 >sm1 &&
 118head5=$(git hash-object sm1 | cut -c1-7) &&
 119git add sm1 &&
 120rm -f sm1 &&
 121mv sm1-bak sm1
 122
 123test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 124        git diff --submodule=log --cached >actual &&
 125        diff actual - <<-EOF
 126Submodule sm1 41fbea9...0000000 (submodule deleted)
 127diff --git a/sm1 b/sm1
 128new file mode 100644
 129index 0000000..9da5fb8
 130--- /dev/null
 131+++ b/sm1
 132@@ -0,0 +1 @@
 133+sm1
 134EOF
 135"
 136
 137test_expect_success 'typechanged submodule(submodule->blob)' "
 138        git diff --submodule=log >actual &&
 139        diff actual - <<-EOF
 140diff --git a/sm1 b/sm1
 141deleted file mode 100644
 142index 9da5fb8..0000000
 143--- a/sm1
 144+++ /dev/null
 145@@ -1 +0,0 @@
 146-sm1
 147Submodule sm1 0000000...$head4 (new submodule)
 148EOF
 149"
 150
 151rm -rf sm1 &&
 152git checkout-index sm1
 153test_expect_success 'typechanged submodule(submodule->blob)' "
 154        git diff-index -p --submodule=log HEAD >actual &&
 155        diff actual - <<-EOF
 156Submodule sm1 $head4...0000000 (submodule deleted)
 157diff --git a/sm1 b/sm1
 158new file mode 100644
 159index 0000000..$head5
 160--- /dev/null
 161+++ b/sm1
 162@@ -0,0 +1 @@
 163+sm1
 164EOF
 165"
 166
 167rm -f sm1 &&
 168test_create_repo sm1 &&
 169head6=$(add_file sm1 foo6 foo7)
 170fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
 171test_expect_success 'nonexistent commit' "
 172        git diff-index -p --submodule=log HEAD >actual &&
 173        diff actual - <<-EOF
 174Submodule sm1 $head4...$head6 (commits not present)
 175EOF
 176"
 177
 178commit_file
 179test_expect_success 'typechanged submodule(blob->submodule)' "
 180        git diff-index -p --submodule=log HEAD >actual &&
 181        diff actual - <<-EOF
 182diff --git a/sm1 b/sm1
 183deleted file mode 100644
 184index $head5..0000000
 185--- a/sm1
 186+++ /dev/null
 187@@ -1 +0,0 @@
 188-sm1
 189Submodule sm1 0000000...$head6 (new submodule)
 190EOF
 191"
 192
 193commit_file sm1 &&
 194test_expect_success 'submodule is up to date' "
 195        git diff-index -p --submodule=log HEAD >actual &&
 196        diff actual - <<-EOF
 197EOF
 198"
 199
 200test_expect_success 'submodule contains untracked content' "
 201        echo new > sm1/new-file &&
 202        git diff-index -p --submodule=log HEAD >actual &&
 203        diff actual - <<-EOF
 204Submodule sm1 contains untracked content
 205EOF
 206"
 207
 208test_expect_success 'submodule contains untracked content (untracked ignored)' "
 209        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 210        ! test -s actual
 211"
 212
 213test_expect_success 'submodule contains untracked content (dirty ignored)' "
 214        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 215        ! test -s actual
 216"
 217
 218test_expect_success 'submodule contains untracked content (all ignored)' "
 219        git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
 220        ! test -s actual
 221"
 222
 223test_expect_success 'submodule contains untracked and modifed content' "
 224        echo new > sm1/foo6 &&
 225        git diff-index -p --submodule=log HEAD >actual &&
 226        diff actual - <<-EOF
 227Submodule sm1 contains untracked content
 228Submodule sm1 contains modified content
 229EOF
 230"
 231
 232test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
 233        echo new > sm1/foo6 &&
 234        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 235        diff actual - <<-EOF
 236Submodule sm1 contains modified content
 237EOF
 238"
 239
 240test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
 241        echo new > sm1/foo6 &&
 242        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 243        ! test -s actual
 244"
 245
 246test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
 247        echo new > sm1/foo6 &&
 248        git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
 249        ! test -s actual
 250"
 251
 252test_expect_success 'submodule contains modifed content' "
 253        rm -f sm1/new-file &&
 254        git diff-index -p --submodule=log HEAD >actual &&
 255        diff actual - <<-EOF
 256Submodule sm1 contains modified content
 257EOF
 258"
 259
 260(cd sm1; git commit -mchange foo6 >/dev/null) &&
 261head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
 262test_expect_success 'submodule is modified' "
 263        git diff-index -p --submodule=log HEAD >actual &&
 264        diff actual - <<-EOF
 265Submodule sm1 $head6..$head8:
 266  > change
 267EOF
 268"
 269
 270test_expect_success 'modified submodule contains untracked content' "
 271        echo new > sm1/new-file &&
 272        git diff-index -p --submodule=log HEAD >actual &&
 273        diff actual - <<-EOF
 274Submodule sm1 contains untracked content
 275Submodule sm1 $head6..$head8:
 276  > change
 277EOF
 278"
 279
 280test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
 281        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 282        diff actual - <<-EOF
 283Submodule sm1 $head6..$head8:
 284  > change
 285EOF
 286"
 287
 288test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
 289        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 290        diff actual - <<-EOF
 291Submodule sm1 $head6..$head8:
 292  > change
 293EOF
 294"
 295
 296test_expect_success 'modified submodule contains untracked content (all ignored)' "
 297        git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
 298        ! test -s actual
 299"
 300
 301test_expect_success 'modified submodule contains untracked and modifed content' "
 302        echo modification >> sm1/foo6 &&
 303        git diff-index -p --submodule=log HEAD >actual &&
 304        diff actual - <<-EOF
 305Submodule sm1 contains untracked content
 306Submodule sm1 contains modified content
 307Submodule sm1 $head6..$head8:
 308  > change
 309EOF
 310"
 311
 312test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
 313        echo modification >> sm1/foo6 &&
 314        git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
 315        diff actual - <<-EOF
 316Submodule sm1 contains modified content
 317Submodule sm1 $head6..$head8:
 318  > change
 319EOF
 320"
 321
 322test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
 323        echo modification >> sm1/foo6 &&
 324        git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
 325        diff actual - <<-EOF
 326Submodule sm1 $head6..$head8:
 327  > change
 328EOF
 329"
 330
 331test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
 332        echo modification >> sm1/foo6 &&
 333        git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
 334        ! test -s actual
 335"
 336
 337test_expect_success 'modified submodule contains modifed content' "
 338        rm -f sm1/new-file &&
 339        git diff-index -p --submodule=log HEAD >actual &&
 340        diff actual - <<-EOF
 341Submodule sm1 contains modified content
 342Submodule sm1 $head6..$head8:
 343  > change
 344EOF
 345"
 346
 347rm -rf sm1
 348test_expect_success 'deleted submodule' "
 349        git diff-index -p --submodule=log HEAD >actual &&
 350        diff actual - <<-EOF
 351Submodule sm1 $head6...0000000 (submodule deleted)
 352EOF
 353"
 354
 355test_create_repo sm2 &&
 356head7=$(add_file sm2 foo8 foo9) &&
 357git add sm2
 358
 359test_expect_success 'multiple submodules' "
 360        git diff-index -p --submodule=log HEAD >actual &&
 361        diff actual - <<-EOF
 362Submodule sm1 $head6...0000000 (submodule deleted)
 363Submodule sm2 0000000...$head7 (new submodule)
 364EOF
 365"
 366
 367test_expect_success 'path filter' "
 368        git diff-index -p --submodule=log HEAD sm2 >actual &&
 369        diff actual - <<-EOF
 370Submodule sm2 0000000...$head7 (new submodule)
 371EOF
 372"
 373
 374commit_file sm2
 375test_expect_success 'given commit' "
 376        git diff-index -p --submodule=log HEAD^ >actual &&
 377        diff actual - <<-EOF
 378Submodule sm1 $head6...0000000 (submodule deleted)
 379Submodule sm2 0000000...$head7 (new submodule)
 380EOF
 381"
 382
 383test_expect_success 'given commit --submodule' "
 384        git diff-index -p --submodule HEAD^ >actual &&
 385        diff actual - <<-EOF
 386Submodule sm1 $head6...0000000 (submodule deleted)
 387Submodule sm2 0000000...$head7 (new submodule)
 388EOF
 389"
 390
 391fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
 392
 393test_expect_success 'given commit --submodule=short' "
 394        git diff-index -p --submodule=short HEAD^ >actual &&
 395        diff actual - <<-EOF
 396diff --git a/sm1 b/sm1
 397deleted file mode 160000
 398index $head6..0000000
 399--- a/sm1
 400+++ /dev/null
 401@@ -1 +0,0 @@
 402-Subproject commit $fullhead6
 403diff --git a/sm2 b/sm2
 404new file mode 160000
 405index 0000000..$head7
 406--- /dev/null
 407+++ b/sm2
 408@@ -0,0 +1 @@
 409+Subproject commit $fullhead7
 410EOF
 411"
 412
 413test_expect_success 'setup .git file for sm2' '
 414        (cd sm2 &&
 415         REAL="$(pwd)/../.real" &&
 416         mv .git "$REAL"
 417         echo "gitdir: $REAL" >.git)
 418'
 419
 420test_expect_success 'diff --submodule with .git file' '
 421        git diff --submodule HEAD^ >actual &&
 422        diff actual - <<-EOF
 423Submodule sm1 $head6...0000000 (submodule deleted)
 424Submodule sm2 0000000...$head7 (new submodule)
 425EOF
 426'
 427
 428test_done