git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Keeping <john@keeping.me.uk>
To: git@vger.kernel.org
Cc: John Keeping <john@keeping.me.uk>, Duy Nguyen <pclouds@gmail.com>,
	Jens Lehmann <Jens.Lehmann@web.de>, Johannes Sixt <j6t@kdbg.org>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 4/4] reset: handle submodule with trailing slash
Date: Thu, 12 Sep 2013 20:25:01 +0100	[thread overview]
Message-ID: <46340e653ef24dec3dcb51e4d88c5ec46f197d82.1379013786.git.john@keeping.me.uk> (raw)
In-Reply-To: <cover.1379013786.git.john@keeping.me.uk>
In-Reply-To: <cover.1379013786.git.john@keeping.me.uk>

When using tab-completion, a directory path will often end with a
trailing slash which currently confuses "git reset" when dealing with
submodules.  Now that we have parse_pathspec we can easily handle this
by simply adding the PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP flag.

To do this, we need to move the read_cache() call before the
parse_pathspec() call.  All of the existing paths through cmd_reset()
that do not die early already call read_cache() at some point, so there
is no performance impact to doing this in the common case.

Signed-off-by: John Keeping <john@keeping.me.uk>
---
 builtin/reset.c            | 8 ++++++--
 t/t7400-submodule-basic.sh | 6 ++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/builtin/reset.c b/builtin/reset.c
index 5e4c551..800117f 100644
--- a/builtin/reset.c
+++ b/builtin/reset.c
@@ -143,7 +143,6 @@ static int read_from_tree(const struct pathspec *pathspec,
 	opt.output_format = DIFF_FORMAT_CALLBACK;
 	opt.format_callback = update_index_from_diff;
 
-	read_cache();
 	if (do_diff_cache(tree_sha1, &opt))
 		return 1;
 	diffcore_std(&opt);
@@ -169,7 +168,7 @@ static void set_reflog_message(struct strbuf *sb, const char *action,
 
 static void die_if_unmerged_cache(int reset_type)
 {
-	if (is_merge() || read_cache() < 0 || unmerged_cache())
+	if (is_merge() || unmerged_cache())
 		die(_("Cannot do a %s reset in the middle of a merge."),
 		    _(reset_type_names[reset_type]));
 
@@ -220,8 +219,13 @@ static void parse_args(struct pathspec *pathspec,
 		}
 	}
 	*rev_ret = rev;
+
+	if (read_cache() < 0)
+		die(_("index file corrupt"));
+
 	parse_pathspec(pathspec, 0,
 		       PATHSPEC_PREFER_FULL |
+		       PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP |
 		       (patch_mode ? PATHSPEC_PREFIX_ORIGIN : 0),
 		       prefix, argv);
 }
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 4192fe0..c268d3c 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -481,7 +481,7 @@ test_expect_success 'do not add files from a submodule' '
 
 '
 
-test_expect_success 'gracefully add submodule with a trailing slash' '
+test_expect_success 'gracefully add/reset submodule with a trailing slash' '
 
 	git reset --hard &&
 	git commit -m "commit subproject" init &&
@@ -495,7 +495,9 @@ test_expect_success 'gracefully add submodule with a trailing slash' '
 	git add init/ &&
 	test_must_fail git diff --exit-code --cached init &&
 	test $commit = $(git ls-files --stage |
-		sed -n "s/^160000 \([^ ]*\).*/\1/p")
+		sed -n "s/^160000 \([^ ]*\).*/\1/p") &&
+	git reset init/ &&
+	git diff --exit-code --cached init
 
 '
 
-- 
1.8.4.277.gfbd6843.dirty

      parent reply	other threads:[~2013-09-12 19:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-10 19:13 [PATCH 0/2] reset: handle submodule with trailing slash John Keeping
2013-09-10 19:13 ` [PATCH 1/2] " John Keeping
2013-09-10 19:37   ` Jens Lehmann
2013-09-10 19:46     ` John Keeping
2013-09-11  6:05   ` Johannes Sixt
2013-09-11  8:20     ` John Keeping
2013-09-11 10:54       ` Duy Nguyen
2013-09-11 11:08         ` John Keeping
2013-09-11 11:20           ` Duy Nguyen
2013-09-11 17:08         ` Junio C Hamano
2013-09-11 17:27           ` John Keeping
2013-09-11 18:14             ` Junio C Hamano
2013-09-11 18:22               ` John Keeping
2013-09-11 18:45                 ` Junio C Hamano
2013-09-10 19:13 ` [PATCH 2/2] rm: re-use parse_pathspec's trailing-slash removal John Keeping
2013-09-11  7:48   ` Duy Nguyen
2013-09-11  8:24     ` John Keeping
2013-09-12 19:24 ` [PATCH v2 0/4] submodule trailing slash improvements John Keeping
2013-09-12 19:24 ` [PATCH v2 1/4] pathspec: use is_dir_sep() to check for trailing slashes John Keeping
2013-09-12 20:17   ` Johannes Sixt
2013-09-12 19:24 ` [PATCH v2 2/4] pathspec: strip multiple trailing slashes from submodules John Keeping
2013-09-12 19:48   ` Junio C Hamano
2013-09-12 20:21     ` John Keeping
2013-09-13  1:28       ` Duy Nguyen
2013-09-13  8:48         ` John Keeping
2013-09-12 19:25 ` [PATCH v2 3/4] rm: re-use parse_pathspec's trailing-slash removal John Keeping
2013-09-12 19:25 ` John Keeping [this message]

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=46340e653ef24dec3dcb51e4d88c5ec46f197d82.1379013786.git.john@keeping.me.uk \
    --to=john@keeping.me.uk \
    --cc=Jens.Lehmann@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    --cc=pclouds@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).