]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'dk/stash-apply-index' into next
authorJunio C Hamano <gitster@pobox.com>
Tue, 23 Sep 2025 19:05:32 +0000 (12:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 Sep 2025 19:05:33 +0000 (12:05 -0700)
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

1  2 
builtin/stash.c
t/t3903-stash.sh

diff --cc builtin/stash.c
Simple merge
index 930c31e547f8572aebc11f23152284c493ddef8c,d6127173b1184e3b616130fb0f842158110d26b8..70879941c22f8c4c0046c7af4765f693d1de525f
@@@ -1709,45 -1595,41 +1712,82 @@@ test_expect_success 'stash apply report
        )
  '
  
 +test_expect_success 'submodules does not affect the branch recorded in stash message' '
 +      git init sub_project &&
 +      (
 +              cd sub_project &&
 +              echo "Initial content in sub_project" >sub_file.txt &&
 +              git add sub_file.txt &&
 +              git commit -m "Initial commit in sub_project"
 +      ) &&
 +
 +      git init main_project &&
 +      (
 +              cd main_project &&
 +              echo "Initial content in main_project" >main_file.txt &&
 +              git add main_file.txt &&
 +              git commit -m "Initial commit in main_project" &&
 +
 +              git -c protocol.file.allow=always submodule add ../sub_project sub &&
 +              git commit -m "Added submodule sub_project" &&
 +
 +              git checkout -b feature_main &&
 +              git -C sub checkout -b feature_sub &&
 +
 +              git checkout -b work_branch &&
 +              echo "Important work to be stashed" >work_item.txt &&
 +              git add work_item.txt &&
 +              git stash push -m "custom stash for work_branch" &&
 +
 +              git stash list >../actual_stash_list.txt &&
 +              grep "On work_branch: custom stash for work_branch" ../actual_stash_list.txt
 +      )
 +'
 +
 +test_expect_success SANITIZE_LEAK 'stash show handles -- without leaking' '
 +      git stash show --
 +'
 +
 +test_expect_success 'controlled error return on unrecognized option' '
 +      test_expect_code 129 git stash show -p --invalid 2>usage &&
 +      grep -e "^usage: git stash show" usage
 +'
 +
+ test_expect_success 'stash.index=true implies --index' '
+       # setup for a few related tests
+       test_commit file base &&
+       echo index >file &&
+       git add file &&
+       echo working >file &&
+       git stash &&
+       test_when_finished "git reset --hard" &&
+       git -c stash.index=true stash apply &&
+       echo index >expect &&
+       git show :0:file >actual &&
+       test_cmp expect actual &&
+       echo working >expect &&
+       test_cmp expect file
+ '
+ test_expect_success 'stash.index=true overridden by --no-index' '
+       test_when_finished "git reset --hard" &&
+       git -c stash.index=true stash apply --no-index &&
+       echo base >expect &&
+       git show :0:file >actual &&
+       test_cmp expect actual &&
+       echo working >expect &&
+       test_cmp expect file
+ '
+ test_expect_success 'stash.index=false overridden by --index' '
+       test_when_finished "git reset --hard" &&
+       git -c stash.index=false stash apply --index &&
+       echo index >expect &&
+       git show :0:file >actual &&
+       test_cmp expect actual &&
+       echo working >expect &&
+       test_cmp expect file
+ '
  test_done