Skip to content

Commit 5a875ff

Browse files
newrengitster
authored andcommitted
upload-pack: fix ambiguous error message
upload-pack.c takes any --shallow-exclude argument(s) from clone/fetch/etc. and passes them through expand_ref(). If it does not get back exactly one ref from the call to expand_ref(), it will die with the following error: fatal: git upload-pack: ambiguous deepen-not: %s Given that the documentation suggests to users that --shallow-exclude accepts a revision rather than a ref (which will be corrected in a subsequent commit), users may try to pass a revision. In such a case, expand_ref() will return 0 matches, but the error message we print will be misleading since "ambiguous" suggests there are multiple matches. Provide a clearer error message for such a case. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8f8d6ee commit 5a875ff

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

t/t5500-fetch-pack.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,13 @@ test_expect_success 'fetch exclude tag one' '
926926
test_cmp expected actual
927927
'
928928

929+
test_expect_success 'fetch exclude tag one as revision' '
930+
test_when_finished rm -f rev err &&
931+
git -C shallow-exclude rev-parse one >rev &&
932+
test_must_fail git -C shallow12 fetch --shallow-exclude $(cat rev) origin 2>err &&
933+
grep "deepen-not is not a ref:" err
934+
'
935+
929936
test_expect_success 'fetching deepen' '
930937
test_create_repo shallow-deepen &&
931938
(

upload-pack.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,14 @@ static int process_deepen_not(const char *line, struct oidset *deepen_not, int *
10251025
{
10261026
const char *arg;
10271027
if (skip_prefix(line, "deepen-not ", &arg)) {
1028+
int cnt;
10281029
char *ref = NULL;
10291030
struct object_id oid;
1030-
if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
1031+
cnt = expand_ref(the_repository, arg, strlen(arg), &oid, &ref);
1032+
if (cnt > 1)
10311033
die("git upload-pack: ambiguous deepen-not: %s", line);
1034+
if (cnt < 1)
1035+
die("git upload-pack: deepen-not is not a ref: %s", line);
10321036
oidset_insert(deepen_not, &oid);
10331037
free(ref);
10341038
*deepen_rev_list = 1;

0 commit comments

Comments
 (0)