threads / bug / 44732

Bug report: $program_name in error message

Subject: Bug report: $program_name in error message

## tl;dr

9 messages between Dec 18, 2016 and Dec 20, 2016.

replies: 8people: 4as markdown or json

Josh Bleecher Snyder· Dec 18, 2016, 20:36 UTC · lore
To reproduce, run 'git submodule' from within a bare repo. Result:

$ git submodule fatal: $program_name cannot be used without a working tree.

Looks like the intent was for $program_name to be interpolated.

As an aside, I sent a message a few days ago about a segfault when working with a filesystem with direct_io on, but it appears not to have made it to the archives on marc.info. Am I perhaps still greylisted?

Thanks, Josh

Stefan Beller· Dec 18, 2016, 21:34 UTC · re: Josh Bleecher Snyder · lore

Re: Bug report: $program_name in error message

On Sun, Dec 18, 2016 at 12:36 PM, Josh Bleecher Snyder <josharian@gmail.com> wrote:

Show 6 quoted lines
> To reproduce, run 'git submodule' from within a bare repo. Result:
>
> $ git submodule
> fatal: $program_name cannot be used without a working tree.
>
> Looks like the intent was for $program_name to be interpolated.
Which version of git do you use?
Show 6 quoted lines
>
>
> As an aside, I sent a message a few days ago about a segfault when
> working with a filesystem with direct_io on, but it appears not to
> have made it to the archives on marc.info. Am I perhaps still
> greylisted?

Both emails show up in my mailbox (subscribed to the mailing list), so I think that just nobody answered your first email as the answer may be non trivial.

>
> Thanks,
> Josh
Josh Bleecher Snyder· Dec 18, 2016, 21:44 UTC · re: Stefan Beller · lore

Re: Bug report: $program_name in error message

Show 8 quoted lines
>> To reproduce, run 'git submodule' from within a bare repo. Result:
>>
>> $ git submodule
>> fatal: $program_name cannot be used without a working tree.
>>
>> Looks like the intent was for $program_name to be interpolated.
>
> Which version of git do you use?

$ git version git version 2.11.0

Show 8 quoted lines
>> As an aside, I sent a message a few days ago about a segfault when
>> working with a filesystem with direct_io on, but it appears not to
>> have made it to the archives on marc.info. Am I perhaps still
>> greylisted?
>
> Both emails show up in my mailbox (subscribed to the mailing list),
> so I think that just nobody answered your first email as the answer
> may be non trivial.
Thanks for the confirmation.
-josh
Stefan Beller· Dec 19, 2016, 17:07 UTC · re: Josh Bleecher Snyder · lore

Re: Bug report: $program_name in error message

+ Vasco Almeida, who authored d323c6b641,
(i18n: git-sh-setup.sh: mark strings for translation, 2016-06-17)

On Sun, Dec 18, 2016 at 1:44 PM, Josh Bleecher Snyder <josharian@gmail.com> wrote:

Show 25 quoted lines
>>> To reproduce, run 'git submodule' from within a bare repo. Result:
>>>
>>> $ git submodule
>>> fatal: $program_name cannot be used without a working tree.
>>>
>>> Looks like the intent was for $program_name to be interpolated.
>>
>> Which version of git do you use?
>
> $ git version
> git version 2.11.0
>
>
>>> As an aside, I sent a message a few days ago about a segfault when
>>> working with a filesystem with direct_io on, but it appears not to
>>> have made it to the archives on marc.info. Am I perhaps still
>>> greylisted?
>>
>> Both emails show up in my mailbox (subscribed to the mailing list),
>> so I think that just nobody answered your first email as the answer
>> may be non trivial.
>
> Thanks for the confirmation.
>
> -josh
Junio C Hamano· Dec 19, 2016, 20:44 UTC · re: Stefan Beller · lore

Re: Bug report: $program_name in error message

Stefan Beller <sbeller@google.com> writes:
> + Vasco Almeida, who authored d323c6b641,
> (i18n: git-sh-setup.sh: mark strings for translation, 2016-06-17)
Comparing these changes that involve "\$variable" ...
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index c48139a494..2eda134800 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -2,6 +2,9 @@
 # to set up some variables pointing at the normal git directories and
 # a few helper shell functions.
 
