fetch-pack: move code to report unmatched refs to a function
Prepare to reuse this code in transport.c for "git fetch". While we're here, internationalize the existing error message. Signed-off-by: Matt McCutchen <matt@mattmccutchen.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Matt McCutchen committed
Feb 22, 2017 at 11:01 UTC
e860d96bf89fca63f664eb2d507f2f14537a9008
4 files changed
+23
-9
builtin/fetch-pack.c
+1
-6
@@ -219,12 +219,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
219
* remote no-such-ref' would silently succeed without issuing
220
* an error.
221
*/
222
- for (i = 0; i < nr_sought; i++) {
223
- if (!sought[i] || sought[i]->matched)
224
- continue;
225
- error("no such remote ref %s", sought[i]->name);
226
- ret = 1;
227
- }
222
+ ret |= report_unmatched_refs(sought, nr_sought);
223
224
while (ref) {
225
printf("%s %s\n",
fetch-pack.c
+13
@@ -1094,3 +1094,16 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
1094
clear_shallow_info(&si);
1095
return ref_cpy;
1096
}
1097
+
1098
+int report_unmatched_refs(struct ref **sought, int nr_sought)
1099
+{
1100
+ int i, ret = 0;
1101
+
1102
+ for (i = 0; i < nr_sought; i++) {
1103
+ if (!sought[i] || sought[i]->matched)
1104
+ continue;
1105
+ error(_("no such remote ref %s"), sought[i]->name);
1106
+ ret = 1;
1107
+ }
1108
+ return ret;
1109
+}
fetch-pack.h
+6
@@ -45,4 +45,10 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
45
struct sha1_array *shallow,
46
char **pack_lockfile);
47
48
+/*
49
+ * Print an appropriate error message for each sought ref that wasn't
50
+ * matched. Return 0 if all sought refs were matched, otherwise 1.
51
+ */
52
+int report_unmatched_refs(struct ref **sought, int nr_sought);
53
+
54
#endif
t/t5500-fetch-pack.sh
+3
-3
@@ -484,7 +484,7 @@ test_expect_success 'test lonely missing ref' '
484
cd client &&
485
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy
486
) >/dev/null 2>error-m &&
487
- test_cmp expect-error error-m
487
+ test_i18ncmp expect-error error-m
488
'
489
490
test_expect_success 'test missing ref after existing' '
@@ -492,7 +492,7 @@ test_expect_success 'test missing ref after existing' '
492
cd client &&
493
test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy
494
) >/dev/null 2>error-em &&
495
- test_cmp expect-error error-em
495
+ test_i18ncmp expect-error error-em
496
'
497
498
test_expect_success 'test missing ref before existing' '
@@ -500,7 +500,7 @@ test_expect_success 'test missing ref before existing' '
500
cd client &&
501
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A
502
) >/dev/null 2>error-me &&
503
- test_cmp expect-error error-me
503
+ test_i18ncmp expect-error error-me
504
'
505
506
test_expect_success 'test --all, --depth, and explicit head' '