Imported Upstream version 2.15.4
[platform/upstream/git.git] / t / t3903-stash.sh
index b71d1e6..3b1ac19 100755 (executable)
@@ -444,6 +444,14 @@ test_expect_failure 'stash file to directory' '
        test foo = "$(cat file/file)"
 '
 
+test_expect_success 'stash create - no changes' '
+       git stash clear &&
+       test_when_finished "git reset --hard HEAD" &&
+       git reset --hard &&
+       git stash create >actual &&
+       test_must_be_empty actual
+'
+
 test_expect_success 'stash branch - no stashes on stack, stash-like argument' '
        git stash clear &&
        test_when_finished "git reset --hard HEAD" &&
@@ -648,6 +656,20 @@ test_expect_success 'stash branch should not drop the stash if the branch exists
        git rev-parse stash@{0} --
 '
 
+test_expect_success 'stash branch should not drop the stash if the apply fails' '
+       git stash clear &&
+       git reset HEAD~1 --hard &&
+       echo foo >file &&
+       git add file &&
+       git commit -m initial &&
+       echo bar >file &&
+       git stash &&
+       echo baz >file &&
+       test_when_finished "git checkout master" &&
+       test_must_fail git stash branch new_branch stash@{0} &&
+       git rev-parse stash@{0} --
+'
+
 test_expect_success 'stash apply shows status same as git status (relative to current directory)' '
        git stash clear &&
        echo 1 >subdir/subfile1 &&
@@ -800,6 +822,18 @@ test_expect_success 'create with multiple arguments for the message' '
        test_cmp expect actual
 '
 
+test_expect_success 'create in a detached state' '
+       test_when_finished "git checkout master" &&
+       git checkout HEAD~1 &&
+       >foo &&
+       git add foo &&
+       STASH_ID=$(git stash create) &&
+       HEAD_ID=$(git rev-parse --short HEAD) &&
+       echo "WIP on (no branch): ${HEAD_ID} initial" >expect &&
+       git show --pretty=%s -s ${STASH_ID} >actual &&
+       test_cmp expect actual
+'
+
 test_expect_success 'stash -- <pathspec> stashes and restores the file' '
        >foo &&
        >bar &&
@@ -812,6 +846,22 @@ test_expect_success 'stash -- <pathspec> stashes and restores the file' '
        test_path_is_file bar
 '
 
+test_expect_success 'stash -- <pathspec> stashes in subdirectory' '
+       mkdir sub &&
+       >foo &&
+       >bar &&
+       git add foo bar &&
+       (
+               cd sub &&
+               git stash push -- ../foo
+       ) &&
+       test_path_is_file bar &&
+       test_path_is_missing foo &&
+       git stash pop &&
+       test_path_is_file foo &&
+       test_path_is_file bar
+'
+
 test_expect_success 'stash with multiple pathspec arguments' '
        >foo &&
        >bar &&
@@ -865,7 +915,7 @@ test_expect_success 'stash push -p with pathspec shows no changes only once' '
        git stash push -p foo >actual &&
        echo "No local changes to save" >expect &&
        git reset --hard HEAD~ &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_expect_success 'stash push with pathspec shows no changes when there are none' '
@@ -875,7 +925,7 @@ test_expect_success 'stash push with pathspec shows no changes when there are no
        git stash push foo >actual &&
        echo "No local changes to save" >expect &&
        git reset --hard HEAD~ &&
-       test_cmp expect actual
+       test_i18ncmp expect actual
 '
 
 test_expect_success 'stash push with pathspec not in the repository errors out' '