t / t3905-stash-include-untracked.shon commit Merge branch 'maint-1.7.6' into maint-1.7.7 (8769e93)
   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        git stash --include-untracked &&
  21        git diff-files --quiet &&
  22        git diff-index --cached --quiet HEAD
  23'
  24
  25cat > expect <<EOF
  26?? expect
  27?? output
  28EOF
  29
  30test_expect_success 'stash save --include-untracked cleaned the untracked files' '
  31        git status --porcelain > output
  32        test_cmp output expect
  33'
  34
  35cat > expect.diff <<EOF
  36diff --git a/file2 b/file2
  37new file mode 100644
  38index 0000000..d00491f
  39--- /dev/null
  40+++ b/file2
  41@@ -0,0 +1 @@
  42+1
  43EOF
  44cat > expect.lstree <<EOF
  45file2
  46EOF
  47
  48test_expect_success 'stash save --include-untracked stashed the untracked files' '
  49        test "!" -f file2 &&
  50        git diff HEAD..stash^3 -- file2 > output &&
  51        test_cmp output expect.diff &&
  52        git ls-tree --name-only stash^3: > output &&
  53        test_cmp output expect.lstree
  54'
  55test_expect_success 'stash save --patch --include-untracked fails' '
  56        test_must_fail git stash --patch --include-untracked
  57'
  58
  59test_expect_success 'stash save --patch --all fails' '
  60        test_must_fail git stash --patch --all
  61'
  62
  63git clean --force --quiet
  64
  65cat > expect <<EOF
  66 M file
  67?? expect
  68?? file2
  69?? output
  70EOF
  71
  72test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
  73        git stash pop &&
  74        git status --porcelain > output
  75        test_cmp output expect
  76'
  77
  78git clean --force --quiet
  79
  80test_expect_success 'stash save -u dirty index' '
  81        echo 4 > file3 &&
  82        git add file3 &&
  83        test_tick &&
  84        git stash -u
  85'
  86
  87cat > expect <<EOF
  88diff --git a/file3 b/file3
  89new file mode 100644
  90index 0000000..b8626c4
  91--- /dev/null
  92+++ b/file3
  93@@ -0,0 +1 @@
  94+4
  95EOF
  96
  97test_expect_success 'stash save --include-untracked dirty index got stashed' '
  98        git stash pop --index &&
  99        git diff --cached > output &&
 100        test_cmp output expect
 101'
 102
 103git reset > /dev/null
 104
 105test_expect_success 'stash save --include-untracked -q is quiet' '
 106        echo 1 > file5 &&
 107        git stash save --include-untracked --quiet > output.out 2>&1 &&
 108        test ! -s output.out
 109'
 110
 111test_expect_success 'stash save --include-untracked removed files' '
 112        rm -f file &&
 113        git stash save --include-untracked &&
 114        echo 1 > expect &&
 115        test_cmp file expect
 116'
 117
 118rm -f expect
 119
 120test_expect_success 'stash save --include-untracked removed files got stashed' '
 121        git stash pop &&
 122        test ! -f file
 123'
 124
 125cat > .gitignore <<EOF
 126.gitignore
 127ignored
 128EOF
 129
 130test_expect_success 'stash save --include-untracked respects .gitignore' '
 131        echo ignored > ignored &&
 132        git stash -u &&
 133        test -s ignored &&
 134        test -s .gitignore
 135'
 136
 137test_expect_success 'stash save -u can stash with only untracked files different' '
 138        echo 4 > file4 &&
 139        git stash -u
 140        test "!" -f file4
 141'
 142
 143test_expect_success 'stash save --all does not respect .gitignore' '
 144        git stash -a &&
 145        test "!" -f ignored &&
 146        test "!" -f .gitignore
 147'
 148
 149test_expect_success 'stash save --all is stash poppable' '
 150        git stash pop &&
 151        test -s ignored &&
 152        test -s .gitignore
 153'
 154
 155test_done