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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Nov 4, 2024 at 19:02 UTC 5a875ff7fbd4b8edd99b339c7c9eaa0650b7b195
2 files changed +12 -1
t/t5500-fetch-pack.sh
+7
@@ -926,6 +926,13 @@ test_expect_success 'fetch exclude tag one' '
926 test_cmp expected actual
927 '
928
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 +
936 test_expect_success 'fetching deepen' '
937 test_create_repo shallow-deepen &&
938 (
upload-pack.c
+5 -1
@@ -1025,10 +1025,14 @@ static int process_deepen_not(const char *line, struct oidset *deepen_not, int *
1025 {
1026 const char *arg;
1027 if (skip_prefix(line, "deepen-not ", &arg)) {
1028 + int cnt;
1029 char *ref = NULL;
1030 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)
1033 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);
1036 oidset_insert(deepen_not, &oid);
1037 free(ref);
1038 *deepen_rev_list = 1;