@matheusbsbs / matheus-bagliano / commits / b0418303b1
Fork 0

sha1-name: mark get_oid() error messages for translation

There are several error messages in get_oid() and its children that are clearly intended for humans, but aren't marked for translation. E.g.: $ git show :1:foo fatal: Path 'foo' is in the index, but not at stage 1. Did you mean ':0:foo'? Let's mark these for translation. While we're at it, let's switch the style to be more like our usual error messages: start with a lowercase letter and omit a period at the end of the line. This does mean that multi-line messages like the one above don't have any punctuation between the two sentences. I solved that by adding a "hint" marker like we'd see from advise(). So the result is: $ git show :1:foo fatal: path 'foo' is in the index, but not at stage 1 hint: Did you mean ':0:foo'? A few tests had to be switched to test_i18ngrep and test_i18ncmp. Since we were touching them anyway, I also simplified the ones using i18ngrep a bit for readability. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 24, 2020 at 19:13 UTC b0418303b1f335d0753736c314a4fdd7966209ac
3 files changed +34 -34
sha1-name.c
+15 -15
@@ -919,15 +919,15 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
919 }
920 if (at_time) {
921 if (!(flags & GET_OID_QUIETLY)) {
922 - warning("Log for '%.*s' only goes "
923 - "back to %s.", len, str,
922 + warning(_("log for '%.*s' only goes back to %s"),
923 + len, str,
924 show_date(co_time, co_tz, DATE_MODE(RFC2822)));
925 }
926 } else {
927 if (flags & GET_OID_QUIETLY) {
928 exit(128);
929 }
930 - die("Log for '%.*s' only has %d entries.",
930 + die(_("log for '%.*s' only has %d entries"),
931 len, str, co_cnt);
932 }
933 }
@@ -1692,14 +1692,14 @@ static void diagnose_invalid_oid_path(struct repository *r,
1692 prefix = "";
1693
1694 if (file_exists(filename))
1695 - die("Path '%s' exists on disk, but not in '%.*s'.",
1695 + die(_("path '%s' exists on disk, but not in '%.*s'"),
1696 filename, object_name_len, object_name);
1697 if (is_missing_file_error(errno)) {
1698 char *fullname = xstrfmt("%s%s", prefix, filename);
1699
1700 if (!get_tree_entry(r, tree_oid, fullname, &oid, &mode)) {
1701 - die("Path '%s' exists, but not '%s'.\n"
1702 - "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
1701 + die(_("path '%s' exists, but not '%s'\n"
1702 + "hint: Did you mean '%.*s:%s' aka '%.*s:./%s'?"),
1703 fullname,
1704 filename,
1705 object_name_len, object_name,
@@ -1707,7 +1707,7 @@ static void diagnose_invalid_oid_path(struct repository *r,
1707 object_name_len, object_name,
1708 filename);
1709 }
1710 - die("Path '%s' does not exist in '%.*s'",
1710 + die(_("path '%s' does not exist in '%.*s'"),
1711 filename, object_name_len, object_name);
1712 }
1713 }
@@ -1735,8 +1735,8 @@ static void diagnose_invalid_index_path(struct repository *r,
1735 ce = istate->cache[pos];
1736 if (ce_namelen(ce) == namelen &&
1737 !memcmp(ce->name, filename, namelen))
1738 - die("Path '%s' is in the index, but not at stage %d.\n"
1739 - "Did you mean ':%d:%s'?",
1738 + die(_("path '%s' is in the index, but not at stage %d\n"
1739 + "hint: Did you mean ':%d:%s'?"),
1740 filename, stage,
1741 ce_stage(ce), filename);
1742 }
@@ -1751,17 +1751,17 @@ static void diagnose_invalid_index_path(struct repository *r,
1751 ce = istate->cache[pos];
1752 if (ce_namelen(ce) == fullname.len &&
1753 !memcmp(ce->name, fullname.buf, fullname.len))
1754 - die("Path '%s' is in the index, but not '%s'.\n"
1755 - "Did you mean ':%d:%s' aka ':%d:./%s'?",
1754 + die(_("path '%s' is in the index, but not '%s'\n"
1755 + "hint: Did you mean ':%d:%s' aka ':%d:./%s'?"),
1756 fullname.buf, filename,
1757 ce_stage(ce), fullname.buf,
1758 ce_stage(ce), filename);
1759 }
1760
1761 if (repo_file_exists(r, filename))
1762 - die("Path '%s' exists on disk, but not in the index.", filename);
1762 + die(_("path '%s' exists on disk, but not in the index"), filename);
1763 if (is_missing_file_error(errno))
1764 - die("Path '%s' does not exist (neither on disk nor in the index).",
1764 + die(_("path '%s' does not exist (neither on disk nor in the index)"),
1765 filename);
1766
1767 strbuf_release(&fullname);
@@ -1774,7 +1774,7 @@ static char *resolve_relative_path(struct repository *r, const char *rel)
1774 return NULL;
1775
1776 if (r != the_repository || !is_inside_work_tree())
1777 - die("relative path syntax can't be used outside working tree.");
1777 + die(_("relative path syntax can't be used outside working tree"));
1778
1779 /* die() inside prefix_path() if resolved path is outside worktree */
1780 return prefix_path(startup_info->prefix,
@@ -1912,7 +1912,7 @@ static enum get_oid_result get_oid_with_context_1(struct repository *repo,
1912 return ret;
1913 } else {
1914 if (only_to_die)
1915 - die("Invalid object name '%.*s'.", len, name);
1915 + die(_("invalid object name '%.*s'."), len, name);
1916 }
1917 }
1918 return ret;
t/t1400-update-ref.sh
+6 -6
@@ -363,24 +363,24 @@ test_expect_success 'Query "master@{May 25 2005}" (before history)' '
363 git rev-parse --verify "master@{May 25 2005}" >o 2>e &&
364 echo "$C" >expect &&
365 test_cmp expect o &&
366 - echo "warning: Log for '\''master'\'' only goes back to $ed." >expect &&
367 - test_cmp expect e
366 + echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
367 + test_i18ncmp expect e
368 '
369 test_expect_success 'Query master@{2005-05-25} (before history)' '
370 test_when_finished "rm -f o e" &&
371 git rev-parse --verify master@{2005-05-25} >o 2>e &&
372 echo "$C" >expect &&
373 test_cmp expect o &&
374 - echo "warning: Log for '\''master'\'' only goes back to $ed." >expect &&
375 - test_cmp expect e
374 + echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
375 + test_i18ncmp expect e
376 '
377 test_expect_success 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' '
378 test_when_finished "rm -f o e" &&
379 git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e &&
380 echo "$C" >expect &&
381 test_cmp expect o &&
382 - echo "warning: Log for '\''master'\'' only goes back to $ed." >expect &&
383 - test_cmp expect e
382 + echo "warning: log for '\''master'\'' only goes back to $ed" >expect &&
383 + test_i18ncmp expect e
384 '
385 test_expect_success 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' '
386 test_when_finished "rm -f o e" &&
t/t1506-rev-parse-diagnosis.sh
+13 -13
@@ -9,10 +9,10 @@ exec </dev/null
9 test_did_you_mean ()
10 {
11 cat >expected <<-EOF &&
12 - fatal: Path '$2$3' $4, but not ${5:-$SQ$3$SQ}.
13 - Did you mean '$1:$2$3'${2:+ aka $SQ$1:./$3$SQ}?
12 + fatal: path '$2$3' $4, but not ${5:-$SQ$3$SQ}
13 + hint: Did you mean '$1:$2$3'${2:+ aka $SQ$1:./$3$SQ}?
14 EOF
15 - test_cmp expected error
15 + test_i18ncmp expected error
16 }
17
18 HASH_file=
@@ -103,16 +103,16 @@ test_expect_success 'correct relative file objects (6)' '
103
104 test_expect_success 'incorrect revision id' '
105 test_must_fail git rev-parse foobar:file.txt 2>error &&
106 - grep "Invalid object name '"'"'foobar'"'"'." error &&
106 + test_i18ngrep "invalid object name .foobar." error &&
107 test_must_fail git rev-parse foobar 2>error &&
108 test_i18ngrep "unknown revision or path not in the working tree." error
109 '
110
111 test_expect_success 'incorrect file in sha1:path' '
112 test_must_fail git rev-parse HEAD:nothing.txt 2>error &&
113 - grep "fatal: Path '"'"'nothing.txt'"'"' does not exist in '"'"'HEAD'"'"'" error &&
113 + test_i18ngrep "path .nothing.txt. does not exist in .HEAD." error &&
114 test_must_fail git rev-parse HEAD:index-only.txt 2>error &&
115 - grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error &&
115 + test_i18ngrep "path .index-only.txt. exists on disk, but not in .HEAD." error &&
116 (cd subdir &&
117 test_must_fail git rev-parse HEAD:file2.txt 2>error &&
118 test_did_you_mean HEAD subdir/ file2.txt exists )
@@ -120,9 +120,9 @@ test_expect_success 'incorrect file in sha1:path' '
120
121 test_expect_success 'incorrect file in :path and :N:path' '
122 test_must_fail git rev-parse :nothing.txt 2>error &&
123 - grep "fatal: Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
123 + test_i18ngrep "path .nothing.txt. does not exist (neither on disk nor in the index)" error &&
124 test_must_fail git rev-parse :1:nothing.txt 2>error &&
125 - grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error &&
125 + test_i18ngrep "path .nothing.txt. does not exist (neither on disk nor in the index)" error &&
126 test_must_fail git rev-parse :1:file.txt 2>error &&
127 test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" &&
128 (cd subdir &&
@@ -133,23 +133,23 @@ test_expect_success 'incorrect file in :path and :N:path' '
133 test_must_fail git rev-parse :2:file2.txt 2>error &&
134 test_did_you_mean :0 subdir/ file2.txt "is in the index") &&
135 test_must_fail git rev-parse :disk-only.txt 2>error &&
136 - grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error
136 + test_i18ngrep "path .disk-only.txt. exists on disk, but not in the index" error
137 '
138
139 test_expect_success 'invalid @{n} reference' '
140 test_must_fail git rev-parse master@{99999} >output 2>error &&
141 test_must_be_empty output &&
142 - grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error &&
142 + test_i18ngrep "log for [^ ]* only has [0-9][0-9]* entries" error &&
143 test_must_fail git rev-parse --verify master@{99999} >output 2>error &&
144 test_must_be_empty output &&
145 - grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error
145 + test_i18ngrep "log for [^ ]* only has [0-9][0-9]* entries" error
146 '
147
148 test_expect_success 'relative path not found' '
149 (
150 cd subdir &&
151 test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error &&
152 - grep subdir/nonexistent.txt error
152 + test_i18ngrep subdir/nonexistent.txt error
153 )
154 '
155
@@ -162,7 +162,7 @@ test_expect_success 'relative path outside worktree' '
162 test_expect_success 'relative path when cwd is outside worktree' '
163 test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error &&
164 test_must_be_empty output &&
165 - grep "relative path syntax can.t be used outside working tree." error
165 + test_i18ngrep "relative path syntax can.t be used outside working tree" error
166 '
167
168 test_expect_success '<commit>:file correctly diagnosed after a pathname' '