t / t7506-status-submodule.shon commit Merge branch 'lf/bundle-verify-list-prereqs' (a6da9cb)
   1#!/bin/sh
   2
   3test_description='git status for submodule'
   4
   5. ./test-lib.sh
   6
   7test_create_repo_with_commit () {
   8        test_create_repo "$1" &&
   9        (
  10                cd "$1" &&
  11                : >bar &&
  12                git add bar &&
  13                git commit -m " Add bar" &&
  14                : >foo &&
  15                git add foo &&
  16                git commit -m " Add foo"
  17        )
  18}
  19
  20test_expect_success 'setup' '
  21        test_create_repo_with_commit sub &&
  22        echo output > .gitignore &&
  23        git add sub .gitignore &&
  24        git commit -m "Add submodule sub"
  25'
  26
  27test_expect_success 'status clean' '
  28        git status >output &&
  29        test_i18ngrep "nothing to commit" output
  30'
  31
  32test_expect_success 'commit --dry-run -a clean' '
  33        test_must_fail git commit --dry-run -a >output &&
  34        test_i18ngrep "nothing to commit" output
  35'
  36
  37test_expect_success 'status with modified file in submodule' '
  38        (cd sub && git reset --hard) &&
  39        echo "changed" >sub/foo &&
  40        git status >output &&
  41        test_i18ngrep "modified:   sub (modified content)" output
  42'
  43
  44test_expect_success 'status with modified file in submodule (porcelain)' '
  45        (cd sub && git reset --hard) &&
  46        echo "changed" >sub/foo &&
  47        git status --porcelain >output &&
  48        diff output - <<-\EOF
  49         M sub
  50        EOF
  51'
  52
  53test_expect_success 'status with added file in submodule' '
  54        (cd sub && git reset --hard && echo >foo && git add foo) &&
  55        git status >output &&
  56        test_i18ngrep "modified:   sub (modified content)" output
  57'
  58
  59test_expect_success 'status with added file in submodule (porcelain)' '
  60        (cd sub && git reset --hard && echo >foo && git add foo) &&
  61        git status --porcelain >output &&
  62        diff output - <<-\EOF
  63         M sub
  64        EOF
  65'
  66
  67test_expect_success 'status with untracked file in submodule' '
  68        (cd sub && git reset --hard) &&
  69        echo "content" >sub/new-file &&
  70        git status >output &&
  71        test_i18ngrep "modified:   sub (untracked content)" output
  72'
  73
  74test_expect_success 'status -uno with untracked file in submodule' '
  75        git status -uno >output &&
  76        test_i18ngrep "^nothing to commit" output
  77'
  78
  79test_expect_success 'status with untracked file in submodule (porcelain)' '
  80        git status --porcelain >output &&
  81        diff output - <<-\EOF
  82         M sub
  83        EOF
  84'
  85
  86test_expect_success 'status with added and untracked file in submodule' '
  87        (cd sub && git reset --hard && echo >foo && git add foo) &&
  88        echo "content" >sub/new-file &&
  89        git status >output &&
  90        test_i18ngrep "modified:   sub (modified content, untracked content)" output
  91'
  92
  93test_expect_success 'status with added and untracked file in submodule (porcelain)' '
  94        (cd sub && git reset --hard && echo >foo && git add foo) &&
  95        echo "content" >sub/new-file &&
  96        git status --porcelain >output &&
  97        diff output - <<-\EOF
  98         M sub
  99        EOF
 100'
 101
 102test_expect_success 'status with modified file in modified submodule' '
 103        (cd sub && git reset --hard) &&
 104        rm sub/new-file &&
 105        (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
 106        echo "changed" >sub/foo &&
 107        git status >output &&
 108        test_i18ngrep "modified:   sub (new commits, modified content)" output
 109'
 110
 111test_expect_success 'status with modified file in modified submodule (porcelain)' '
 112        (cd sub && git reset --hard) &&
 113        echo "changed" >sub/foo &&
 114        git status --porcelain >output &&
 115        diff output - <<-\EOF
 116         M sub
 117        EOF
 118'
 119
 120test_expect_success 'status with added file in modified submodule' '
 121        (cd sub && git reset --hard && echo >foo && git add foo) &&
 122        git status >output &&
 123        test_i18ngrep "modified:   sub (new commits, modified content)" output
 124'
 125
 126test_expect_success 'status with added file in modified submodule (porcelain)' '
 127        (cd sub && git reset --hard && echo >foo && git add foo) &&
 128        git status --porcelain >output &&
 129        diff output - <<-\EOF
 130         M sub
 131        EOF
 132'
 133
 134test_expect_success 'status with untracked file in modified submodule' '
 135        (cd sub && git reset --hard) &&
 136        echo "content" >sub/new-file &&
 137        git status >output &&
 138        test_i18ngrep "modified:   sub (new commits, untracked content)" output
 139'
 140
 141test_expect_success 'status with untracked file in modified submodule (porcelain)' '
 142        git status --porcelain >output &&
 143        diff output - <<-\EOF
 144         M sub
 145        EOF
 146'
 147
 148test_expect_success 'status with added and untracked file in modified submodule' '
 149        (cd sub && git reset --hard && echo >foo && git add foo) &&
 150        echo "content" >sub/new-file &&
 151        git status >output &&
 152        test_i18ngrep "modified:   sub (new commits, modified content, untracked content)" output
 153'
 154
 155test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
 156        (cd sub && git reset --hard && echo >foo && git add foo) &&
 157        echo "content" >sub/new-file &&
 158        git status --porcelain >output &&
 159        diff output - <<-\EOF
 160         M sub
 161        EOF
 162'
 163
 164test_expect_success 'setup .git file for sub' '
 165        (cd sub &&
 166         rm -f new-file
 167         REAL="$(pwd)/../.real" &&
 168         mv .git "$REAL"
 169         echo "gitdir: $REAL" >.git) &&
 170         echo .real >>.gitignore &&
 171         git commit -m "added .real to .gitignore" .gitignore
 172'
 173
 174test_expect_success 'status with added file in modified submodule with .git file' '
 175        (cd sub && git reset --hard && echo >foo && git add foo) &&
 176        git status >output &&
 177        test_i18ngrep "modified:   sub (new commits, modified content)" output
 178'
 179
 180test_expect_success 'rm submodule contents' '
 181        rm -rf sub/* sub/.git
 182'
 183
 184test_expect_success 'status clean (empty submodule dir)' '
 185        git status >output &&
 186        test_i18ngrep "nothing to commit" output
 187'
 188
 189test_expect_success 'status -a clean (empty submodule dir)' '
 190        test_must_fail git commit --dry-run -a >output &&
 191        test_i18ngrep "nothing to commit" output
 192'
 193
 194cat >status_expect <<\EOF
 195AA .gitmodules
 196A  sub1
 197EOF
 198
 199test_expect_success 'status with merge conflict in .gitmodules' '
 200        git clone . super &&
 201        test_create_repo_with_commit sub1 &&
 202        test_tick &&
 203        test_create_repo_with_commit sub2 &&
 204        (
 205                cd super &&
 206                prev=$(git rev-parse HEAD) &&
 207                git checkout -b add_sub1 &&
 208                git submodule add ../sub1 &&
 209                git commit -m "add sub1" &&
 210                git checkout -b add_sub2 $prev &&
 211                git submodule add ../sub2 &&
 212                git commit -m "add sub2" &&
 213                git checkout -b merge_conflict_gitmodules &&
 214                test_must_fail git merge add_sub1 &&
 215                git status -s >../status_actual 2>&1
 216        ) &&
 217        test_cmp status_actual status_expect
 218'
 219
 220sha1_merge_sub1=$(cd sub1 && git rev-parse HEAD)
 221sha1_merge_sub2=$(cd sub2 && git rev-parse HEAD)
 222short_sha1_merge_sub1=$(cd sub1 && git rev-parse --short HEAD)
 223short_sha1_merge_sub2=$(cd sub2 && git rev-parse --short HEAD)
 224cat >diff_expect <<\EOF
 225diff --cc .gitmodules
 226index badaa4c,44f999a..0000000
 227--- a/.gitmodules
 228+++ b/.gitmodules
 229@@@ -1,3 -1,3 +1,9 @@@
 230++<<<<<<< HEAD
 231 +[submodule "sub2"]
 232 +      path = sub2
 233 +      url = ../sub2
 234++=======
 235+ [submodule "sub1"]
 236+       path = sub1
 237+       url = ../sub1
 238++>>>>>>> add_sub1
 239EOF
 240
 241cat >diff_submodule_expect <<\EOF
 242diff --cc .gitmodules
 243index badaa4c,44f999a..0000000
 244--- a/.gitmodules
 245+++ b/.gitmodules
 246@@@ -1,3 -1,3 +1,9 @@@
 247++<<<<<<< HEAD
 248 +[submodule "sub2"]
 249 +      path = sub2
 250 +      url = ../sub2
 251++=======
 252+ [submodule "sub1"]
 253+       path = sub1
 254+       url = ../sub1
 255++>>>>>>> add_sub1
 256EOF
 257
 258test_expect_success 'diff with merge conflict in .gitmodules' '
 259        (
 260                cd super &&
 261                git diff >../diff_actual 2>&1
 262        ) &&
 263        test_cmp diff_actual diff_expect
 264'
 265
 266test_expect_success 'diff --submodule with merge conflict in .gitmodules' '
 267        (
 268                cd super &&
 269                git diff --submodule >../diff_submodule_actual 2>&1
 270        ) &&
 271        test_cmp diff_submodule_actual diff_submodule_expect
 272'
 273
 274test_done