Git fork

Merge branch 'dk/stash-apply-index'

The stash.index configuration variable can be set to make "git stash
pop/apply" pretend that it was invoked with "--index".

* dk/stash-apply-index:
stash: honor stash.index in apply, pop modes
stash: refactor private config globals
t3905: remove unneeded blank line
t3903: reduce dependencies on previous tests

+56 -7
+5
Documentation/config/stash.adoc
··· 1 + stash.index:: 2 + If this is set to true, `git stash apply` and `git stash pop` will 3 + behave as if `--index` was supplied. Defaults to false. See the 4 + descriptions in linkgit:git-stash[1]. 5 + 1 6 stash.showIncludeUntracked:: 2 7 If this is set to true, the `git stash show` command will show 3 8 the untracked files of a stash entry. Defaults to false. See
+11 -6
builtin/stash.c
··· 146 146 static const char ref_stash[] = "refs/stash"; 147 147 static struct strbuf stash_index_path = STRBUF_INIT; 148 148 149 + static int show_stat = 1; 150 + static int show_patch; 151 + static int show_include_untracked; 152 + static int use_index; 153 + 149 154 /* 150 155 * w_commit is set to the commit containing the working tree 151 156 * b_commit is set to the base commit ··· 717 722 { 718 723 int ret = -1; 719 724 int quiet = 0; 720 - int index = 0; 725 + int index = use_index; 721 726 struct stash_info info = STASH_INFO_INIT; 722 727 struct option options[] = { 723 728 OPT__QUIET(&quiet, N_("be quiet, only report errors")), ··· 815 820 struct repository *repo UNUSED) 816 821 { 817 822 int ret = -1; 818 - int index = 0; 823 + int index = use_index; 819 824 int quiet = 0; 820 825 struct stash_info info = STASH_INFO_INIT; 821 826 struct option options[] = { ··· 905 910 return run_command(&cp); 906 911 } 907 912 908 - static int show_stat = 1; 909 - static int show_patch; 910 - static int show_include_untracked; 911 - 912 913 static int git_stash_config(const char *var, const char *value, 913 914 const struct config_context *ctx, void *cb) 914 915 { ··· 922 923 } 923 924 if (!strcmp(var, "stash.showincludeuntracked")) { 924 925 show_include_untracked = git_config_bool(var, value); 926 + return 0; 927 + } 928 + if (!strcmp(var, "stash.index")) { 929 + use_index = git_config_bool(var, value); 925 930 return 0; 926 931 } 927 932 return git_diff_basic_config(var, value, ctx, cb);
+40
t/t3903-stash.sh
··· 902 902 903 903 test_expect_success 'apply: show same status as git status (relative to ./)' ' 904 904 git stash clear && 905 + mkdir -p subdir && 905 906 echo 1 >subdir/subfile1 && 906 907 echo 2 >subdir/subfile2 && 907 908 git add subdir/subfile1 && ··· 1356 1357 1357 1358 test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' ' 1358 1359 git reset && 1360 + mkdir -p subdir && 1359 1361 >subdir/untracked && 1360 1362 >subdir/tracked1 && 1361 1363 >subdir/tracked2 && ··· 1372 1374 1373 1375 test_expect_success 'stash -- <subdir> works with binary files' ' 1374 1376 git reset && 1377 + mkdir -p subdir && 1375 1378 >subdir/untracked && 1376 1379 >subdir/tracked && 1377 1380 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary && ··· 1748 1751 test_expect_success 'controlled error return on unrecognized option' ' 1749 1752 test_expect_code 129 git stash show -p --invalid 2>usage && 1750 1753 grep -e "^usage: git stash show" usage 1754 + ' 1755 + 1756 + test_expect_success 'stash.index=true implies --index' ' 1757 + # setup for a few related tests 1758 + test_commit file base && 1759 + echo index >file && 1760 + git add file && 1761 + echo working >file && 1762 + git stash && 1763 + 1764 + test_when_finished "git reset --hard" && 1765 + git -c stash.index=true stash apply && 1766 + echo index >expect && 1767 + git show :0:file >actual && 1768 + test_cmp expect actual && 1769 + echo working >expect && 1770 + test_cmp expect file 1771 + ' 1772 + 1773 + test_expect_success 'stash.index=true overridden by --no-index' ' 1774 + test_when_finished "git reset --hard" && 1775 + git -c stash.index=true stash apply --no-index && 1776 + echo base >expect && 1777 + git show :0:file >actual && 1778 + test_cmp expect actual && 1779 + echo working >expect && 1780 + test_cmp expect file 1781 + ' 1782 + 1783 + test_expect_success 'stash.index=false overridden by --index' ' 1784 + test_when_finished "git reset --hard" && 1785 + git -c stash.index=false stash apply --index && 1786 + echo index >expect && 1787 + git show :0:file >actual && 1788 + test_cmp expect actual && 1789 + echo working >expect && 1790 + test_cmp expect file 1751 1791 ' 1752 1792 1753 1793 test_done
-1
t/t3905-stash-include-untracked.sh
··· 87 87 88 88 test_expect_success 'clean up untracked/untracked file to prepare for next tests' ' 89 89 git clean --force --quiet 90 - 91 90 ' 92 91 93 92 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '