git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [BUG] git-submodule has bash-ism?

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 1, 2016, 19:45 UTC
Message-ID
<xmqqinxsy9q0.fsf@gitster.mtv.corp.google.com>
In-Reply-To
<20160601191621.GO1355@john.keeping.me.uk>
John Keeping <john@keeping.me.uk> writes:
Show 27 quoted lines
> 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?

Previous: John KeepingNext: John Keeping
Message 10 of 17 in “[BUG] git-submodule has bash-ism?”
  1. Junio C HamanoMay 31, 2016
  2. Stefan BellerMay 31, 2016
  3. submodule: remove bashism from shell scriptStefan Beller, Jun 1, 2016
  4. Junio C HamanoJun 1, 2016
  5. Junio C HamanoJun 1, 2016
  6. Jeff KingJun 1, 2016
  7. John KeepingJun 1, 2016
  8. Jeff KingJun 1, 2016
  9. John KeepingJun 1, 2016
  10. Junio C HamanoJun 1, 2016
  11. John KeepingJun 1, 2016
  12. Jeff KingJun 1, 2016
  13. Junio C HamanoJun 1, 2016
  14. Junio C HamanoJun 1, 2016
  15. Eric SunshineJun 1, 2016
  16. Jeff KingJun 1, 2016
  17. Stefan BellerJun 1, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.