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.showIncludeUntracked:: 2 If this is set to true, the `git stash show` command will show 3 the untracked files of a stash entry. Defaults to false. See
··· 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 + 6 stash.showIncludeUntracked:: 7 If this is set to true, the `git stash show` command will show 8 the untracked files of a stash entry. Defaults to false. See
+11 -6
builtin/stash.c
··· 146 static const char ref_stash[] = "refs/stash"; 147 static struct strbuf stash_index_path = STRBUF_INIT; 148 149 /* 150 * w_commit is set to the commit containing the working tree 151 * b_commit is set to the base commit ··· 717 { 718 int ret = -1; 719 int quiet = 0; 720 - int index = 0; 721 struct stash_info info = STASH_INFO_INIT; 722 struct option options[] = { 723 OPT__QUIET(&quiet, N_("be quiet, only report errors")), ··· 815 struct repository *repo UNUSED) 816 { 817 int ret = -1; 818 - int index = 0; 819 int quiet = 0; 820 struct stash_info info = STASH_INFO_INIT; 821 struct option options[] = { ··· 905 return run_command(&cp); 906 } 907 908 - static int show_stat = 1; 909 - static int show_patch; 910 - static int show_include_untracked; 911 - 912 static int git_stash_config(const char *var, const char *value, 913 const struct config_context *ctx, void *cb) 914 { ··· 922 } 923 if (!strcmp(var, "stash.showincludeuntracked")) { 924 show_include_untracked = git_config_bool(var, value); 925 return 0; 926 } 927 return git_diff_basic_config(var, value, ctx, cb);
··· 146 static const char ref_stash[] = "refs/stash"; 147 static struct strbuf stash_index_path = STRBUF_INIT; 148 149 + static int show_stat = 1; 150 + static int show_patch; 151 + static int show_include_untracked; 152 + static int use_index; 153 + 154 /* 155 * w_commit is set to the commit containing the working tree 156 * b_commit is set to the base commit ··· 722 { 723 int ret = -1; 724 int quiet = 0; 725 + int index = use_index; 726 struct stash_info info = STASH_INFO_INIT; 727 struct option options[] = { 728 OPT__QUIET(&quiet, N_("be quiet, only report errors")), ··· 820 struct repository *repo UNUSED) 821 { 822 int ret = -1; 823 + int index = use_index; 824 int quiet = 0; 825 struct stash_info info = STASH_INFO_INIT; 826 struct option options[] = { ··· 910 return run_command(&cp); 911 } 912 913 static int git_stash_config(const char *var, const char *value, 914 const struct config_context *ctx, void *cb) 915 { ··· 923 } 924 if (!strcmp(var, "stash.showincludeuntracked")) { 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); 930 return 0; 931 } 932 return git_diff_basic_config(var, value, ctx, cb);
+40
t/t3903-stash.sh
··· 902 903 test_expect_success 'apply: show same status as git status (relative to ./)' ' 904 git stash clear && 905 echo 1 >subdir/subfile1 && 906 echo 2 >subdir/subfile2 && 907 git add subdir/subfile1 && ··· 1356 1357 test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' ' 1358 git reset && 1359 >subdir/untracked && 1360 >subdir/tracked1 && 1361 >subdir/tracked2 && ··· 1372 1373 test_expect_success 'stash -- <subdir> works with binary files' ' 1374 git reset && 1375 >subdir/untracked && 1376 >subdir/tracked && 1377 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary && ··· 1748 test_expect_success 'controlled error return on unrecognized option' ' 1749 test_expect_code 129 git stash show -p --invalid 2>usage && 1750 grep -e "^usage: git stash show" usage 1751 ' 1752 1753 test_done
··· 902 903 test_expect_success 'apply: show same status as git status (relative to ./)' ' 904 git stash clear && 905 + mkdir -p subdir && 906 echo 1 >subdir/subfile1 && 907 echo 2 >subdir/subfile2 && 908 git add subdir/subfile1 && ··· 1357 1358 test_expect_success 'stash -- <subdir> leaves untracked files in subdir intact' ' 1359 git reset && 1360 + mkdir -p subdir && 1361 >subdir/untracked && 1362 >subdir/tracked1 && 1363 >subdir/tracked2 && ··· 1374 1375 test_expect_success 'stash -- <subdir> works with binary files' ' 1376 git reset && 1377 + mkdir -p subdir && 1378 >subdir/untracked && 1379 >subdir/tracked && 1380 cp "$TEST_DIRECTORY"/test-binary-1.png subdir/tracked-binary && ··· 1751 test_expect_success 'controlled error return on unrecognized option' ' 1752 test_expect_code 129 git stash show -p --invalid 2>usage && 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 1791 ' 1792 1793 test_done
-1
t/t3905-stash-include-untracked.sh
··· 87 88 test_expect_success 'clean up untracked/untracked file to prepare for next tests' ' 89 git clean --force --quiet 90 - 91 ' 92 93 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '
··· 87 88 test_expect_success 'clean up untracked/untracked file to prepare for next tests' ' 89 git clean --force --quiet 90 ' 91 92 test_expect_success 'stash pop after save --include-untracked leaves files untracked again' '