t / t3903-stash.shon commit refactor fetch's ref matching to use refname_match() (605b497)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E Schindelin
   4#
   5
   6test_description='Test git-stash'
   7
   8. ./test-lib.sh
   9
  10test_expect_success 'stash 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        git stash &&
  20        git diff-files --quiet &&
  21        git diff-index --cached --quiet HEAD
  22'
  23
  24cat > expect << EOF
  25diff --git a/file b/file
  26index 0cfbf08..00750ed 100644
  27--- a/file
  28+++ b/file
  29@@ -1 +1 @@
  30-2
  31+3
  32EOF
  33
  34test_expect_success 'parents of stash' '
  35        test $(git rev-parse stash^) = $(git rev-parse HEAD) &&
  36        git diff stash^2..stash > output &&
  37        diff -u output expect
  38'
  39
  40test_expect_success 'apply needs clean working directory' '
  41        echo 4 > other-file &&
  42        git add other-file &&
  43        echo 5 > other-file
  44        ! git stash apply
  45'
  46
  47test_expect_success 'apply stashed changes' '
  48        git add other-file &&
  49        test_tick &&
  50        git commit -m other-file &&
  51        git stash apply &&
  52        test 3 = $(cat file) &&
  53        test 1 = $(git show :file) &&
  54        test 1 = $(git show HEAD:file)
  55'
  56
  57test_expect_success 'apply stashed changes (including index)' '
  58        git reset --hard HEAD^ &&
  59        echo 6 > other-file &&
  60        git add other-file &&
  61        test_tick &&
  62        git commit -m other-file &&
  63        git stash apply --index &&
  64        test 3 = $(cat file) &&
  65        test 2 = $(git show :file) &&
  66        test 1 = $(git show HEAD:file)
  67'
  68
  69test_expect_success 'unstashing in a subdirectory' '
  70        git reset --hard HEAD &&
  71        mkdir subdir &&
  72        cd subdir &&
  73        git stash apply
  74'
  75
  76test_done