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