git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kyle Meyer <kyle@kyleam.com>
To: git@vger.kernel.org
Cc: Thomas Gummerer <t.gummerer@gmail.com>, joostkremers@fastmail.fm
Subject: [PATCH] stash: disable literal treatment when passing top pathspec
Date: Thu,  7 Apr 2022 23:12:28 -0400	[thread overview]
Message-ID: <20220408031228.782547-1-kyle@kyleam.com> (raw)

do_push_stash() passes ":/" as the pathspec to two subprocess calls.
When pathspecs are interpreted literally for the main process, these
subprocess calls do not behave as intended:

 * the 'git clean' call, triggered by --include-untracked, does not
   remove untracked files from the working tree

 * the 'git checkout' call, triggered by --keep-index, fails with a
   message about ":/" not matching any known files, and the main
   command exits with a non-zero status

Fix both of these spots by passing --no-literal-pathspecs to the
subprocess commands.

Signed-off-by: Kyle Meyer <kyle@kyleam.com>
---
 builtin/stash.c                    | 5 ++++-
 t/t3903-stash.sh                   | 5 +++++
 t/t3905-stash-include-untracked.sh | 5 +++++
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/builtin/stash.c b/builtin/stash.c
index 0c7b6a9588..afc8400c5d 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -1529,7 +1529,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
 					     GIT_WORK_TREE_ENVIRONMENT,
 					     the_repository->worktree);
 			}
-			strvec_pushl(&cp.args, "clean", "--force",
+			strvec_pushl(&cp.args, "--no-literal-pathspecs",
+				     "clean", "--force",
 				     "--quiet", "-d", ":/", NULL);
 			if (include_untracked == INCLUDE_ALL_FILES)
 				strvec_push(&cp.args, "-x");
@@ -1592,6 +1593,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q
 			struct child_process cp = CHILD_PROCESS_INIT;
 
 			cp.git_cmd = 1;
+			if (!ps->nr)
+				strvec_push(&cp.args, "--no-literal-pathspecs");
 			strvec_pushl(&cp.args, "checkout", "--no-overlay",
 				     oid_to_hex(&info.i_tree), "--", NULL);
 			if (!ps->nr)
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index 4abbc8fcca..f85c3a06cb 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1383,6 +1383,11 @@ test_expect_success 'stash --keep-index with file deleted in index does not resu
 	test_path_is_missing to-remove
 '
 
+test_expect_success 'stash --keep-index succeeds with --literal-pathspecs' '
+	echo modified >file &&
+	git --literal-pathspecs stash --keep-index
+'
+
 test_expect_success 'stash apply should succeed with unmodified file' '
 	echo base >file &&
 	git add file &&
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 5390eec4e3..2f216274b2 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -427,5 +427,10 @@ test_expect_success 'stash -u ignores sub-repository' '
 	git init sub-repo &&
 	git stash -u
 '
+test_expect_success 'stash -u works with --literal-pathspecs' '
+	>untracked &&
+	git --literal-pathspecs stash -u &&
+	test_path_is_missing untracked
+'
 
 test_done

base-commit: bf23fe5c37d62f37267d31d4afa1a1444f70cdac
-- 
2.34.0


             reply	other threads:[~2022-04-08  3:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-08  3:12 Kyle Meyer [this message]
2022-04-08  6:33 ` [PATCH] stash: disable literal treatment when passing top pathspec Bagas Sanjaya
2022-04-08  8:46   ` Ævar Arnfjörð Bjarmason
2022-04-08 18:47     ` Junio C Hamano
2022-04-08 18:46 ` Junio C Hamano
2022-04-09  4:10   ` Kyle Meyer
2022-04-11 17:55     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220408031228.782547-1-kyle@kyleam.com \
    --to=kyle@kyleam.com \
    --cc=git@vger.kernel.org \
    --cc=joostkremers@fastmail.fm \
    --cc=t.gummerer@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).