t / t7401-submodule-summary.shon commit test scripts: refactor start_httpd helper (75318a3)
   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
  59commit_file sm1 &&
  60cd sm1 &&
  61git reset --hard HEAD~2 >/dev/null &&
  62head3=$(git rev-parse --verify HEAD | cut -c1-7) &&
  63cd ..
  64
  65test_expect_success 'modified submodule(backward)' "
  66    git submodule summary >actual &&
  67    diff actual - <<-EOF
  68* sm1 $head2...$head3 (2):
  69  < Add foo3
  70  < Add foo2
  71
  72EOF
  73"
  74
  75head4=$(add_file sm1 foo4 foo5) &&
  76head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
  77test_expect_success 'modified submodule(backward and forward)' "
  78    git submodule summary >actual &&
  79    diff actual - <<-EOF
  80* sm1 $head2...$head4 (4):
  81  > Add foo5
  82  > Add foo4
  83  < Add foo3
  84  < Add foo2
  85
  86EOF
  87"
  88
  89test_expect_success '--summary-limit' "
  90    git submodule summary -n 3 >actual &&
  91    diff actual - <<-EOF
  92* sm1 $head2...$head4 (4):
  93  > Add foo5
  94  > Add foo4
  95  < Add foo3
  96
  97EOF
  98"
  99
 100commit_file sm1 &&
 101mv sm1 sm1-bak &&
 102echo sm1 >sm1 &&
 103head5=$(git hash-object sm1 | cut -c1-7) &&
 104git add sm1 &&
 105rm -f sm1 &&
 106mv sm1-bak sm1
 107
 108test_expect_success 'typechanged submodule(submodule->blob), --cached' "
 109    git submodule summary --cached >actual &&
 110    diff actual - <<-EOF
 111* sm1 $head4(submodule)->$head5(blob) (3):
 112  < Add foo5
 113
 114EOF
 115"
 116
 117rm -rf sm1 &&
 118git checkout-index sm1
 119test_expect_success 'typechanged submodule(submodule->blob)' "
 120    git submodule summary >actual &&
 121    diff actual - <<-EOF
 122* sm1 $head4(submodule)->$head5(blob):
 123
 124EOF
 125"
 126
 127rm -f sm1 &&
 128test_create_repo sm1 &&
 129head6=$(add_file sm1 foo6 foo7)
 130test_expect_success 'nonexistent commit' "
 131    git submodule summary >actual &&
 132    diff actual - <<-EOF
 133* sm1 $head4...$head6:
 134  Warn: sm1 doesn't contain commit $head4_full
 135
 136EOF
 137"
 138
 139commit_file
 140test_expect_success 'typechanged submodule(blob->submodule)' "
 141    git submodule summary >actual &&
 142    diff actual - <<-EOF
 143* sm1 $head5(blob)->$head6(submodule) (2):
 144  > Add foo7
 145
 146EOF
 147"
 148
 149commit_file sm1 &&
 150rm -rf sm1
 151test_expect_success 'deleted submodule' "
 152    git submodule summary >actual &&
 153    diff actual - <<-EOF
 154* sm1 $head6...0000000:
 155
 156EOF
 157"
 158
 159test_create_repo sm2 &&
 160head7=$(add_file sm2 foo8 foo9) &&
 161git add sm2
 162
 163test_expect_success 'multiple submodules' "
 164    git submodule summary >actual &&
 165    diff actual - <<-EOF
 166* sm1 $head6...0000000:
 167
 168* sm2 0000000...$head7 (2):
 169  > Add foo9
 170
 171EOF
 172"
 173
 174test_expect_success 'path filter' "
 175    git submodule summary sm2 >actual &&
 176    diff actual - <<-EOF
 177* sm2 0000000...$head7 (2):
 178  > Add foo9
 179
 180EOF
 181"
 182
 183commit_file sm2
 184test_expect_success 'given commit' "
 185    git submodule summary HEAD^ >actual &&
 186    diff actual - <<-EOF
 187* sm1 $head6...0000000:
 188
 189* sm2 0000000...$head7 (2):
 190  > Add foo9
 191
 192EOF
 193"
 194
 195test_expect_success '--for-status' "
 196    git submodule summary --for-status HEAD^ >actual &&
 197    test_cmp actual - <<EOF
 198# Modified submodules:
 199#
 200# * sm1 $head6...0000000:
 201#
 202# * sm2 0000000...$head7 (2):
 203#   > Add foo9
 204#
 205EOF
 206"
 207
 208test_done