From cb360cdbcc3032be8ba051286fb56e81d205d12e Mon Sep 17 00:00:00 2001 From: mefyl Date: Fri, 16 Oct 2026 12:58:07 +0200 Subject: [PATCH] fix(pkg): do not report all git fetch errors as "revision not found". Signed-off-by: mefyl --- doc/changes/fixed/16623.md | 2 ++ src/dune_pkg/opamUrl0.ml | 22 ++++++++++++------- .../test-cases/pkg/commit-hash-references.t | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) create mode 100644 doc/changes/fixed/16623.md diff --git a/doc/changes/fixed/16623.md b/doc/changes/fixed/16623.md new file mode 100644 index 00000000000..a09241106f6 --- /dev/null +++ b/doc/changes/fixed/16623.md @@ -0,0 +1,2 @@ +- Do not report unrelated git remote errors as "revision does not exist" + (#16623, fixes #16466, @mefyl) diff --git a/src/dune_pkg/opamUrl0.ml b/src/dune_pkg/opamUrl0.ml index 0c964e80adc..2d627d307fe 100644 --- a/src/dune_pkg/opamUrl0.ml +++ b/src/dune_pkg/opamUrl0.ml @@ -35,16 +35,22 @@ type resolve = | Resolved of Rev_store.Object.resolved | Unresolved of Rev_store.Object.t -let not_found ~loc ~git_output t = - let url = base_url t in - let rev = rev t in +let not_found ~loc t revision = + Error + (User_message.make + ~loc + [ Pp.textf "revision %S not found in %s" revision (base_url t) ]) +;; + +let fetch_failed ~loc ~git_output t obj = let git_output = List.map ~f:Pp.verbatim git_output in Error (User_message.make ~loc @@ git_output - @ [ (match rev with - | None -> Pp.textf "default branch not found in %s" url - | Some rev -> Pp.textf "revision %S not found in %s" rev url) + @ [ Pp.textf + "could not fetch revision %S from %s" + (Rev_store.Object.to_hex obj) + (base_url t) ]) ;; @@ -74,7 +80,7 @@ let resolve t ~loc rev_store = | `Ref revision -> Rev_store.resolve_revision rev_store remote ~revision >>| (function - | None -> not_found ~loc ~git_output:[] t + | None -> not_found ~loc t revision | Some o -> Ok (Resolved o)) ;; @@ -86,7 +92,7 @@ let fetch_revision t ~loc resolve rev_store = | Unresolved o -> Rev_store.fetch_object rev_store remote o >>| (function - | Error git_output -> not_found ~loc ~git_output t + | Error git_output -> fetch_failed ~loc ~git_output t o | Ok rev -> Ok rev) ;; diff --git a/test/blackbox-tests/test-cases/pkg/commit-hash-references.t b/test/blackbox-tests/test-cases/pkg/commit-hash-references.t index a856da68445..64c0c785c4d 100644 --- a/test/blackbox-tests/test-cases/pkg/commit-hash-references.t +++ b/test/blackbox-tests/test-cases/pkg/commit-hash-references.t @@ -30,6 +30,6 @@ Depend on foo from the repo Which foo will we get? - $ dune pkg lock 2>&1 | grep "not found" | dune_cmd subst "$AMBIGUOUS_REF" '$AMBIGUOUS_REF' - revision "$AMBIGUOUS_REF" not found in + $ dune pkg lock 2>&1 | grep "could not fetch" | dune_cmd subst "$AMBIGUOUS_REF" '$AMBIGUOUS_REF' + could not fetch revision "$AMBIGUOUS_REF" from [1]