All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: John Keeping <john@keeping.me.uk>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Re: [BUG] git-submodule has bash-ism?
Date: Wed, 01 Jun 2016 12:45:11 -0700	[thread overview]
Message-ID: <xmqqinxsy9q0.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20160601191621.GO1355@john.keeping.me.uk> (John Keeping's message of "Wed, 1 Jun 2016 20:16:21 +0100")

John Keeping <john@keeping.me.uk> writes:

> On Wed, Jun 01, 2016 at 03:07:59PM -0400, Jeff King wrote:
>> On Wed, Jun 01, 2016 at 07:31:00PM +0100, John Keeping wrote:
>> 
>> > > >  reset_submodule_urls () {
>> > > > -	local root
>> > > > -	root=$(pwd) &&
>> > > >  	(
>> > > > +		root=$(pwd) &&
>> > > >  		cd super-clone/submodule &&
>> > > >  		git config remote.origin.url "$root/submodule"
>> > > >  	) &&
>> > > >  	(
>> > > > +		root=$(pwd) &&
>> > > >  		cd super-clone/submodule/sub-submodule &&
>> > > >  		git config remote.origin.url "$root/submodule"
>> > [...]
>> > I wonder if it's relevant that the "local root" line isn't &&-chained?
>> > Is it possible that on some shells we ignore an error but everything
>> > still works?
>> 
>> I don't think so. We're inside a function, so we wouldn't affect any
>> outer &&-chaining in the function (and there isn't any in the caller
>> anyway). I think it's a reasonable custom not to bother &&-chaining
>> "local" lines, as they come at the top of a function and can't fail.
>
> Can't fail if the shell supports "local", but if we're in a shell that
> doesn't support it, then the lack of "&&" may allow us to just carry on.

True, but if "to just carry on" were a correct behaviour, then
wouldn't that mean that "local" was unnecessary, i.e. the variable
did not have to get localized because stomping on the global name
would not affect later reference to the same variable made by the
caller?

If the clobbering of a global variable breaks the behaviour of the
script, wouldn't we rather want to catch that fact?

So either way, I do not think "local variable names" that breaks
&&-chain can be justified.  Either the variable must be localized
for the script to work correctly, in which case we want local with
&&-chaining, or it does not have to, in which case we do not want to
have "local" that is not necessary, no?

  reply	other threads:[~2016-06-01 19:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-31 23:08 [BUG] git-submodule has bash-ism? Junio C Hamano
2016-05-31 23:16 ` Stefan Beller
2016-06-01  0:27 ` [PATCH] submodule: remove bashism from shell script Stefan Beller
2016-06-01 16:13 ` [BUG] git-submodule has bash-ism? Junio C Hamano
2016-06-01 16:19   ` Junio C Hamano
2016-06-01 16:37     ` Jeff King
2016-06-01 18:31       ` John Keeping
2016-06-01 19:07         ` Jeff King
2016-06-01 19:16           ` John Keeping
2016-06-01 19:45             ` Junio C Hamano [this message]
2016-06-01 20:28               ` John Keeping
2016-06-01 20:32                 ` Jeff King
2016-06-01 20:48                 ` Junio C Hamano
2016-06-01 20:56                   ` Junio C Hamano
2016-06-01 20:59                     ` Eric Sunshine
2016-06-01 21:08                     ` Jeff King
2016-06-01 20:59                   ` Stefan Beller

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=xmqqinxsy9q0.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=john@keeping.me.uk \
    --cc=peff@peff.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.