Skip to content

Commit

Permalink
i18n: rebase-interactive: mark here-doc strings for translation
Browse files Browse the repository at this point in the history
Use pipe to send gettext output to git stripspace instead of the
original method of using shell here-document, because command
substitution '$(...)' would not take place inside the here-documents.
The exception is the case of the last here-document redirecting to cat,
in which commands substitution works and, thus, is preserved in this
commit.

t3404: adapt test to the strings newly marked for translation
Test t3404-rebase-interactive.sh would fail under GETTEXT_POISON unless
using test_i18ngrep.

Add eval_ngettext fallback functions to be called when running, for
instance, under GETTEXT_POISON. Otherwise, tests would fail under
GETTEXT_POISON, or other build that doesn't support the GNU gettext,
because that function could not be found.

Signed-off-by: Vasco Almeida <vascomalmeida@sapo.pt>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
vascool authored and gitster committed Jun 17, 2016
1 parent 9588c52 commit b8fc9e4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 22 deletions.
30 changes: 15 additions & 15 deletions git-rebase--interactive.sh
Expand Up @@ -144,29 +144,28 @@ reschedule_last_action () {
}

append_todo_help () {
git stripspace --comment-lines >>"$todo" <<\EOF
gettext "
Commands:
p, pick = use commit
r, reword = use commit, but edit the commit message
e, edit = use commit, but stop for amending
s, squash = use commit, but meld into previous commit
f, fixup = like "squash", but discard this commit's log message
f, fixup = like \"squash\", but discard this commit's log message
x, exec = run command (the rest of the line) using shell
d, drop = remove commit
These lines can be re-ordered; they are executed from top to bottom.
" | git stripspace --comment-lines >>"$todo"

EOF
if test $(get_missing_commit_check_level) = error
then
git stripspace --comment-lines >>"$todo" <<\EOF
gettext "
Do not remove any line. Use 'drop' explicitly to remove a commit.
EOF
" | git stripspace --comment-lines >>"$todo"
else
git stripspace --comment-lines >>"$todo" <<\EOF
gettext "
If you remove a line here THAT COMMIT WILL BE LOST.
EOF
" | git stripspace --comment-lines >>"$todo"
fi
}

Expand Down Expand Up @@ -1123,13 +1122,12 @@ edit-todo)
mv -f "$todo".new "$todo"
collapse_todo_ids
append_todo_help
git stripspace --comment-lines >>"$todo" <<\EOF
gettext "
You are editing the todo file of an ongoing interactive rebase.
To continue rebase after editing, run:
git rebase --continue
EOF
" | git stripspace --comment-lines >>"$todo"

git_sequence_editor "$todo" ||
die "$(gettext "Could not execute editor")"
Expand Down Expand Up @@ -1270,14 +1268,16 @@ todocount=${todocount##* }

cat >>"$todo" <<EOF
$comment_char Rebase $shortrevisions onto $shortonto ($todocount command(s))
$comment_char $(eval_ngettext \
"Rebase \$shortrevisions onto \$shortonto (\$todocount command)" \
"Rebase \$shortrevisions onto \$shortonto (\$todocount commands)" \
"$todocount")
EOF
append_todo_help
git stripspace --comment-lines >>"$todo" <<\EOF
gettext "
However, if you remove everything, the rebase will be aborted.
EOF
" | git stripspace --comment-lines >>"$todo"

if test -z "$keep_empty"
then
Expand Down
18 changes: 18 additions & 0 deletions git-sh-i18n.sh
Expand Up @@ -53,6 +53,13 @@ gettext_without_eval_gettext)
git sh-i18n--envsubst "$1"
)
}

eval_ngettext () {
ngettext "$1" "$2" "$3" | (
export PATH $(git sh-i18n--envsubst --variables "$2");
git sh-i18n--envsubst "$2"
)
}
;;
poison)
# Emit garbage so that tests that incorrectly rely on translatable
Expand All @@ -64,6 +71,10 @@ poison)
eval_gettext () {
printf "%s" "# GETTEXT POISON #"
}

eval_ngettext () {
printf "%s" "# GETTEXT POISON #"
}
;;
*)
gettext () {
Expand All @@ -76,6 +87,13 @@ poison)
git sh-i18n--envsubst "$1"
)
}

eval_ngettext () {
(test "$3" = 1 && printf "%s" "$1" || printf "%s" "$2") | (
export PATH $(git sh-i18n--envsubst --variables "$2");
git sh-i18n--envsubst "$2"
)
}
;;
esac

Expand Down
14 changes: 7 additions & 7 deletions t/t3404-rebase-interactive.sh
Expand Up @@ -540,7 +540,7 @@ test_expect_success 'clean error after failed "exec"' '
echo "edited again" > file7 &&
git add file7 &&
test_must_fail git rebase --continue 2>error &&
grep "You have staged changes in your working tree." error
test_i18ngrep "You have staged changes in your working tree." error
'

test_expect_success 'rebase a detached HEAD' '
Expand Down Expand Up @@ -1060,7 +1060,7 @@ test_expect_success 'todo count' '
EOF
test_set_editor "$(pwd)/dump-raw.sh" &&
git rebase -i HEAD~4 >actual &&
grep "^# Rebase ..* onto ..* ([0-9]" actual
test_i18ngrep "^# Rebase ..* onto ..* ([0-9]" actual
'

test_expect_success 'rebase -i commits that overwrite untracked files (pick)' '
Expand Down Expand Up @@ -1160,7 +1160,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = ignore' '
FAKE_LINES="1 2 3 4" \
git rebase -i --root 2>actual &&
test D = $(git cat-file commit HEAD | sed -ne \$p) &&
test_cmp expect actual
test_i18ncmp expect actual
'

cat >expect <<EOF
Expand All @@ -1181,7 +1181,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = warn' '
set_fake_editor &&
FAKE_LINES="1 2 3 4" \
git rebase -i --root 2>actual &&
test_cmp expect actual &&
test_i18ncmp expect actual &&
test D = $(git cat-file commit HEAD | sed -ne \$p)
'

Expand All @@ -1205,7 +1205,7 @@ test_expect_success 'rebase -i respects rebase.missingCommitsCheck = error' '
set_fake_editor &&
test_must_fail env FAKE_LINES="1 2 4" \
git rebase -i --root 2>actual &&
test_cmp expect actual &&
test_i18ncmp expect actual &&
cp .git/rebase-merge/git-rebase-todo.backup \
.git/rebase-merge/git-rebase-todo &&
FAKE_LINES="1 2 drop 3 4 drop 5" \
Expand All @@ -1228,7 +1228,7 @@ test_expect_success 'static check of bad command' '
set_fake_editor &&
test_must_fail env FAKE_LINES="1 2 3 bad 4 5" \
git rebase -i --root 2>actual &&
test_cmp expect actual &&
test_i18ncmp expect actual &&
FAKE_LINES="1 2 3 drop 4 5" git rebase --edit-todo &&
git rebase --continue &&
test E = $(git cat-file commit HEAD | sed -ne \$p) &&
Expand Down Expand Up @@ -1263,7 +1263,7 @@ test_expect_success 'static check of bad SHA-1' '
set_fake_editor &&
test_must_fail env FAKE_LINES="1 2 edit fakesha 3 4 5 #" \
git rebase -i --root 2>actual &&
test_cmp expect actual &&
test_i18ncmp expect actual &&
FAKE_LINES="1 2 4 5 6" git rebase --edit-todo &&
git rebase --continue &&
test E = $(git cat-file commit HEAD | sed -ne \$p)
Expand Down

0 comments on commit b8fc9e4

Please sign in to comment.