Merge branch 'master' (early part) into pd/bash-4-completion
[gitweb.git] / t / t3903-stash.sh
index ea9f97997e48362bb9cca8ccf496d4ef6ce9a54b..903a122efe0c54cb44eb6c3e7ed04bdbab81439d 100755 (executable)
@@ -69,9 +69,10 @@ test_expect_success 'apply stashed changes (including index)' '
 test_expect_success 'unstashing in a subdirectory' '
        git reset --hard HEAD &&
        mkdir subdir &&
-       cd subdir &&
-       git stash apply &&
-       cd ..
+       (
+               cd subdir &&
+               git stash apply
+       )
 '
 
 test_expect_success 'drop top stash' '
@@ -415,8 +416,37 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' '
        echo bar >> file &&
        STASH_ID=$(git stash create) &&
        git reset --hard &&
-       git stash show ${STASH_ID}
+       cat >expected <<-EOF &&
+        file |    1 +
+        1 files changed, 1 insertions(+), 0 deletions(-)
+       EOF
+       git stash show ${STASH_ID} >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'stash show -p - stashes on stack, stash-like argument' '
+       git stash clear &&
+       test_when_finished "git reset --hard HEAD" &&
+       git reset --hard &&
+       echo foo >> file &&
+       git stash &&
+       test_when_finished "git stash drop" &&
+       echo bar >> file &&
+       STASH_ID=$(git stash create) &&
+       git reset --hard &&
+       cat >expected <<-EOF &&
+       diff --git a/file b/file
+       index 7601807..935fbd3 100644
+       --- a/file
+       +++ b/file
+       @@ -1 +1,2 @@
+        baz
+       +bar
+       EOF
+       git stash show -p ${STASH_ID} >actual &&
+       test_cmp expected actual
 '
+
 test_expect_success 'stash show - no stashes on stack, stash-like argument' '
        git stash clear &&
        test_when_finished "git reset --hard HEAD" &&
@@ -424,7 +454,32 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' '
        echo foo >> file &&
        STASH_ID=$(git stash create) &&
        git reset --hard &&
-       git stash show ${STASH_ID}
+       cat >expected <<-EOF &&
+        file |    1 +
+        1 files changed, 1 insertions(+), 0 deletions(-)
+       EOF
+       git stash show ${STASH_ID} >actual &&
+       test_cmp expected actual
+'
+
+test_expect_success 'stash show -p - no stashes on stack, stash-like argument' '
+       git stash clear &&
+       test_when_finished "git reset --hard HEAD" &&
+       git reset --hard &&
+       echo foo >> file &&
+       STASH_ID=$(git stash create) &&
+       git reset --hard &&
+       cat >expected <<-EOF &&
+       diff --git a/file b/file
+       index 7601807..71b52c4 100644
+       --- a/file
+       +++ b/file
+       @@ -1 +1,2 @@
+        baz
+       +foo
+       EOF
+       git stash show -p ${STASH_ID} >actual &&
+       test_cmp expected actual
 '
 
 test_expect_success 'stash drop - fail early if specified stash is not a stash reference' '
@@ -435,7 +490,7 @@ test_expect_success 'stash drop - fail early if specified stash is not a stash r
        git stash &&
        echo bar > file &&
        git stash &&
-       test_must_fail "git stash drop $(git rev-parse stash@{0})" &&
+       test_must_fail git stash drop $(git rev-parse stash@{0}) &&
        git stash pop &&
        test bar = "$(cat file)" &&
        git reset --hard HEAD
@@ -449,7 +504,7 @@ test_expect_success 'stash pop - fail early if specified stash is not a stash re
        git stash &&
        echo bar > file &&
        git stash &&
-       test_must_fail "git stash pop $(git rev-parse stash@{0})" &&
+       test_must_fail git stash pop $(git rev-parse stash@{0}) &&
        git stash pop &&
        test bar = "$(cat file)" &&
        git reset --hard HEAD
@@ -462,32 +517,43 @@ test_expect_success 'ref with non-existant reflog' '
        git add file2 &&
        git stash &&
        ! "git rev-parse --quiet --verify does-not-exist" &&
-       test_must_fail "git stash drop does-not-exist" &&
-       test_must_fail "git stash drop does-not-exist@{0}" &&
-       test_must_fail "git stash pop does-not-exist" &&
-       test_must_fail "git stash pop does-not-exist@{0}" &&
-       test_must_fail "git stash apply does-not-exist" &&
-       test_must_fail "git stash apply does-not-exist@{0}" &&
-       test_must_fail "git stash show does-not-exist" &&
-       test_must_fail "git stash show does-not-exist@{0}" &&
-       test_must_fail "git stash branch tmp does-not-exist" &&
-       test_must_fail "git stash branch tmp does-not-exist@{0}" &&
+       test_must_fail git stash drop does-not-exist &&
+       test_must_fail git stash drop does-not-exist@{0} &&
+       test_must_fail git stash pop does-not-exist &&
+       test_must_fail git stash pop does-not-exist@{0} &&
+       test_must_fail git stash apply does-not-exist &&
+       test_must_fail git stash apply does-not-exist@{0} &&
+       test_must_fail git stash show does-not-exist &&
+       test_must_fail git stash show does-not-exist@{0} &&
+       test_must_fail git stash branch tmp does-not-exist &&
+       test_must_fail git stash branch tmp does-not-exist@{0} &&
        git stash drop
 '
 
 test_expect_success 'invalid ref of the form stash@{n}, n >= N' '
        git stash clear &&
-       test_must_fail "git stash drop stash@{0}" &&
+       test_must_fail git stash drop stash@{0} &&
        echo bar5 > file &&
        echo bar6 > file2 &&
        git add file2 &&
        git stash &&
-       test_must_fail "git drop stash@{1}" &&
-       test_must_fail "git pop stash@{1}" &&
-       test_must_fail "git apply stash@{1}" &&
-       test_must_fail "git show stash@{1}" &&
-       test_must_fail "git branch tmp stash@{1}" &&
+       test_must_fail git drop stash@{1} &&
+       test_must_fail git pop stash@{1} &&
+       test_must_fail git apply stash@{1} &&
+       test_must_fail git show stash@{1} &&
+       test_must_fail git branch tmp stash@{1} &&
        git stash drop
 '
 
+test_expect_success 'stash branch should not drop the stash if the branch exists' '
+       git stash clear &&
+       echo foo >file &&
+       git add file &&
+       git commit -m initial &&
+       echo bar >file &&
+       git stash &&
+       test_must_fail git stash branch master stash@{0} &&
+       git rev-parse stash@{0} --
+'
+
 test_done