git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] submodule helper: accept '.' for repositories with no submodules
@ 2016-03-22 17:59 Stefan Beller
  2016-03-22 18:53 ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 17:59 UTC (permalink / raw)
  To: gitster, cederp; +Cc: Jens.Lehmann, git, Stefan Beller

In 74703a1e4d (2015-09-02, submodule: rewrite `module_list` shell
function in C), "submodule deinit ." was broken.

The original module_list accepted '.' as a pathspec just fine, as it
was using

  git ls-files -z --error-unmatch --stage -- "$@" || { custom filtering}

and git ls-files doesn't make a difference between "." and no arguments
there. When using the parse_pathspec function in C, this is a difference
however, when no path matches.

'submodule deinit' asks users to explicitely to give '.' instead of
empty arguments to specify all submodules (as a safety measure?),
so we have to support that as well.

Add a test case to prevent this error coming up again and fix this
by special casing '.' in the new module_list to reduce the difference
between the old and new module_list.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

 This applies on v2.7.4
 
 I looked at alternatives of how to fix it, e.g.
 later in module_list to make an exception for calling
        if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
             result = -1;
 but that is similarly ugly.

 builtin/submodule--helper.c |  8 ++++++++
 t/t7400-submodule-basic.sh  | 10 ++++++++++
 2 files changed, 18 insertions(+)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ed764c9..47e6839 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -23,6 +23,14 @@ static int module_list_compute(int argc, const char **argv,
 {
 	int i, result = 0;
 	char *ps_matched = NULL;
+
+	/*
+	 * We need to treat a path spec of '.' the same as an empty
+	 * path spec, because "submodule deinit" wants to be given '.'
+	 * instead of an empty list.
+	 */
+	if (argc == 1 && !strcmp(".", argv[0]))
+		argv[0] = NULL;
 	parse_pathspec(pathspec, 0,
 		       PATHSPEC_PREFER_FULL |
 		       PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index be82a75..fdf7105 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -849,6 +849,16 @@ test_expect_success 'set up a second submodule' '
 	git commit -m "submodule example2 added"
 '
 
+test_expect_success 'submodule deinit -f . works on empty repository' '
+	test_when_finished "rm -rf newdirectory" &&
+	mkdir newdirectory &&
+	(
+		cd newdirectory &&
+		git init &&
+		git submodule deinit .
+	)
+'
+
 test_expect_success 'submodule deinit should remove the whole submodule section from .git/config' '
 	git config submodule.example.foo bar &&
 	git config submodule.example2.frotz nitfol &&
-- 
2.7.4.1.g33fcf9d

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 17:59 [PATCH] submodule helper: accept '.' for repositories with no submodules Stefan Beller
@ 2016-03-22 18:53 ` Junio C Hamano
  2016-03-22 19:30   ` Stefan Beller
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2016-03-22 18:53 UTC (permalink / raw)
  To: Stefan Beller; +Cc: cederp, Jens.Lehmann, git

Stefan Beller <sbeller@google.com> writes:

> In 74703a1e4d (2015-09-02, submodule: rewrite `module_list` shell
> function in C), "submodule deinit ." was broken.
>
> The original module_list accepted '.' as a pathspec just fine, as it
> was using
>
>   git ls-files -z --error-unmatch --stage -- "$@" || { custom filtering}
>
> and git ls-files doesn't make a difference between "." and no arguments
> there. When using the parse_pathspec function in C, this is a difference
> however, when no path matches.

Is that an accurate description of the issue?

The original (above) errors out if there is a pathspec that does not
match any path in the index.  The C rewrite however instead does
this:

		if (!S_ISGITLINK(ce->ce_mode) ||
		    !match_pathspec(pathspec, ce->name, ce_namelen(ce),
				    0, ps_matched, 1))
			continue;

to error out if there is a pathspec that does not match any
submodule path.  That is the root cause of the difference in
behaviour.

So if we were to aim for a faithful rewrite, perhaps swapping the
order of the check, i.e.

		if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
				    0, ps_matched, 1) ||
		    !S_ISGITLINK(ce->ce_mode))
			continue;

Now, arguably, the behaviour of C rewrite makes more sense in that
it would diagnose a pathspec that does not match a submodule as an
error, e.g.

	$ git submodule--helper list 'COPYIN*'
	error: pathspec 'COPYIN*' did not match any file(s) known to git.
	#unmatched

The error message _is_ wrong, but the end result is more helpful to
the user---the user thought there was a submodule that would match
that pathspec, and there isn't, so we suspect there was a typo and
cautiously error out.

"submodule deinit ." may have "worked" in the sense that you would
have at least one path in your tree and avoided this "nothing
matches" most of the time.  It would have still failed with the
exactly same error if run in an empty repository, i.e.

	$ E=/var/tmp/x/empty && rm -fr "$E" && mkdir -p "$E" && cd "$E"
        $ git init
        $ rungit v2.6.6 submodule deinit .
        error: pathspec '.' did not match any file(s) known to git.
	Did you forget to 'git add'?
	$ >file && git add file
        $ rungit v2.6.6 submodule deinit .
	$ echo $?
	0

In other words, "Use '.' if you really want to" is a faulty
suggestion.  There is no guarantee that it would match anything in
the old world order, and certainly there is no guarantee that it
would match any submodule in the new world order.

When another person who is not Per Cederqvist realizes that the
logic that issues the faulty suggestion is because the command wants
some pathspec, she may try

    $ git submodule deinit '*'

and complain that it used to work but it no longer, even with the
band-aid patch under discussion that special cases '.'.

So I dunno.  This is not only "deinit", but also the post rewrite
version catches

	$ git submodule init -- 'COPYIN*'

as an error, which we probably would want to keep, so I am reluctant
to suggest swapping the order of the check to do pathspec first and
then gitlink-ness (it has performance implications but correctness
is a more important issue), but if we want to keep the backward
compatibility, that would be the best bug-to-bug compatible fix in
the shorter term.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 18:53 ` Junio C Hamano
@ 2016-03-22 19:30   ` Stefan Beller
  2016-03-22 20:06     ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 19:30 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

On Tue, Mar 22, 2016 at 11:53 AM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> In 74703a1e4d (2015-09-02, submodule: rewrite `module_list` shell
>> function in C), "submodule deinit ." was broken.
>>
>> The original module_list accepted '.' as a pathspec just fine, as it
>> was using
>>
>>   git ls-files -z --error-unmatch --stage -- "$@" || { custom filtering}
>>
>> and git ls-files doesn't make a difference between "." and no arguments
>> there. When using the parse_pathspec function in C, this is a difference
>> however, when no path matches.
>
> Is that an accurate description of the issue?
>
> The original (above) errors out if there is a pathspec that does not
> match any path in the index.  The C rewrite however instead does
> this:
>
>                 if (!S_ISGITLINK(ce->ce_mode) ||
>                     !match_pathspec(pathspec, ce->name, ce_namelen(ce),
>                                     0, ps_matched, 1))
>                         continue;
>
> to error out if there is a pathspec that does not match any
> submodule path.  That is the root cause of the difference in
> behaviour.
>
> So if we were to aim for a faithful rewrite, perhaps swapping the
> order of the check, i.e.
>
>                 if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
>                                     0, ps_matched, 1) ||
>                     !S_ISGITLINK(ce->ce_mode))
>                         continue;
>
> Now, arguably, the behaviour of C rewrite makes more sense in that
> it would diagnose a pathspec that does not match a submodule as an
> error, e.g.
>
>         $ git submodule--helper list 'COPYIN*'
>         error: pathspec 'COPYIN*' did not match any file(s) known to git.
>         #unmatched
>
> The error message _is_ wrong, but the end result is more helpful to
> the user---the user thought there was a submodule that would match
> that pathspec, and there isn't, so we suspect there was a typo and
> cautiously error out.
>
> "submodule deinit ." may have "worked" in the sense that you would
> have at least one path in your tree and avoided this "nothing
> matches" most of the time.  It would have still failed with the
> exactly same error if run in an empty repository, i.e.
>
>         $ E=/var/tmp/x/empty && rm -fr "$E" && mkdir -p "$E" && cd "$E"
>         $ git init
>         $ rungit v2.6.6 submodule deinit .
>         error: pathspec '.' did not match any file(s) known to git.
>         Did you forget to 'git add'?
>         $ >file && git add file
>         $ rungit v2.6.6 submodule deinit .
>         $ echo $?
>         0
>
> In other words, "Use '.' if you really want to" is a faulty
> suggestion.  There is no guarantee that it would match anything in
> the old world order, and certainly there is no guarantee that it
> would match any submodule in the new world order.
>
> When another person who is not Per Cederqvist realizes that the
> logic that issues the faulty suggestion is because the command wants
> some pathspec, she may try
>
>     $ git submodule deinit '*'
>
> and complain that it used to work but it no longer, even with the
> band-aid patch under discussion that special cases '.'.
>
> So I dunno.  This is not only "deinit", but also the post rewrite
> version catches
>
>         $ git submodule init -- 'COPYIN*'
>
> as an error, which we probably would want to keep, so I am reluctant
> to suggest swapping the order of the check to do pathspec first and
> then gitlink-ness (it has performance implications but correctness
> is a more important issue), but if we want to keep the backward
> compatibility, that would be the best bug-to-bug compatible fix in
> the shorter term.

