dc9150a71f70e76a89c3ef5e4a715c8fba69e01c
   1#!/bin/sh
   2
   3test_description='git status for submodule'
   4
   5. ./test-lib.sh
   6
   7test_expect_success 'setup' '
   8        test_create_repo sub &&
   9        (
  10                cd sub &&
  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        echo output > .gitignore &&
  19        git add sub .gitignore &&
  20        git commit -m "Add submodule sub"
  21'
  22
  23test_expect_success 'status clean' '
  24        git status >output &&
  25        grep "nothing to commit" output
  26'
  27
  28test_expect_success 'commit --dry-run -a clean' '
  29        test_must_fail git commit --dry-run -a >output &&
  30        grep "nothing to commit" output
  31'
  32
  33test_expect_success 'status with modified file in submodule' '
  34        (cd sub && git reset --hard) &&
  35        echo "changed" >sub/foo &&
  36        git status >output &&
  37        grep "modified:   sub (modified content)" output
  38'
  39
  40test_expect_success 'status with modified file in submodule (porcelain)' '
  41        (cd sub && git reset --hard) &&
  42        echo "changed" >sub/foo &&
  43        git status --porcelain >output &&
  44        diff output - <<-\EOF
  45         M sub
  46        EOF
  47'
  48
  49test_expect_success 'status with added file in submodule' '
  50        (cd sub && git reset --hard && echo >foo && git add foo) &&
  51        git status >output &&
  52        grep "modified:   sub (modified content)" output
  53'
  54
  55test_expect_success 'status with added file in submodule (porcelain)' '
  56        (cd sub && git reset --hard && echo >foo && git add foo) &&
  57        git status --porcelain >output &&
  58        diff output - <<-\EOF
  59         M sub
  60        EOF
  61'
  62
  63test_expect_success 'status with untracked file in submodule' '
  64        (cd sub && git reset --hard) &&
  65        echo "content" >sub/new-file &&
  66        git status >output &&
  67        grep "modified:   sub (untracked content)" output
  68'
  69
  70test_expect_success 'status with untracked file in submodule (porcelain)' '
  71        git status --porcelain >output &&
  72        diff output - <<-\EOF
  73         M sub
  74        EOF
  75'
  76
  77test_expect_success 'status with added and untracked file in submodule' '
  78        (cd sub && git reset --hard && echo >foo && git add foo) &&
  79        echo "content" >sub/new-file &&
  80        git status >output &&
  81        grep "modified:   sub (modified content, untracked content)" output
  82'
  83
  84test_expect_success 'status with added and untracked file in submodule (porcelain)' '
  85        (cd sub && git reset --hard && echo >foo && git add foo) &&
  86        echo "content" >sub/new-file &&
  87        git status --porcelain >output &&
  88        diff output - <<-\EOF
  89         M sub
  90        EOF
  91'
  92
  93test_expect_success 'status with modified file in modified submodule' '
  94        (cd sub && git reset --hard) &&
  95        rm sub/new-file &&
  96        (cd sub && echo "next change" >foo && git commit -m "next change" foo) &&
  97        echo "changed" >sub/foo &&
  98        git status >output &&
  99        grep "modified:   sub (new commits, modified content)" output
 100'
 101
 102test_expect_success 'status with modified file in modified submodule (porcelain)' '
 103        (cd sub && git reset --hard) &&
 104        echo "changed" >sub/foo &&
 105        git status --porcelain >output &&
 106        diff output - <<-\EOF
 107         M sub
 108        EOF
 109'
 110
 111test_expect_success 'status with added file in modified submodule' '
 112        (cd sub && git reset --hard && echo >foo && git add foo) &&
 113        git status >output &&
 114        grep "modified:   sub (new commits, modified content)" output
 115'
 116
 117test_expect_success 'status with added file in modified submodule (porcelain)' '
 118        (cd sub && git reset --hard && echo >foo && git add foo) &&
 119        git status --porcelain >output &&
 120        diff output - <<-\EOF
 121         M sub
 122        EOF
 123'
 124
 125test_expect_success 'status with untracked file in modified submodule' '
 126        (cd sub && git reset --hard) &&
 127        echo "content" >sub/new-file &&
 128        git status >output &&
 129        grep "modified:   sub (new commits, untracked content)" output
 130'
 131
 132test_expect_success 'status with untracked file in modified submodule (porcelain)' '
 133        git status --porcelain >output &&
 134        diff output - <<-\EOF
 135         M sub
 136        EOF
 137'
 138
 139test_expect_success 'status with added and untracked file in modified submodule' '
 140        (cd sub && git reset --hard && echo >foo && git add foo) &&
 141        echo "content" >sub/new-file &&
 142        git status >output &&
 143        grep "modified:   sub (new commits, modified content, untracked content)" output
 144'
 145
 146test_expect_success 'status with added and untracked file in modified submodule (porcelain)' '
 147        (cd sub && git reset --hard && echo >foo && git add foo) &&
 148        echo "content" >sub/new-file &&
 149        git status --porcelain >output &&
 150        diff output - <<-\EOF
 151         M sub
 152        EOF
 153'
 154
 155test_expect_success 'rm submodule contents' '
 156        rm -rf sub/* sub/.git
 157'
 158
 159test_expect_success 'status clean (empty submodule dir)' '
 160        git status >output &&
 161        grep "nothing to commit" output
 162'
 163
 164test_expect_success 'status -a clean (empty submodule dir)' '
 165        test_must_fail git commit --dry-run -a >output &&
 166        grep "nothing to commit" output
 167'
 168
 169test_done