git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH 4/6] check_filename(): handle ":^" path magic
Date: Fri, 26 May 2017 15:08:39 -0400	[thread overview]
Message-ID: <20170526190839.773oeulwzxnl3x3n@sigill.intra.peff.net> (raw)
In-Reply-To: <20170526190607.jr44oygs6mzm3q6e@sigill.intra.peff.net>

We special-case "git log :/foo" to work when "foo" exists in
the working tree. But :^ (and its alias :!) do not get the
same treatment, requiring the user to supply a
disambiguating "--". Let's make them work without requiring
the user to type the "--".

Signed-off-by: Jeff King <peff@peff.net>
---
 setup.c                       |  4 ++++
 t/t4208-log-magic-pathspec.sh | 13 +++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/setup.c b/setup.c
index f2a8070bd..86bb7c9a9 100644
--- a/setup.c
+++ b/setup.c
@@ -141,6 +141,10 @@ int check_filename(const char *prefix, const char *arg)
 		if (!*arg) /* ":/" is root dir, always exists */
 			return 1;
 		prefix = NULL;
+	} else if (skip_prefix(arg, ":!", &arg) ||
+		   skip_prefix(arg, ":^", &arg)) {
+		if (!*arg) /* excluding everything is silly, but allowed */
+			return 1;
 	}
 
 	if (prefix)
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 70bc64100..67250ebdc 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -52,6 +52,19 @@ test_expect_success 'git log HEAD -- :/' '
 	test_cmp expected actual
 '
 
+test_expect_success '"git log :^sub" is not ambiguous' '
+	git log :^sub
+'
+
+test_expect_success '"git log :^does-not-exist" does not match anything' '
+	test_must_fail git log :^does-not-exist
+'
+
+test_expect_success  '"git log :!" behaves the same as :^' '
+	git log :!sub &&
+	test_must_fail git log :!does-not-exist
+'
+
 test_expect_success 'command line pathspec parsing for "git log"' '
 	git reset --hard &&
 	>a &&
-- 
2.13.0.496.ge44ba89db


  parent reply	other threads:[~2017-05-26 19:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-25 15:27 [RFC/PATCH] recognize pathspec magic without "--" disambiguation Jeff King
2017-05-26  2:13 ` Junio C Hamano
2017-05-26 13:24   ` Jeff King
2017-05-26 19:06     ` [PATCH 0/6] make "^:foo" work without disambiguating "--" Jeff King
2017-05-26 19:06       ` [PATCH 1/6] t4208: add check for ":/" without matching file Jeff King
2017-05-26 19:07       ` [PATCH 2/6] check_filename(): refactor ":/" handling Jeff King
2017-05-26 19:07       ` [PATCH 3/6] check_filename(): use skip_prefix Jeff King
2017-05-26 19:08       ` Jeff King [this message]
2017-05-26 19:10       ` [PATCH 5/6] verify_filename(): treat ":(magic)" as a pathspec Jeff King
2017-05-26 19:10       ` [PATCH 6/6] verify_filename(): flip order of checks Jeff King
2017-05-27  9:54 ` [RFC/PATCH] recognize pathspec magic without "--" disambiguation Ævar Arnfjörð Bjarmason
2017-05-27 20:39   ` Jeff King
2017-05-28  0:04     ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20170526190839.773oeulwzxnl3x3n@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).