So I have 2 goals in mind:
* Git suggested to use '.' explicitly, so it should just work --even
for a completely
  empty repository (see the test for it)
* Eventually -- not in this patch, but a later patch targeted at
master -- we want to
  remove the recommendation to use '.', and allow no arguments or a
different argument
  for "all submodules". git add uses '.' for it though, so '.' seems
right and valid.
  git add '*' is also valid.

Maybe combine the second idea with a slight refactoring of
parse_pathspec, such that you
can pass a callback function to parse_pathspec which can decided on
each file if it is
a file to inspect. (i.e. for our usecase we'd check for ce_mode to be
GITLINK, another
hypothetical use case would be using parse_pathspec for finding all
files with a certain
property, e.g. finding all files ending in .c or files written in all
capital letters or such)

Then you could do a conditional parse_pathspec over the partial
repository which matched
the additional filtering function.


Maybe we can also special case the "force" argument only here for
Cedars use case.
("git submodule deinit ." complains because there are no further
submodules, but -f solves
the complaint?)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 19:30   ` Stefan Beller
@ 2016-03-22 20:06     ` Junio C Hamano
  2016-03-22 21:16       ` Stefan Beller
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2016-03-22 20:06 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> Maybe we can also special case the "force" argument only here for
> Cedars use case.  ("git submodule deinit ." complains because
> there are no further submodules, but -f solves the complaint?)

I think that would have been the most sensible thing to do when
we were adding "git submodule deinit", and it would be the most
sensible behaviour in the longer term.


> So I have 2 goals in mind:

> * Git suggested to use '.' explicitly, so it should just work
> --even for a completely empty repository (see the test for it)

I actually view this as either a low-prio goal or even a
non-goal, as long as we have a sensible migration plan to stop
suggesting '.'.

> * Eventually -- not in this patch, but a later patch targeted
> at master -- we want to remove the recommendation to use '.',
> and allow no arguments or a different argument for "all
> submodules".

> git add uses '.' for it though, so '.' seems right and valid.
> git add '*' is also valid.

Perhaps I am misunderstanding what you want.  Do you want a
regular file that happens to match pathspec to prevent
module_list from noticing "pathspec did not match" situation and
giving the user an error?  That would be the "match-pathspec first
and then mode-check" behaviour, that is the same as v2.6.x
series [*1*].

> Maybe combine the second idea with a slight refactoring of
> parse_pathspec, such that you can pass a callback function to
> parse_pathspec which can decided on each file if it is a file
> to inspect. (i.e. for our usecase we'd check for ce_mode to be
> GITLINK, another hypothetical use case would be using
> parse_pathspec for finding all files with a certain property,
> e.g. finding all files ending in .c or files written in all
> capital letters or such)
>
> Then you could do a conditional parse_pathspec over the partial
> repository which matched
> the additional filtering function.
>

I do not think that buys us much.  You have already shown how to
implement "filter first and then pathspec match" if a caller
wants to (which turned out to be a regression in this case, but
that is besides the point).



[Footnote]

*1* If not, then similaritly with "git add" does not have much
    to do with what module_list() should do.  "git add $pathspec"
    fails if there is nothing that matches the pathspec, but
    "module_list" wants to complain if $pathspec does not match
    any submodule.  And it is an accident that "git add ." in
    an empty directory does not complain (indeed "git add '*'"
    does complain because it sidesteps the accident).

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 20:06     ` Junio C Hamano
@ 2016-03-22 21:16       ` Stefan Beller
  2016-03-22 21:38         ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 21:16 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

On Tue, Mar 22, 2016 at 1:06 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> Maybe we can also special case the "force" argument only here for
>> Cedars use case.  ("git submodule deinit ." complains because
>> there are no further submodules, but -f solves the complaint?)
>
> I think that would have been the most sensible thing to do when
> we were adding "git submodule deinit", and it would be the most
> sensible behaviour in the longer term.
>
>
>> So I have 2 goals in mind:
>
>> * Git suggested to use '.' explicitly, so it should just work
>> --even for a completely empty repository (see the test for it)
>
> I actually view this as either a low-prio goal or even a
> non-goal, as long as we have a sensible migration plan to stop
> suggesting '.'.
>
>> * Eventually -- not in this patch, but a later patch targeted
>> at master -- we want to remove the recommendation to use '.',
>> and allow no arguments or a different argument for "all
>> submodules".
>
>> git add uses '.' for it though, so '.' seems right and valid.
>> git add '*' is also valid.
>
> Perhaps I am misunderstanding what you want.  Do you want a
> regular file that happens to match pathspec to prevent
> module_list from noticing "pathspec did not match" situation and
> giving the user an error?  That would be the "match-pathspec first
> and then mode-check" behaviour, that is the same as v2.6.x
> series [*1*].
>
>> Maybe combine the second idea with a slight refactoring of
>> parse_pathspec, such that you can pass a callback function to
>> parse_pathspec which can decided on each file if it is a file
>> to inspect. (i.e. for our usecase we'd check for ce_mode to be
>> GITLINK, another hypothetical use case would be using
>> parse_pathspec for finding all files with a certain property,
>> e.g. finding all files ending in .c or files written in all
>> capital letters or such)
>>
>> Then you could do a conditional parse_pathspec over the partial
>> repository which matched
>> the additional filtering function.
>>
>
> I do not think that buys us much.  You have already shown how to
> implement "filter first and then pathspec match" if a caller
> wants to (which turned out to be a regression in this case, but
> that is besides the point).

And by including this filtering into the pathspec machine we can pass
a flag DONT_BREAK_ON_NO_FILTER_RESULTS_WHEN_HAVING_OTHER_MATCHES
(name for illustration purpose only ;) which is how I understand this
regression?

>
>
>
> [Footnote]
>
> *1* If not, then similaritly with "git add" does not have much
>     to do with what module_list() should do.  "git add $pathspec"
>     fails if there is nothing that matches the pathspec, but
>     "module_list" wants to complain if $pathspec does not match
>     any submodule.  And it is an accident that "git add ." in
>     an empty directory does not complain (indeed "git add '*'"
>     does complain because it sidesteps the accident).
>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 21:16       ` Stefan Beller
@ 2016-03-22 21:38         ` Junio C Hamano
  2016-03-22 21:47           ` Stefan Beller
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2016-03-22 21:38 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

