t / t7401-submodule-summary.shon commit Merge branch 'maint-1.6.6' into maint (d16a5da)
   1#!/bin/sh
   2#
   3# Copyright (c) 2008 Ping Yin
   4#
   5
   6test_description='Summary support for submodules
   7
   8This test tries to verify the sanity of summary subcommand of git submodule.
   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 submodule summary >actual &&
  40        diff actual - <<-EOF
  41* sm1 0000000...$head1 (2):
  42  > Add foo2
  43
  44EOF
  45"
  46
  47commit_file sm1 &&
  48head2=$(add_file sm1 foo3)
  49
  50test_expect_success 'modified submodule(forward)' "
  51        git submodule summary >actual &&
  52        diff actual - <<-EOF
  53* sm1 $head1...$head2 (1):
  54  > Add foo3
  55
  56EOF
  57"
  58
  59test_expect_success 'modified submodule(forward), --files' "
  60        git submodule summary --files >actual &&
  61        diff actual - <<-EOF
  62* sm1 $head1...$head2 (1):
  63  > Add foo3
  64
  65EOF
  66"
  67
  68commit_file sm1 &&
  69cd sm1 &&
  70git reset --hard HEAD~2 >/dev/null &&
  71head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
  72cd ..
  73
  74test_expect_success 'modified submodule(backward)' "
  75    git submodule summary >actual &&
  76    diff actual - <<-EOF
  77* sm1 $head2...$head3 (2):
  78  < Add foo3
  79  < Add foo2
  80
  81EOF
  82"
  83
  84head4=$(add_file sm1 foo4 foo5) &&
  85head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
  86test_expect_success 'modified submodule(backward and forward)' "
  87    git submodule summary >actual &&
  88    diff actual - <<-EOF
  89* sm1 $head2...$head4 (4):
  90  > Add foo5
  91  > Add foo4
  92  < Add foo3
  93  < Add foo2
  94
  95EOF
  96"
  97
  98test_expect_success '--summary-limit' "
  99    git submodule summary -n 3 >actual &&
 100    diff actual - <<-EOF
 101* sm1 $head2...$head4 (4):
 102  > Add foo5
 103  > Add foo4
 104  < Add foo3
 105
 106EOF
 107"
 108
 109commit_file sm1 &&
 110mv sm1 sm1-bak &&
 111echo sm1 >sm1 &&
 112head5=$(git hash-object sm1 | cut -c1-7) &&
 113git add sm1 &&
 114rm -f sm1 &&
 115mv sm1-bak sm1
 116
 117test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 118    git submodule summary --cached >actual &&
 119    diff actual - <<-EOF
 120* sm1 $head4(submodule)->$head5(blob) (3):
 121  < Add foo5
 122
 123EOF
 124"
 125
 126test_expect_success 'typechanged submodule(submodule->blob), --files' "
 127    git submodule summary --files >actual &&
 128    diff actual - <<-EOF
 129* sm1 $head5(blob)->$head4(submodule) (3):
 130  > Add foo5
 131
 132EOF
 133"
 134
 135rm -rf sm1 &&
 136git checkout-index sm1
 137test_expect_success 'typechanged submodule(submodule->blob)' "
 138    git submodule summary >actual &&
 139    diff actual - <<-EOF
 140* sm1 $head4(submodule)->$head5(blob):
 141
 142EOF
 143"
 144
 145rm -f sm1 &&
 146test_create_repo sm1 &&
 147head6=$(add_file sm1 foo6 foo7)
 148test_expect_success 'nonexistent commit' "
 149    git submodule summary >actual &&
 150    diff actual - <<-EOF
 151* sm1 $head4...$head6:
 152  Warn: sm1 doesn't contain commit $head4_full
 153
 154EOF
 155"
 156
 157commit_file
 158test_expect_success 'typechanged submodule(blob->submodule)' "
 159    git submodule summary >actual &&
 160    diff actual - <<-EOF
 161* sm1 $head5(blob)->$head6(submodule) (2):
 162  > Add foo7
 163
 164EOF
 165"
 166
 167commit_file sm1 &&
 168rm -rf sm1
 169test_expect_success 'deleted submodule' "
 170    git submodule summary >actual &&
 171    diff actual - <<-EOF
 172* sm1 $head6...0000000:
 173
 174EOF
 175"
 176
 177test_create_repo sm2 &&
 178head7=$(add_file sm2 foo8 foo9) &&
 179git add sm2
 180
 181test_expect_success 'multiple submodules' "
 182    git submodule summary >actual &&
 183    diff actual - <<-EOF
 184* sm1 $head6...0000000:
 185
 186* sm2 0000000...$head7 (2):
 187  > Add foo9
 188
 189EOF
 190"
 191
 192test_expect_success 'path filter' "
 193    git submodule summary sm2 >actual &&
 194    diff actual - <<-EOF
 195* sm2 0000000...$head7 (2):
 196  > Add foo9
 197
 198EOF
 199"
 200
 201commit_file sm2
 202test_expect_success 'given commit' "
 203    git submodule summary HEAD^ >actual &&
 204    diff actual - <<-EOF
 205* sm1 $head6...0000000:
 206
 207* sm2 0000000...$head7 (2):
 208  > Add foo9
 209
 210EOF
 211"
 212
 213test_expect_success '--for-status' "
 214    git submodule summary --for-status HEAD^ >actual &&
 215    test_cmp actual - <<EOF
 216# Submodule changes to be committed:
 217#
 218# * sm1 $head6...0000000:
 219#
 220# * sm2 0000000...$head7 (2):
 221#   > Add foo9
 222#
 223EOF
 224"
 225
 226test_expect_success 'fail when using --files together with --cached' "
 227    test_must_fail git submodule summary --files --cached
 228"
 229
 230test_done