d84bda1dda54befb466b67d784a506a17b5fdf33
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='git-status'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'setup' '
  11        : > tracked &&
  12        : > modified &&
  13        mkdir dir1 &&
  14        : > dir1/tracked &&
  15        : > dir1/modified &&
  16        mkdir dir2 &&
  17        : > dir1/tracked &&
  18        : > dir1/modified &&
  19        git add . &&
  20
  21        git status >output &&
  22
  23        test_tick &&
  24        git commit -m initial &&
  25        : > untracked &&
  26        : > dir1/untracked &&
  27        : > dir2/untracked &&
  28        echo 1 > dir1/modified &&
  29        echo 2 > dir2/modified &&
  30        echo 3 > dir2/added &&
  31        git add dir2/added
  32'
  33
  34test_expect_success 'status (1)' '
  35
  36        grep "use \"git rm --cached <file>\.\.\.\" to unstage" output
  37
  38'
  39
  40cat > expect << \EOF
  41# On branch master
  42# Changes to be committed:
  43#   (use "git reset HEAD <file>..." to unstage)
  44#
  45#       new file:   dir2/added
  46#
  47# Changed but not updated:
  48#   (use "git add <file>..." to update what will be committed)
  49#
  50#       modified:   dir1/modified
  51#
  52# Untracked files:
  53#   (use "git add <file>..." to include in what will be committed)
  54#
  55#       dir1/untracked
  56#       dir2/modified
  57#       dir2/untracked
  58#       expect
  59#       output
  60#       untracked
  61EOF
  62
  63test_expect_success 'status (2)' '
  64
  65        git status > output &&
  66        test_cmp expect output
  67
  68'
  69
  70cat >expect <<EOF
  71# On branch master
  72# Changes to be committed:
  73#   (use "git reset HEAD <file>..." to unstage)
  74#
  75#       new file:   dir2/added
  76#
  77# Changed but not updated:
  78#   (use "git add <file>..." to update what will be committed)
  79#
  80#       modified:   dir1/modified
  81#
  82# Untracked files not listed (use -u option to show untracked files)
  83EOF
  84test_expect_success 'status -uno' '
  85        mkdir dir3 &&
  86        : > dir3/untracked1 &&
  87        : > dir3/untracked2 &&
  88        git status -uno >output &&
  89        test_cmp expect output
  90'
  91
  92cat >expect <<EOF
  93# On branch master
  94# Changes to be committed:
  95#   (use "git reset HEAD <file>..." to unstage)
  96#
  97#       new file:   dir2/added
  98#
  99# Changed but not updated:
 100#   (use "git add <file>..." to update what will be committed)
 101#
 102#       modified:   dir1/modified
 103#
 104# Untracked files:
 105#   (use "git add <file>..." to include in what will be committed)
 106#
 107#       dir1/untracked
 108#       dir2/modified
 109#       dir2/untracked
 110#       dir3/
 111#       expect
 112#       output
 113#       untracked
 114EOF
 115test_expect_success 'status -unormal' '
 116        git status -unormal >output &&
 117        test_cmp expect output
 118'
 119
 120cat >expect <<EOF
 121# On branch master
 122# Changes to be committed:
 123#   (use "git reset HEAD <file>..." to unstage)
 124#
 125#       new file:   dir2/added
 126#
 127# Changed but not updated:
 128#   (use "git add <file>..." to update what will be committed)
 129#
 130#       modified:   dir1/modified
 131#
 132# Untracked files:
 133#   (use "git add <file>..." to include in what will be committed)
 134#
 135#       dir1/untracked
 136#       dir2/modified
 137#       dir2/untracked
 138#       dir3/untracked1
 139#       dir3/untracked2
 140#       expect
 141#       output
 142#       untracked
 143EOF
 144test_expect_success 'status -uall' '
 145        git status -uall >output &&
 146        rm -rf dir3 &&
 147        test_cmp expect output
 148'
 149
 150cat > expect << \EOF
 151# On branch master
 152# Changes to be committed:
 153#   (use "git reset HEAD <file>..." to unstage)
 154#
 155#       new file:   ../dir2/added
 156#
 157# Changed but not updated:
 158#   (use "git add <file>..." to update what will be committed)
 159#
 160#       modified:   modified
 161#
 162# Untracked files:
 163#   (use "git add <file>..." to include in what will be committed)
 164#
 165#       untracked
 166#       ../dir2/modified
 167#       ../dir2/untracked
 168#       ../expect
 169#       ../output
 170#       ../untracked
 171EOF
 172
 173test_expect_success 'status with relative paths' '
 174
 175        (cd dir1 && git status) > output &&
 176        test_cmp expect output
 177
 178'
 179
 180cat > expect << \EOF
 181# On branch master
 182# Changes to be committed:
 183#   (use "git reset HEAD <file>..." to unstage)
 184#
 185#       new file:   dir2/added
 186#
 187# Changed but not updated:
 188#   (use "git add <file>..." to update what will be committed)
 189#
 190#       modified:   dir1/modified
 191#
 192# Untracked files:
 193#   (use "git add <file>..." to include in what will be committed)
 194#
 195#       dir1/untracked
 196#       dir2/modified
 197#       dir2/untracked
 198#       expect
 199#       output
 200#       untracked
 201EOF
 202
 203test_expect_success 'status without relative paths' '
 204
 205        git config status.relativePaths false
 206        (cd dir1 && git status) > output &&
 207        test_cmp expect output
 208
 209'
 210
 211cat <<EOF >expect
 212# On branch master
 213# Changes to be committed:
 214#   (use "git reset HEAD <file>..." to unstage)
 215#
 216#       modified:   dir1/modified
 217#
 218# Untracked files:
 219#   (use "git add <file>..." to include in what will be committed)
 220#
 221#       dir1/untracked
 222#       dir2/
 223#       expect
 224#       output
 225#       untracked
 226EOF
 227test_expect_success 'status of partial commit excluding new file in index' '
 228        git status dir1/modified >output &&
 229        test_cmp expect output
 230'
 231
 232test_expect_success 'setup status submodule summary' '
 233        test_create_repo sm && (
 234                cd sm &&
 235                >foo &&
 236                git add foo &&
 237                git commit -m "Add foo"
 238        ) &&
 239        git add sm
 240'
 241
 242cat >expect <<EOF
 243# On branch master
 244# Changes to be committed:
 245#   (use "git reset HEAD <file>..." to unstage)
 246#
 247#       new file:   dir2/added
 248#       new file:   sm
 249#
 250# Changed but not updated:
 251#   (use "git add <file>..." to update what will be committed)
 252#
 253#       modified:   dir1/modified
 254#
 255# Untracked files:
 256#   (use "git add <file>..." to include in what will be committed)
 257#
 258#       dir1/untracked
 259#       dir2/modified
 260#       dir2/untracked
 261#       expect
 262#       output
 263#       untracked
 264EOF
 265test_expect_success 'status submodule summary is disabled by default' '
 266        git status >output &&
 267        test_cmp expect output
 268'
 269
 270head=$(cd sm && git rev-parse --short=7 --verify HEAD)
 271
 272cat >expect <<EOF
 273# On branch master
 274# Changes to be committed:
 275#   (use "git reset HEAD <file>..." to unstage)
 276#
 277#       new file:   dir2/added
 278#       new file:   sm
 279#
 280# Changed but not updated:
 281#   (use "git add <file>..." to update what will be committed)
 282#
 283#       modified:   dir1/modified
 284#
 285# Modified submodules:
 286#
 287# * sm 0000000...$head (1):
 288#   > Add foo
 289#
 290# Untracked files:
 291#   (use "git add <file>..." to include in what will be committed)
 292#
 293#       dir1/untracked
 294#       dir2/modified
 295#       dir2/untracked
 296#       expect
 297#       output
 298#       untracked
 299EOF
 300test_expect_success 'status submodule summary' '
 301        git config status.submodulesummary 10 &&
 302        git status >output &&
 303        test_cmp expect output
 304'
 305
 306
 307cat >expect <<EOF
 308# On branch master
 309# Changed but not updated:
 310#   (use "git add <file>..." to update what will be committed)
 311#
 312#       modified:   dir1/modified
 313#
 314# Untracked files:
 315#   (use "git add <file>..." to include in what will be committed)
 316#
 317#       dir1/untracked
 318#       dir2/modified
 319#       dir2/untracked
 320#       expect
 321#       output
 322#       untracked
 323no changes added to commit (use "git add" and/or "git commit -a")
 324EOF
 325test_expect_success 'status submodule summary (clean submodule)' '
 326        git commit -m "commit submodule" &&
 327        git config status.submodulesummary 10 &&
 328        test_must_fail git status >output &&
 329        test_cmp expect output
 330'
 331
 332cat >expect <<EOF
 333# On branch master
 334# Changes to be committed:
 335#   (use "git reset HEAD^1 <file>..." to unstage)
 336#
 337#       new file:   dir2/added
 338#       new file:   sm
 339#
 340# Changed but not updated:
 341#   (use "git add <file>..." to update what will be committed)
 342#
 343#       modified:   dir1/modified
 344#
 345# Modified submodules:
 346#
 347# * sm 0000000...$head (1):
 348#   > Add foo
 349#
 350# Untracked files:
 351#   (use "git add <file>..." to include in what will be committed)
 352#
 353#       dir1/untracked
 354#       dir2/modified
 355#       dir2/untracked
 356#       expect
 357#       output
 358#       untracked
 359EOF
 360test_expect_success 'status submodule summary (--amend)' '
 361        git config status.submodulesummary 10 &&
 362        git status --amend >output &&
 363        test_cmp expect output
 364'
 365
 366test_done