bisect--helper: warn if we are assuming an unlikely pathspec
PATCH 1/1 bisect--helper: warn if we are assuming an unlikely pathspec
Commit 73c6de06aff8 ("bisect: don't use invalid oid as rev when starting") changes the behaviour to consider invalid oids as pathspecs again, as in the old shell implementation.
While that behaviour may be desirable, it can also cause confusion. For example, while bisecting in a particular repo I encountered this:
$ git bisect start d93ff48803f0 v6.3
$...which led to me sitting for a few moments, wondering why there's no printout stating the first rev to check.
It turns out that the tag was actually "6.3", not "v6.3", and thus the bisect was still silently started with only a bad rev, because d93ff48803f0 was a valid oid and "v6.3" was silently considered to be a pathspec.
While this behaviour may be desirable, it can be confusing, especially with different repo conventions either using or not using "v" before release names, or when a branch name or tag is simply misspelled on the command line.
In order to avoid this, emit a warning when we are assuming an argument is a pathspec, but no such path exists in the checkout and this doesn't look like a pathspec according to looks_like_pathspec:
$ git bisect start d93ff48803f0 v6.3
warning: assuming 'v6.3' is a path
$If the filename is after the double dash, assume the user knows what they're doing, just like with other git commands.
--- builtin/bisect--helper.c | 4 ++++ cache.h | 1 + setup.c | 2 +- t/t6030-bisect-porcelain.sh | 18 ++++++++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-)
builtin/bisect--helper.c +4 -0
@@ -682,6 +682,10 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **adie (_ ("'%s' does not appear to be a valid " "revision" ), arg); }else { +if (!has_double_dash && + !looks_like_pathspec (arg) && + !check_filename (NULL , arg)) +warning (_ ("assuming '%s' is a path" ), arg);break ; } }
cache.h +1 -0
@@ -648,6 +648,7 @@ void verify_filename(const char *prefix, int diagnose_misspelt_rev);void verify_non_filename (const char *prefix,const char *name);int path_inside_repo (const char *prefix,const char *path); +int looks_like_pathspec (const char *arg);#define INIT_DB_QUIET 0x0001#define INIT_DB_EXIST_OK 0x0002
setup.c +1 -1
@@ -208,7 +208,7 @@ static void NORETURN die_verify_filename(struct repository *r,* but which look sufficiently like pathspecs that we'll consider * them such for the purposes of rev/pathspec DWIM parsing. */ -static int looks_like_pathspec (const char *arg) +int looks_like_pathspec (const char *arg) {const char *p;int escaped =0 ;
t/t6030-bisect-porcelain.sh +18 -0
@@ -1025,4 +1025,22 @@ test_expect_success 'bisect visualize with a filename with dash and space' ' git bisect visualize -p -- "-hello 2" ' +test_expect_success 'bisect warning on implicit enoent pathspec' ' + git bisect reset && + git bisect start "$HASH4" doesnotexist 2>output && + grep -F "assuming '\''doesnotexist'\'' is a path" output +' + +test_expect_success 'bisect fatal on implicit enoent pathspec with dash' ' + git bisect reset && + test_must_fail git bisect start "$HASH4" doesnotexist -- dne2 2>output && + grep -F "'\''doesnotexist'\'' does not appear to be a valid revision" output +' + +test_expect_success 'bisect no warning on explicit enoent pathspec' ' + git bisect reset && + git bisect start "$HASH4" -- doesnotexist 2>output && + [ -z "$(cat output)" ] +' + test_done
Signature · 1 line
2.36.0
Quoted 8 lines · Chris Down
In order to avoid this, emit a warning when we are assuming an argument is a pathspec, but no such path exists in the checkout and this doesn't look like a pathspec according to
looks_like_pathspec:$ git bisect start d93ff48803f0 v6.3 warning: assuming 'v6.3' is a path $
For completeness, we can say 'If this is incorrect, abort the current bisection with "git bisect reset" and rerun with correct commit-ish.'.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Quoted 5 lines · Bagas Sanjaya
Quoted 4 lines · Chris Down
In order to avoid this, emit a warning when we are assuming an argument is a pathspec, but no such path exists in the checkout and this doesn't look like a pathspec according to
looks_like_pathspec:
Quoted 7 lines
Quoted 4 lines
$ git bisect start d93ff48803f0 v6.3 warning: assuming 'v6.3' is a path $For completeness, we can say 'If this is incorrect, abort the current bisection with "git bisect reset" and rerun with correct commit-ish.'.
We certainly can, but I am not sure how much it helps.
Even though I understand that the original end-user confusion happened to come from taking what the user thought was a revision as pathspec, I think it is a mistake to build the "warning" UI around it.
Stepping back a bit, there are "git bisect" invocations that compute and check out the commit to be tested, and there are "git bisect" invocations that only advance the internal state a bit but not yet become ready to offer the first commit to be tested. The problem in the current UI is that we are fairly chatty once we start bisecting, but until we receive enough information to start bisecting, we are fairly silent.
Even if the user did not use the lazy short-hand form of "bisect start" with bad and good commits at all, after saying "git bisect good <X>" (read: it is a state that made a bit of progress but still not ready, because the command wants to see at least one bad commit, too), wouldn't it be nice if the user is told what state the command is in? Perhaps we can give some feedback _before_ we are ready to compute bisection?
A model dialogue may go like this.
$ git bisect start -- bin/
info: bisect waiting for good and bad commits.
$ git bisect good master
info: bisect waiting for a bad commit, one good commit known.
$ git bisect good maint
info: bisect waiting for a bad commit, two good commits known.
$ git bisect bad next
Bisecting: ...Then the exchange for the lazy short-hand form of "bisect start" would fall out quite naturally.
$ git bisect start d93ff48803f0 -- v6.3
info: bisect waiting for a good commit, one bad commit known.For a bonus point, we may want to also say something on these "info:" lines that we were given a pathspec.
It would also be a good idea to add a new subcommand "git bisect status" to recompute the state (i.e. what it is waiting for and what it already knows) when the user forgets, which can happen quite often.
With such a bonus feature, the exchange might go like this:
$ git bisect start seen
info: bisect waiting for a good commit, a bad commit known.
$ git reset --hard maint ;# choose an older point, hoping it is good.
$ make test
... pages of output scrolls the "info:" out of window ...
$ git bisect status
info: bisect waiting for a good commit, a bad commit known.
$ git bisect bad maint
info: bisect waiting for a good commit, a bad commit known.
$ git reset --hard v1.0 ;# an even older point, hoping it is good.
$ make test
... again pages of output ...
$ git bisect good v1.0
Bisecting ...Hmm?
Quoted 17 lines · Junio C Hamano
A model dialogue may go like this.
$ git bisect start -- bin/ info: bisect waiting for good and bad commits. $ git bisect good master info: bisect waiting for a bad commit, one good commit known. $ git bisect good maint info: bisect waiting for a bad commit, two good commits known. $ git bisect bad next Bisecting: ...Then the exchange for the lazy short-hand form of "bisect start" would fall out quite naturally.
$ git bisect start d93ff48803f0 -- v6.3 info: bisect waiting for a good commit, one bad commit known.
Quoted 6 lines
For a bonus point, we may want to also say something on these "info:" lines that we were given a pathspec.
It would also be a good idea to add a new subcommand "git bisect status" to recompute the state (i.e. what it is waiting for and what it already knows) when the user forgets, which can happen quite often.
Sounds good.
Quoted 17 lines
With such a bonus feature, the exchange might go like this:
$ git bisect start seen info: bisect waiting for a good commit, a bad commit known. $ git reset --hard maint ;# choose an older point, hoping it is good. $ make test ... pages of output scrolls the "info:" out of window ... $ git bisect status info: bisect waiting for a good commit, a bad commit known. $ git bisect bad maint info: bisect waiting for a good commit, a bad commit known. $ git reset --hard v1.0 ;# an even older point, hoping it is good. $ make test ... again pages of output ... $ git bisect good v1.0 Bisecting ...
Quoted 1 line
Hmm?
I'll wait a few days to see if anyone else has any other feedback, and then I'll send a patch to that effect.
Thanks!