git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 0/2] stash: fix and improve "git stash -p <pathspec>"

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jun 7, 2025, 09:45 UTC
Message-ID
<cover.1749289514.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<6292feee7c4347efad31e9fb2a1763779b7df133.1747407473.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

"git stash -p <pathspec>" should imply "git stash push -p <pathspec>" but that was broken by a code cleanup in c3713cede7 (stash: eliminate crude option parsing, 2020-02-17). This regression is fixed in the first patch. Although "-p" implies the "push" subcommand "--patch" has never implied "push". That is fixed in the second patch.

Thanks to Martin for his comments on V2
Changes since V2:
 - Made test stricter as suggested by Martin
Thanks to Junio for his comments on V1.
Changes since V1:
 - Split out the regression fix into its own patch
Base-Commit: 1a8a4971cc6c179c4dd711f4a7f5d7178f4b3ab7
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fstash-assume-push-with-dash-p%2Fv3
View-Changes-At: https://github.com/phillipwood/git/compare/1a8a4971c...d3a958430
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/stash-assume-push-with-dash-p/v3
Phillip Wood (2):
  stash: allow "git stash -p <pathspec>" to assume push again
  stash: allow "git stash [<options>] --patch <pathspec>" to assume push
 builtin/stash.c  | 10 +++++++---
 t/t3903-stash.sh | 22 ++++++++++++++++++++++
 2 files changed, 29 insertions(+), 3 deletions(-)
Range-diff against v2:
1:  2cd67f5cd85 ! 1:  c147eaf2eae stash: allow "git stash -p <pathspec>" to assume push again
    @@ Commit message
         Fix this by regression by checking argv[1] instead of argv[0] and add a
         couple of tests to prevent future regressions.
     
    +    Helped-by: Martin Ågren <martin.agren@gmail.com>
         Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
     
      ## builtin/stash.c ##
    @@ t/t3903-stash.sh: test_expect_success 'stash -- <pathspec> stashes and restores
      '
      
     +test_expect_success 'stash -p <pathspec> stash and restores the file' '
    -+	cat file >expect-file &&
    -+	echo changed-file >file &&
    ++	test_write_lines b c >file &&
    ++	git commit -m "add a few lines" file &&
    ++	test_write_lines a b c d >file &&
    ++	test_write_lines b c d >expect-file &&
     +	echo changed-other-file >other-file &&
    -+	echo a | git stash -p file &&
    ++	test_write_lines s y n | git stash -p file &&
     +	test_cmp expect-file file &&
     +	echo changed-other-file >expect &&
     +	test_cmp expect other-file &&
    ++	git checkout HEAD -- file &&
     +	git stash pop &&
     +	test_cmp expect other-file &&
    -+	echo changed-file >expect &&
    ++	test_write_lines a b c >expect &&
     +	test_cmp expect file
     +'
     +
2:  98ad3de9770 ! 2:  d3a95843055 stash: allow "git stash [<options>] --patch <pathspec>" to assume push
    @@ t/t3903-stash.sh: test_expect_success 'stash -- <pathspec> stashes and restores
      
     -test_expect_success 'stash -p <pathspec> stash and restores the file' '
     +test_expect_success 'stash --patch <pathspec> stash and restores the file' '
    - 	cat file >expect-file &&
    - 	echo changed-file >file &&
    + 	test_write_lines b c >file &&
    + 	git commit -m "add a few lines" file &&
    + 	test_write_lines a b c d >file &&
    + 	test_write_lines b c d >expect-file &&
      	echo changed-other-file >other-file &&
    --	echo a | git stash -p file &&
    -+	echo a | git stash -m "stash bar" --patch file &&
    +-	test_write_lines s y n | git stash -p file &&
    ++	test_write_lines s y n | git stash -m "stash bar" --patch file &&
      	test_cmp expect-file file &&
      	echo changed-other-file >expect &&
      	test_cmp expect other-file &&
-- 
2.49.0.897.gfad3eb7d210
Previous: Martin ÅgrenNext: Phillip Wood
Message 13 of 18 in “stash: allow "git stash -p <pathspec>" to assume push again”
  1. stash: allow "git stash -p <pathspec>" to assume push againPhillip Wood, May 16, 2025
  2. Junio C HamanoMay 16, 2025
  3. Phillip WoodMay 20, 2025
  4. 0/2 stash: fix and improve "git stash -p <pathspec>"Phillip Wood, May 20, 2025
  5. 1/2 stash: allow "git stash -p <pathspec>" to assume push againPhillip Wood, May 20, 2025
  6. Martin ÅgrenJun 6, 2025
  7. Phillip WoodJun 6, 2025
  8. 2/2 stash: allow "git stash [<options>] --patch <pathspec>" to assume pushPhillip Wood, May 20, 2025
  9. Martin ÅgrenJun 6, 2025
  10. Junio C HamanoMay 21, 2025
  11. Junio C HamanoJun 3, 2025
  12. Martin ÅgrenJun 6, 2025
  13. 0/2 stash: fix and improve "git stash -p <pathspec>"Phillip Wood, Jun 7, 2025
  14. 1/2 stash: allow "git stash -p <pathspec>" to assume push againPhillip Wood, Jun 7, 2025
  15. 2/2 stash: allow "git stash [<options>] --patch <pathspec>" to assume pushPhillip Wood, Jun 7, 2025
  16. Martin ÅgrenJun 7, 2025
  17. Phillip WoodJun 9, 2025
  18. Martin ÅgrenJun 10, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.