]> git.ipfire.org Git - thirdparty/git.git/commitdiff
upload-pack: fix ambiguous error message
authorElijah Newren <newren@gmail.com>
Mon, 4 Nov 2024 19:02:43 +0000 (19:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 5 Nov 2024 01:20:21 +0000 (17:20 -0800)
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 <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5500-fetch-pack.sh
upload-pack.c

index 8da8e7fe4230af6cdd05e472a6e61c2c9030d094..6552da78d19490274df3013ae1af2bf8e179d01d 100755 (executable)
@@ -926,6 +926,13 @@ test_expect_success 'fetch exclude tag one' '
        test_cmp expected actual
 '
 
+test_expect_success 'fetch exclude tag one as revision' '
+       test_when_finished rm -f rev err &&
+       git -C shallow-exclude rev-parse one >rev &&
+       test_must_fail git -C shallow12 fetch --shallow-exclude $(cat rev) origin 2>err &&
+       grep "deepen-not is not a ref:" err
+'
+
 test_expect_success 'fetching deepen' '
        test_create_repo shallow-deepen &&
        (
index 6d6e0f9f9800f99f368d1d3c0b9bc0b18322789c..640d45295e103ee6061765a77bd2b8f13b66bd41 100644 (file)
@@ -1025,10 +1025,14 @@ static int process_deepen_not(const char *line, struct oidset *deepen_not, int *
 {
        const char *arg;
        if (skip_prefix(line, "deepen-not ", &arg)) {
+               int cnt;
                char *ref = NULL;
                struct object_id oid;
-               if (expand_ref(the_repository, arg, strlen(arg), &oid, &ref) != 1)
+               cnt = expand_ref(the_repository, arg, strlen(arg), &oid, &ref);
+               if (cnt > 1)
                        die("git upload-pack: ambiguous deepen-not: %s", line);
+               if (cnt < 1)
+                       die("git upload-pack: deepen-not is not a ref: %s", line);
                oidset_insert(deepen_not, &oid);
                free(ref);
                *deepen_rev_list = 1;