From: Jens Lehmann <Jens.Lehmann@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Phil Hord <phil.hord@gmail.com>,
Git Mailing List <git@vger.kernel.org>,
Heiko Voigt <hvoigt@hvoigt.net>,
Michael J Gruber <git@drmicha.warpmail.net>,
Marc Branchaud <marcnarc@xiplink.com>,
"W. Trevor King" <wking@tremily.us>
Subject: Re: [PATCH v5] submodule: add 'deinit' command
Date: Mon, 18 Feb 2013 20:20:30 +0100 [thread overview]
Message-ID: <51227EFE.6030908@web.de> (raw)
In-Reply-To: <7v38wufu5t.fsf@alter.siamese.dyndns.org>
Am 17.02.2013 23:32, schrieb Junio C Hamano:
> Jens Lehmann <Jens.Lehmann@web.de> writes:
>> diff --git a/git-submodule.sh b/git-submodule.sh
>> index 004c034..0fb6ee0 100755
>> --- a/git-submodule.sh
>> +++ b/git-submodule.sh
>> @@ -547,6 +548,82 @@ cmd_init()
>> }
>>
>> #
>> +# Unregister submodules from .git/config and remove their work tree
>> +#
>> +# $@ = requested paths (use '.' to deinit all submodules)
>> +#
>> +cmd_deinit()
>> +{
>> + # parse $args after "submodule ... init".
>> + while test $# -ne 0
>> + do
>> ..
>> + done
>> +
>> + if test $# = 0
>> + then
>> + die "$(eval_gettext "Use '.' if you really want to deinitialize all submodules")"
>
> I do not think I saw anybody mentioned this so far, but how is
> "deinit" supposed to work inside a subdirectory of a superproject?
> If the answer is to work on submodules appear in that subdirectory,
> '.' should probably not mean "all in the superproject" I think?
"git submodule" fails when not run in the top level directory.
>> + module_list "$@" |
>> + while read mode sha1 stage sm_path
>> + do
>> + die_if_unmatched "$mode"
>> + name=$(module_name "$sm_path") || exit
>> + url=$(git config submodule."$name".url)
>> + if test -z "$url"
>> + then
>> + test $# -ne 1 || test "$@" = "." ||
>> + say "$(eval_gettext "Submodule '\$name' is not initialized for path '\$sm_path'")"
>> + continue
>> + fi
>
> This 'test "$@" = "."' makes readers feel uneasy. This particular
> invocation happens to be safe only because it is protected with
> "test $# -ne 1 ||", but for all other values of $# this will result
> in a syntax error. 'test "$1" = "."' would make the intention of
> the check more clear.
I used $@ here because it makes the code more robust against
someone accidentally removing the "test $# -ne 1 ||" (as it then
will fail when $# > 1 in one of the tests). But looking at it
again I agree that "$1" might better show the intention here and
the "$@" can easily make people suspicious.
> But stepping back a bit, is the condition this test is trying to
> warn against really worth warning?
>
> It seems that this "warn if user told us to deinitialize a submodule
> that hasn't been initialized" is from the very initial round of this
> series, and not something other people asked for during the review.
> If somebody did
>
> git submodule deinit foo bar
>
> and then later said:
>
> git submodule deinit foo
>
> would it a mistake that the user wants to be warned about?
>
> Perhaps the user did not mean to deinitialize foo (e.g. wanted to
> *initialize* foo instead, or wanted to deinitialize *foz* instead)
> and that is worth warning about? I am not sure, but I have a
> feeling that we can do without this check.
Hmm, if you would replace "submodule deinit" with "rm" in the above
example, the "rm" would not only warn but error out the second time.
But on the other hand doing a "git submodule init" again on already
initialized submodules will silently do nothing, which seems to be
the better analogy here. So yes, it looks like we can do without.
Ok, unless someone speaks up and argues in favor of this message
I'll remove it in v6.
> Also the value of submodule.$name.url is not used in the later
> codepath to ensure that the named submodule is in the pristine state
> in the superproject's working tree (i.e. no submodule.$name section
> in the local configuration, no working tree for that submodule), so
> it may be even a good change to remove the "does submodule.$name.url
> exist" check and always do the "deinitialize" process. That would
> give the users a way to recover from a state where a submodule is
> only half initialized for some reason safely, no?
That is a very good point. It makes sense that if we don't nuke the
whole test to at least remove the "continue" there (in case someone
fiddled with .git/config but wants to get rid of the work tree in a
safe manner later).
next prev parent reply other threads:[~2013-02-18 19:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-06 21:11 [PATCH v4] submodule: add 'deinit' command Jens Lehmann
2013-02-12 17:11 ` Phil Hord
2013-02-12 18:03 ` Junio C Hamano
2013-02-13 19:33 ` Jens Lehmann
2013-02-13 19:56 ` Junio C Hamano
2013-02-17 20:06 ` [PATCH v5] " Jens Lehmann
2013-02-17 22:32 ` Junio C Hamano
2013-02-18 19:20 ` Jens Lehmann [this message]
2013-03-04 21:20 ` [PATCH v6] " Jens Lehmann
2013-03-05 7:29 ` Heiko Voigt
2013-03-05 15:45 ` Junio C Hamano
2013-03-06 6:52 ` Heiko Voigt
2013-03-12 15:39 ` [PATCH v4] " Phil Hord
2013-03-12 16:22 ` Junio C Hamano
2013-03-18 20:54 ` Jens Lehmann
2013-03-19 1:45 ` Junio C Hamano
2013-04-01 19:02 ` [PATCH] submodule deinit: clarify work tree removal message Jens Lehmann
2013-04-16 13:32 ` Phil Hord
2013-04-16 20:47 ` [PATCH] submodule deinit: don't output "Cleared directory" when directory is empty Jens Lehmann
2013-04-17 5:16 ` [PATCH] submodule deinit: clarify work tree removal message Junio C Hamano
2013-04-17 20:30 ` Jens Lehmann
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=51227EFE.6030908@web.de \
--to=jens.lehmann@web.de \
--cc=git@drmicha.warpmail.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=hvoigt@hvoigt.net \
--cc=marcnarc@xiplink.com \
--cc=phil.hord@gmail.com \
--cc=wking@tremily.us \
/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).