{"thread":{"id":"47751","subject":"contrib/completion/git-completion.bash: declare -g is not portable","startedAt":"2018-02-03T17:20:32Z","lastAt":"2018-02-04T11:48:54Z","messageCount":6,"participants":["Torsten Bögershausen","Andreas Schwab","Jeff King","Duy Nguyen","Eric Sunshine","Lucas Werkmeister"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"338148","messageId":"1e618c0c-81ba-fa7e-8039-748bdfa5a6d9@web.de","threadId":"47751","inReplyTo":null,"subject":"contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Torsten Bögershausen","fromEmail":"tboegi@web.de","sentAt":"2018-02-03T17:20:18Z","receivedAt":"2018-02-03T17:20:32Z","isPatch":false,"sender":{"key":"tboegi@web.de","avatar":"https://avatars.githubusercontent.com/u/7138363?v=4"},"body":"Hej Duy,\nAfter running t9902-completion.sh on Mac OS I got a failure\nin this style:\n\n.../projects/git/git.pu/t/../contrib/completion/git-completion.bash: line 300:\ndeclare: -g: invalid option\ndeclare: usage: declare [-afFirtx] [-p] [name[=value] ...]\n--- expected\t2018-02-03 17:10:18.000000000 +0000\n+++ out\t2018-02-03 17:10:18.000000000 +0000\n@@ -1,15 +1,2 @@\n---quiet\n---detach\n---track\n---orphan=\n---ours\n---theirs\n---merge\n---conflict=\n---patch\n---ignore-skip-worktree-bits\n---ignore-other-worktrees\n---recurse-submodules\n---progress\n --no-track\n --no-recurse-submodules\nnot ok 92 - double dash \"git checkout\"\n\nWhat is \"declare -g\" good for ?\n\n<https://www.gnu.org/software/bash/manual/html_node/Bash-Builtins.html#index-declare>\n"},{"id":"338150","messageId":"87lgg9g8cr.fsf@linux-m68k.org","threadId":"47751","inReplyTo":"1e618c0c-81ba-fa7e-8039-748bdfa5a6d9@web.de","subject":"Re: contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2018-02-03T19:51:16Z","receivedAt":"2018-02-03T19:51:25Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Feb 03 2018, Torsten Bögershausen <tboegi@web.de> wrote:\n\n> What is \"declare -g\" good for ?\n\n      -g        create global variables when used in a shell function; otherwise\n                ignored\n\n    When used in a function, `declare' makes NAMEs local, as with the `local'\n    command.  The `-g' option suppresses this behavior.\n    \nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"338151","messageId":"20180203202234.GA13374@sigill.intra.peff.net","threadId":"47751","inReplyTo":"87lgg9g8cr.fsf@linux-m68k.org","subject":"Re: contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2018-02-03T20:22:34Z","receivedAt":"2018-02-03T20:22:40Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Feb 03, 2018 at 08:51:16PM +0100, Andreas Schwab wrote:\n\n> On Feb 03 2018, Torsten Bögershausen <tboegi@web.de> wrote:\n> \n> > What is \"declare -g\" good for ?\n> \n>       -g        create global variables when used in a shell function; otherwise\n>                 ignored\n> \n>     When used in a function, `declare' makes NAMEs local, as with the `local'\n>     command.  The `-g' option suppresses this behavior.\n\nI think the bigger question is why one would use \"declare -g\" instead of\njust assigning the variable with \"var=value\".\n\nGlancing at the code, I suspect it is because the name of the variable\nitself needs expanded. If that's the case, we could use eval instead,\nlike:\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 3cc815be0d..204d620ff7 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -297,7 +297,7 @@ __gitcomp_builtin ()\n \teval \"options=\\$$var\"\n \n \tif [ -z \"$options\" ]; then\n-\t\tdeclare -g \"$var=$(__git ${cmd/_/ } --git-completion-helper)\"\n+\t\teval \"$var=\\$(__git \\${cmd/_/ } --git-completion-helper)\"\n \t\teval \"options=\\$$var\"\n \tfi\n \n\n-Peff\n"},{"id":"338162","messageId":"CACsJy8BKpniRxzDa8tOzEu=UVB0kMgv-n0tqZgp0Jreruqq-mg@mail.gmail.com","threadId":"47751","inReplyTo":"1e618c0c-81ba-fa7e-8039-748bdfa5a6d9@web.de","subject":"Re: contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2018-02-04T09:45:13Z","receivedAt":"2018-02-04T09:45:51Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Feb 4, 2018 at 12:20 AM, Torsten Bögershausen <tboegi@web.de> wrote:\n> Hej Duy,\n> After running t9902-completion.sh on Mac OS I got a failure\n> in this style:\n\nSorry I was new with this bash thingy. Jeff already answered this (and\nI will fix it in the re-roll) but just for my own information, what\nbash version is shipped with Mac OS?\n-- \nDuy\n"},{"id":"338163","messageId":"CAPig+cQXT1ov4MjzSzqiLBzr4wN1XcP7aSxMP+_dhtWtYwhDAA@mail.gmail.com","threadId":"47751","inReplyTo":"CACsJy8BKpniRxzDa8tOzEu=UVB0kMgv-n0tqZgp0Jreruqq-mg@mail.gmail.com","subject":"Re: contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-02-04T09:57:48Z","receivedAt":"2018-02-04T09:57:56Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Feb 4, 2018 at 4:45 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sun, Feb 4, 2018 at 12:20 AM, Torsten Bögershausen <tboegi@web.de> wrote:\n>> After running t9902-completion.sh on Mac OS I got a failure\n>> in this style:\n>\n> Sorry I was new with this bash thingy. Jeff already answered this (and\n> I will fix it in the re-roll) but just for my own information, what\n> bash version is shipped with Mac OS?\n\nThe MacOS bash is very old; note the copyright date:\n\n    % /bin/bash --version\n    GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)\n    Copyright (C) 2007 Free Software Foundation, Inc.\n\nA recent bash installed manually (not from Apple):\n\n    % /usr/local/bin/bash --version\n    GNU bash, version 4.4.18(1)-release (x86_64-apple-darwin16.7.0)\n    Copyright (C) 2016 Free Software Foundation, Inc.\n"},{"id":"338165","messageId":"f8500cbd-dd40-690b-22e9-a9f6a7d1eb8f@lucaswerkmeister.de","threadId":"47751","inReplyTo":"CAPig+cQXT1ov4MjzSzqiLBzr4wN1XcP7aSxMP+_dhtWtYwhDAA@mail.gmail.com","subject":"Re: contrib/completion/git-completion.bash: declare -g is not portable","fromName":"Lucas Werkmeister","fromEmail":"mail@lucaswerkmeister.de","sentAt":"2018-02-04T11:48:42Z","receivedAt":"2018-02-04T11:48:54Z","isPatch":false,"sender":{"key":"mail@lucaswerkmeister.de","avatar":"https://avatars.githubusercontent.com/u/2346599?v=4"},"body":"On 04.02.2018 10:57, Eric Sunshine wrote:\n> On Sun, Feb 4, 2018 at 4:45 AM, Duy Nguyen <pclouds@gmail.com> wrote:\n>> On Sun, Feb 4, 2018 at 12:20 AM, Torsten Bögershausen <tboegi@web.de> wrote:\n>>> After running t9902-completion.sh on Mac OS I got a failure\n>>> in this style:\n>>\n>> Sorry I was new with this bash thingy. Jeff already answered this (and\n>> I will fix it in the re-roll) but just for my own information, what\n>> bash version is shipped with Mac OS?\n> \n> The MacOS bash is very old; note the copyright date:\n> \n>     % /bin/bash --version\n>     GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin16)\n>     Copyright (C) 2007 Free Software Foundation, Inc.\n> \n> A recent bash installed manually (not from Apple):\n> \n>     % /usr/local/bin/bash --version\n>     GNU bash, version 4.4.18(1)-release (x86_64-apple-darwin16.7.0)\n>     Copyright (C) 2016 Free Software Foundation, Inc.\n> \n\nSpecifically, Apple ships the latest version of Bash 3.x, which is the\nlast version published under the GPLv2+ – Bash 4.x switched to GPLv3+.\nUsers can install newer Bash versions themselves, e. g. using Homebrew,\nbut that doesn’t help us here.\n\n"}]}