+# Source git-sh-i18n for gettext support.
+. git-sh-i18n
+
 # Having this variable in your environment would break scripts because
 # you would cause "cd" to be taken to unexpected places.  If you
 # like CDPATH, define it for your interactive shell sessions without
@@ -83,16 +86,16 @@ if test -n "$OPTIONS_SPEC"; then
 else
 	dashless=$(basename -- "$0" | sed -e 's/-/ /')
 	usage() {
-		die "usage: $dashless $USAGE"
+		die "$(eval_gettext "usage: \$dashless \$USAGE")"
 	}
 
 	if [ -z "$LONG_USAGE" ]
 	then
-		LONG_USAGE="usage: $dashless $USAGE"
+		LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE")"
 	else
-		LONG_USAGE="usage: $dashless $USAGE
+		LONG_USAGE="$(eval_gettext "usage: \$dashless \$USAGE
 

... and these that appear in the same patch ...

@@ -190,13 +193,16 @@ cd_to_toplevel () {
 require_work_tree_exists () {
 	if test "z$(git rev-parse --is-bare-repository)" != zfalse
 	then
-		die "fatal: $0 cannot be used without a working tree."
+		program_name=$0
+		die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
 	fi
 }
 
 require_work_tree () {
-	test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
-	die "fatal: $0 cannot be used without a working tree."
+	test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true || {
+		program_name=$0
+		die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
+	}
 }
 
tells me that the latter needs to be eval_gettext?
Junio C Hamano· Dec 19, 2016, 20:50 UTC · re: Junio C Hamano · lore

Re: Bug report: $program_name in error message

Junio C Hamano <gitster@pobox.com> writes:
Show 18 quoted lines
> Comparing these changes that involve "\$variable" ...
>
>  	dashless=$(basename -- "$0" | sed -e 's/-/ /')
>  	usage() {
> -		die "usage: $dashless $USAGE"
> +		die "$(eval_gettext "usage: \$dashless \$USAGE")"
> ... and these that appear in the same patch ...
>
> @@ -190,13 +193,16 @@ cd_to_toplevel () {
>  require_work_tree_exists () {
>  	if test "z$(git rev-parse --is-bare-repository)" != zfalse
>  	then
> -		die "fatal: $0 cannot be used without a working tree."
> +		program_name=$0
> +		die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
> ...
>  
> tells me that the latter needs to be eval_gettext?
Just for fun:
    $ git grep -n '[^_]gettext .*\\\$'
shows three hits.  Two of them are from that one.
The other is at git-rebase--interactive.sh:440
Perhaps like this to fix.
-- >8 --
Subject: rebase -i: fix mistaken i18n

f2d17068fd ("i18n: rebase-interactive: mark comments of squash for translation", 2016-06-17) attempted to apply sh-i18n and failed to use $(eval_gettext "string with \$variable interpolation").

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-rebase--interactive.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index 41fd374c72..96865b2375 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -437,7 +437,8 @@ update_squash_messages () {
 			}' <"$squash_msg".bak
 		} >"$squash_msg"
 	else
-		commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
+		commit_message HEAD >"$fixup_msg" ||
+		die "$(eval_gettext "Cannot write \$fixup_msg")"
 		count=2
 		{
 			printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
Stefan Beller· Dec 19, 2016, 23:33 UTC · re: Junio C Hamano · lore

Re: Bug report: $program_name in error message

On Mon, Dec 19, 2016 at 12:50 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
>
> -- >8 --
> Subject: rebase -i: fix mistaken i18n
>
> f2d17068fd ("i18n: rebase-interactive: mark comments of squash for
> translation", 2016-06-17) attempted to apply sh-i18n and failed to
> use $(eval_gettext "string with \$variable interpolation").
>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Looks sensible. Thanks, Stefan

Show 5 quoted lines
>         else
> -               commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
> +               commit_message HEAD >"$fixup_msg" ||
> +               die "$(eval_gettext "Cannot write \$fixup_msg")"
>                 count=2
Vasco Almeida· Dec 20, 2016, 14:16 UTC · re: Junio C Hamano · lore

Re: Bug report: $program_name in error message

Thanks for the report and letting me know. Yes, these were mistakes and lack of attention mine. It was supposed to call 'eval_gettext' rather than 'gettext' when \$variable interpolation is needed. Junio Hamano has the right answer for these errors.

A Seg, 19-12-2016 às 12:50 -0800, Junio C Hamano escreveu:
Show 25 quoted lines
> Subject: rebase -i: fix mistaken i18n
> 
> f2d17068fd ("i18n: rebase-interactive: mark comments of squash for
> translation", 2016-06-17) attempted to apply sh-i18n and failed to
> use $(eval_gettext "string with \$variable interpolation").
> 
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>  git-rebase--interactive.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
> index 41fd374c72..96865b2375 100644
> --- a/git-rebase--interactive.sh
> +++ b/git-rebase--interactive.sh
> @@ -437,7 +437,8 @@ update_squash_messages () {
>                         }' <"$squash_msg".bak
>                 } >"$squash_msg"
>         else
> -               commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
> +               commit_message HEAD >"$fixup_msg" ||
> +               die "$(eval_gettext "Cannot write \$fixup_msg")"
>                 count=2
>                 {
>                         printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"

I agree with this fix. Perhaps indent the second line to be easier on the eyes?:

> +               commit_message HEAD >"$fixup_msg" ||
> +               	die "$(eval_gettext "Cannot write \$fixup_msg")"
Junio C Hamano· Dec 20, 2016, 17:41 UTC · re: Vasco Almeida · lore

Re: Bug report: $program_name in error message

Vasco Almeida <vascomalmeida@sapo.pt> writes:
> Thanks for the report and letting me know.
> Yes, these were mistakes and lack of attention mine. It was supposed to
> call 'eval_gettext' rather than 'gettext' when \$variable interpolation
> is needed.
Thanks.  

As both of the offending commits (d323c6b641 & f2d17068fd) were part of the topic that was merged at 2703572b3a ("Merge branch 'va/i18n-even-more'", 2016-07-13), I'll queue this single patch on top of 2703572b3a^2 (i.e. the tip of the topic).

-- >8 --
Subject: [PATCH] i18n: fix misconversion in shell scripts

An earlier series that was merged at 2703572b3a ("Merge branch 'va/i18n-even-more'", 2016-07-13) failed to use $(eval_gettext "string with \$variable interpolation") and instead used gettext in a few places, and ended up showing the variable names in the message, e.g.

    $ git submodule
    fatal: $program_name cannot be used without a working tree.
Catch these mistakes with
    $ git grep -n '[^_]gettext .*\\\$'
and fix them all to use eval_gettext instead.
Reported-by: Josh Bleecher Snyder
Acked-by: Vasco Almeida <vascomalmeida@sapo.pt>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-rebase--interactive.sh | 3 ++-
 git-sh-setup.sh            | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/git-rebase--interactive.sh b/git-rebase--interactive.sh
index a545d92c26..c5806859f0 100644
--- a/git-rebase--interactive.sh
+++ b/git-rebase--interactive.sh
@@ -467,7 +467,8 @@ update_squash_messages () {
 			}' <"$squash_msg".bak
 		} >"$squash_msg"
 	else
-		commit_message HEAD > "$fixup_msg" || die "$(gettext "Cannot write \$fixup_msg")"
+		commit_message HEAD >"$fixup_msg" ||
+		die "$(eval_gettext "Cannot write \$fixup_msg")"
 		count=2
 		{
 			printf '%s\n' "$comment_char $(gettext "This is a combination of 2 commits.")"
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 2eda134800..c7b2a95463 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -194,14 +194,14 @@ require_work_tree_exists () {
 	if test "z$(git rev-parse --is-bare-repository)" != zfalse
 	then
 		program_name=$0
-		die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
+		die "$(eval_gettext "fatal: \$program_name cannot be used without a working tree.")"
 	fi
 }
 
 require_work_tree () {
 	test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true || {
 		program_name=$0
-		die "$(gettext "fatal: \$program_name cannot be used without a working tree.")"
+		die "$(eval_gettext "fatal: \$program_name cannot be used without a working tree.")"
 	}
 }
 
-- 
2.11.0-416-g1351c11cce

← back to recent threads