Skip to content

Commit e860d96

Browse files
mattmccutchengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b9e3c2 commit e860d96

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

builtin/fetch-pack.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,7 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
219219
* remote no-such-ref' would silently succeed without issuing
220220
* an error.
221221
*/
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);
228223

229224
while (ref) {
230225
printf("%s %s\n",

fetch-pack.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,3 +1094,16 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
10941094
clear_shallow_info(&si);
10951095
return ref_cpy;
10961096
}
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,10 @@ struct ref *fetch_pack(struct fetch_pack_args *args,
4545
struct sha1_array *shallow,
4646
char **pack_lockfile);
4747

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+
4854
#endif

t/t5500-fetch-pack.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,23 +484,23 @@ test_expect_success 'test lonely missing ref' '
484484
cd client &&
485485
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy
486486
) >/dev/null 2>error-m &&
487-
test_cmp expect-error error-m
487+
test_i18ncmp expect-error error-m
488488
'
489489

490490
test_expect_success 'test missing ref after existing' '
491491
(
492492
cd client &&
493493
test_must_fail git fetch-pack --no-progress .. refs/heads/A refs/heads/xyzzy
494494
) >/dev/null 2>error-em &&
495-
test_cmp expect-error error-em
495+
test_i18ncmp expect-error error-em
496496
'
497497

498498
test_expect_success 'test missing ref before existing' '
499499
(
500500
cd client &&
501501
test_must_fail git fetch-pack --no-progress .. refs/heads/xyzzy refs/heads/A
502502
) >/dev/null 2>error-me &&
503-
test_cmp expect-error error-me
503+
test_i18ncmp expect-error error-me
504504
'
505505

506506
test_expect_success 'test --all, --depth, and explicit head' '

0 commit comments

Comments
 (0)