>> I do not think that buys us much.  You have already shown how to
>> implement "filter first and then pathspec match" if a caller
>> wants to (which turned out to be a regression in this case, but
>> that is besides the point).
>
> And by including this filtering into the pathspec machine we can pass
> a flag DONT_BREAK_ON_NO_FILTER_RESULTS_WHEN_HAVING_OTHER_MATCHES
> (name for illustration purpose only ;) which is how I understand this
> regression?

But you do not even need that if you fix the regression with
something like this, no?  Do we need to add complexity to pathspec
machinery only to make it easier to misuse it and then add another
DONT_BREAK_... band-aid to fix a bug that can come from such a
misuse?

 builtin/submodule--helper.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index ed764c9..740b57a 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -37,10 +37,11 @@ static int module_list_compute(int argc, const char **argv,
 	for (i = 0; i < active_nr; i++) {
 		const struct cache_entry *ce = active_cache[i];
 
-		if (!S_ISGITLINK(ce->ce_mode) ||
-		    !match_pathspec(pathspec, ce->name, ce_namelen(ce),
+		if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
 				    0, ps_matched, 1))
 			continue;
+		if (!S_ISGITLINK(ce->ce_mode))
+			continue;
 
 		ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
 		list->entries[list->nr++] = ce;

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 21:38         ` Junio C Hamano
@ 2016-03-22 21:47           ` Stefan Beller
  2016-03-22 22:04             ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 21:47 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

On Tue, Mar 22, 2016 at 2:38 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>>> I do not think that buys us much.  You have already shown how to
>>> implement "filter first and then pathspec match" if a caller
>>> wants to (which turned out to be a regression in this case, but
>>> that is besides the point).
>>
>> And by including this filtering into the pathspec machine we can pass
>> a flag DONT_BREAK_ON_NO_FILTER_RESULTS_WHEN_HAVING_OTHER_MATCHES
>> (name for illustration purpose only ;) which is how I understand this
>> regression?
>
> But you do not even need that if you fix the regression with
> something like this, no?  Do we need to add complexity to pathspec
> machinery only to make it easier to misuse it and then add another
> DONT_BREAK_... band-aid to fix a bug that can come from such a
> misuse?
>
>  builtin/submodule--helper.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
> index ed764c9..740b57a 100644
> --- a/builtin/submodule--helper.c
> +++ b/builtin/submodule--helper.c
> @@ -37,10 +37,11 @@ static int module_list_compute(int argc, const char **argv,
>         for (i = 0; i < active_nr; i++) {
>                 const struct cache_entry *ce = active_cache[i];
>
> -               if (!S_ISGITLINK(ce->ce_mode) ||
> -                   !match_pathspec(pathspec, ce->name, ce_namelen(ce),
> +               if (!match_pathspec(pathspec, ce->name, ce_namelen(ce),
>                                     0, ps_matched, 1))
>                         continue;
> +               if (!S_ISGITLINK(ce->ce_mode))
> +                       continue;
>
>                 ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
>                 list->entries[list->nr++] = ce;


This patch is conceptually, what you said in the first message as

> So I dunno.  This is not only "deinit", but also the post rewrite
> version catches
>
>         $ git submodule init -- 'COPYIN*'
>
> as an error, which we probably would want to keep, so I am reluctant
> to suggest swapping the order of the check to do pathspec first and
> then gitlink-ness (it has performance implications but correctness
> is a more important issue), but if we want to keep the backward
> compatibility, that would be the best bug-to-bug compatible fix in
> the shorter term.

I was under the impression that we do not want to have this bugfix
(at least long term) and then I tried to come up with an idea, which
is both:
* correct in this case
* and catches the git submodule init -- 'COPYIN*' case as failure

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 21:47           ` Stefan Beller
@ 2016-03-22 22:04             ` Junio C Hamano
  2016-03-22 22:10               ` Stefan Beller
  0 siblings, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2016-03-22 22:04 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> I was under the impression that we do not want to have this bugfix
> (at least long term) and then I tried to come up with an idea,
> which is both:
> * correct in this case
> * and catches the git submodule init -- 'COPYIN*' case as failure

Satisfying both has to be impossible, I am afraid, so coming up with
an idea to do so may be futile.

If "git submodule $subcmd -- 'COPYIN*'" must fail (which I think is
a good property to have), then "git submodule $subcmd -- ." must
fail if there is no submodule in the repository, I would think, if
we want to be consistent.  Both are complaining not just because
there is no path that match the given pathspec, but because there is
no submodule that match the given pathspec.

That is why I said I was in favour of giving some _other_ way, other
than "this is guaranteed to match some submodule" pathspec (which
fundamentally does not exist, because there are projects that do not
have any submodule in them), as a suggestion for "deinit all"
safety.

A slight tangent.

We have --error-unmatch in ls-files to detect pathspec that did not
hit anything, and our Porcelain commands treat a pathspec that does
not hit anything as an error, but there probably need to be
"--unmatch-ok" option?  I.e.

	$ git add 'A*'
        fatal: pathspec 'A*' did not match any files
        $ git add --unmatch-ok 'A*'
        ... nothing is added but we do not get an error ...

Then the interaction may go like this:

	$ git submodule deinit
        You need to limit submodules to deinit with some pathspec
        $ git submodule deinit .
        fatal: pathspec '.' did not match any submodule
        $ git submodule deinit --unmatch-ok .
        ... nothing deinited but we do not get an error ...

For this particular one,

	$ git submodule deinit --force

may be also OK, but there may be _other_ conditions that you may
allow overriding in "deinit" operation (e.g. we may refuse to deinit
when there are unsaved/unuploaded changes, and allow --force to
override it), so...

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 22:04             ` Junio C Hamano
@ 2016-03-22 22:10               ` Stefan Beller
  2016-03-22 22:50                 ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Beller @ 2016-03-22 22:10 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

On Tue, Mar 22, 2016 at 3:04 PM, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Beller <sbeller@google.com> writes:
>
>> I was under the impression that we do not want to have this bugfix
>> (at least long term) and then I tried to come up with an idea,
>> which is both:
>> * correct in this case
>> * and catches the git submodule init -- 'COPYIN*' case as failure
>
> Satisfying both has to be impossible, I am afraid, so coming up with
> an idea to do so may be futile.
>
> If "git submodule $subcmd -- 'COPYIN*'" must fail (which I think is
> a good property to have), then "git submodule $subcmd -- ." must
> fail if there is no submodule in the repository, I would think, if
> we want to be consistent.  Both are complaining not just because
> there is no path that match the given pathspec, but because there is
> no submodule that match the given pathspec.
>
> That is why I said I was in favour of giving some _other_ way, other
> than "this is guaranteed to match some submodule" pathspec (which
> fundamentally does not exist, because there are projects that do not
> have any submodule in them), as a suggestion for "deinit all"
> safety.
>
> A slight tangent.
>
> We have --error-unmatch in ls-files to detect pathspec that did not
> hit anything, and our Porcelain commands treat a pathspec that does
> not hit anything as an error, but there probably need to be
> "--unmatch-ok" option?  I.e.
>
>         $ git add 'A*'
>         fatal: pathspec 'A*' did not match any files
>         $ git add --unmatch-ok 'A*'
>         ... nothing is added but we do not get an error ...
>
> Then the interaction may go like this:
>
>         $ git submodule deinit
>         You need to limit submodules to deinit with some pathspec
>         $ git submodule deinit .
>         fatal: pathspec '.' did not match any submodule
>         $ git submodule deinit --unmatch-ok .
>         ... nothing deinited but we do not get an error ...
>
> For this particular one,
>
>         $ git submodule deinit --force
>
> may be also OK, but there may be _other_ conditions that you may
> allow overriding in "deinit" operation (e.g. we may refuse to deinit
> when there are unsaved/unuploaded changes, and allow --force to
> override it), so...

That sounds better thought than my thinking.
So for now I would send the performance regressing flip of IS_GITLINK
and match_pathspec targeting 2.7 and then add a --unmatch-ok switch
for 2.8 and later?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] submodule helper: accept '.' for repositories with no submodules
  2016-03-22 22:10               ` Stefan Beller
@ 2016-03-22 22:50                 ` Junio C Hamano
  0 siblings, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2016-03-22 22:50 UTC (permalink / raw)
  To: Stefan Beller; +Cc: Per Cederqvist, Jens Lehmann, git@vger.kernel.org

Stefan Beller <sbeller@google.com> writes:

> So for now I would send the performance regressing flip of
> IS_GITLINK and match_pathspec targeting 2.7 and then add a
> --unmatch-ok switch for 2.8 and later?

"git submodule $subcommand -- COPYIN\*" that detects that there is
no submodule that match the pathspec and errors out, which is what
the C rewrite does, is a new feature that was done by accident when
we should have been doing a faithful translation.

I'd say bug-to-bug-compatible regression fix is appropriate for 2.8
and below; the "check ce-mode first and then pathspec match" should
be done as a new feature after 2.8 final, and if --unmatch-ok is
necessary to make the feature work better, that, too, should come in
the same timeframe.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-03-22 22:50 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-22 17:59 [PATCH] submodule helper: accept '.' for repositories with no submodules Stefan Beller
2016-03-22 18:53 ` Junio C Hamano
2016-03-22 19:30   ` Stefan Beller
2016-03-22 20:06     ` Junio C Hamano
2016-03-22 21:16       ` Stefan Beller
2016-03-22 21:38         ` Junio C Hamano
2016-03-22 21:47           ` Stefan Beller
2016-03-22 22:04             ` Junio C Hamano
2016-03-22 22:10               ` Stefan Beller
2016-03-22 22:50                 ` Junio C Hamano

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).