t / t3905-stash-include-untracked.shon commit Merge branch 'jc/maint-remove-renamed-ref' (e335304)
   1#!/bin/sh
   2#
   3# Copyright (c) 2011 David Caldwell
   4#
   5
   6test_description='Test git stash --include-untracked'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'stash save --include-untracked some dirty working directory' '
  11        echo 1 > file &&
  12        git add file &&
  13        test_tick &&
  14        git commit -m initial &&
  15        echo 2 > file &&
  16        git add file &&
  17        echo 3 > file &&
  18        test_tick &&
  19        echo 1 > file2 &&
  20        mkdir untracked &&
  21        echo untracked >untracked/untracked &&
  22        git stash --include-untracked &&
  23        git diff-files --quiet &&
  24        git diff-index --cached --quiet HEAD
  25'
  26
  27cat > expect <<EOF
  28?? actual
  29?? expect
  30EOF
  31
  32test_expect_success 'stash save --include-untracked cleaned the untracked files' '
  33        git status --porcelain >actual &&
  34        test_cmp expect actual
  35'
  36
  37cat > expect.diff <<EOF
  38diff --git a/file2 b/file2
  39new file mode 100644
  40index 0000000..d00491f
  41--- /dev/null
  42+++ b/file2
  43@@ -0,0 +1 @@
  44+1
  45diff --git a/untracked/untracked b/untracked/untracked
  46new file mode 100644
  47index 0000000..5a72eb2
  48--- /dev/null
  49+++ b/untracked/untracked
  50@@ -0,0 +1 @@
  51+untracked
  52EOF
  53cat > expect.lstree <<EOF
  54file2
  55untracked
  56EOF
  57
  58test_expect_success 'stash save --include-untracked stashed the untracked files' '
  59        test "!" -f file2 &&
  60        test ! -e untracked &&
  61        git diff HEAD stash^3 -- file2 untracked >actual &&
  62        test_cmp expect.diff actual &&
  63        git ls-tree --name-only stash^3: >actual &&
  64        test_cmp expect.lstree actual
  65'
  66test_expect_success 'stash save --patch --include-untracked fails' '
  67        test_must_fail git stash --patch --include-untracked
  68'
  69
  70test_expect_success 'stash save --patch --all fails' '
  71        test_must_fail git stash --patch --all
  72'
  73
  74git clean --force --quiet
  75
  76cat > expect <<EOF
  77 M file
  78?? actual
  79?? expect
  80?? file2
  81?? untracked/
  82EOF
  83
  84test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
  85        git stash pop &&
  86        git status --porcelain >actual &&
  87        test_cmp expect actual &&
  88        test "1" = "`cat file2`" &&
  89        test untracked = "`cat untracked/untracked`"
  90'
  91
  92git clean --force --quiet -d
  93
  94test_expect_success 'stash save -u dirty index' '
  95        echo 4 > file3 &&
  96        git add file3 &&
  97        test_tick &&
  98        git stash -u
  99'
 100
 101cat > expect <<EOF
 102diff --git a/file3 b/file3
 103new file mode 100644
 104index 0000000..b8626c4
 105--- /dev/null
 106+++ b/file3
 107@@ -0,0 +1 @@
 108+4
 109EOF
 110
 111test_expect_success 'stash save --include-untracked dirty index got stashed' '
 112        git stash pop --index &&
 113        git diff --cached >actual &&
 114        test_cmp expect actual
 115'
 116
 117git reset > /dev/null
 118
 119test_expect_success 'stash save --include-untracked -q is quiet' '
 120        echo 1 > file5 &&
 121        git stash save --include-untracked --quiet > output.out 2>&1 &&
 122        test ! -s output.out
 123'
 124
 125test_expect_success 'stash save --include-untracked removed files' '
 126        rm -f file &&
 127        git stash save --include-untracked &&
 128        echo 1 > expect &&
 129        test_cmp file expect
 130'
 131
 132rm -f expect
 133
 134test_expect_success 'stash save --include-untracked removed files got stashed' '
 135        git stash pop &&
 136        test ! -f file
 137'
 138
 139cat > .gitignore <<EOF
 140.gitignore
 141ignored
 142ignored.d/
 143EOF
 144
 145test_expect_success 'stash save --include-untracked respects .gitignore' '
 146        echo ignored > ignored &&
 147        mkdir ignored.d &&
 148        echo ignored >ignored.d/untracked &&
 149        git stash -u &&
 150        test -s ignored &&
 151        test -s ignored.d/untracked &&
 152        test -s .gitignore
 153'
 154
 155test_expect_success 'stash save -u can stash with only untracked files different' '
 156        echo 4 > file4 &&
 157        git stash -u &&
 158        test "!" -f file4
 159'
 160
 161test_expect_success 'stash save --all does not respect .gitignore' '
 162        git stash -a &&
 163        test "!" -f ignored &&
 164        test "!" -e ignored.d &&
 165        test "!" -f .gitignore
 166'
 167
 168test_expect_success 'stash save --all is stash poppable' '
 169        git stash pop &&
 170        test -s ignored &&
 171        test -s ignored.d/untracked &&
 172        test -s .gitignore
 173'
 174
 175test_done