From 188d76c128ea6d0f2c732ad5898ffc4518d48871 Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 15 Jul 2025 15:43:44 +0100 Subject: [PATCH 1/2] Add a test showing opam pin list not working when the source git directory is missing --- master_changes.md | 1 + tests/reftests/pin.test | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/master_changes.md b/master_changes.md index 788c370325e..797c005ece2 100644 --- a/master_changes.md +++ b/master_changes.md @@ -207,6 +207,7 @@ users) * Add in `repository` test cases for upgrade opam root from 2.5 with repo tarring or 2.1 to 2.6, with `OPAMREPOSITORYTARRING` enabled (trigger upgrade) [#6625 @rjbou] * Add 2.6 root test cases in opamroot-versions [#6625 @rjbou] * Add tests for `.install` fields handling [#6956 #67026 @rjbou] + * Add a test showing opam pin list not working when the source git directory is missing [#6597 @kit-ty-kate] ### Engine * Add `http-server` to launch a minimal http server [#6939 @rjbou] diff --git a/tests/reftests/pin.test b/tests/reftests/pin.test index 6607e2a19d0..328f35c0a93 100644 --- a/tests/reftests/pin.test +++ b/tests/reftests/pin.test @@ -1623,7 +1623,7 @@ Done. file1 ### opam-cat OPAM/flag-edit/.opam-switch/overlay/tide/opam | grep install install: [["mkdir" "%{lib}%/%{name}%"] ["cp" "file1" "%{lib}%/%{name}%/file1"]] -### :C:h: opam pin doesn't upgrade outdated dependencies +### :C:k: opam pin doesn't upgrade outdated dependencies ### opam switch create no-upgrade --empty ### opam-version: "2.0" @@ -1660,3 +1660,18 @@ The following actions will be performed: -> installed dep.2 -> installed pkg.1 Done. +### :C:l: make sure opam pin list works even when the source git directory is missing +### opam switch create no-source-dir --empty +### +opam-version: "2.0" +name: "pinned-pkg" +### git -C no-source-dir init -q --initial-branch=master +### git -C no-source-dir config core.autocrlf false +### git -C no-source-dir add opam +### git -C no-source-dir commit -qm 'init' +### opam pin add -n ./no-source-dir +[NOTE] Package pinned-pkg does not exist in opam repositories registered in the current switch. +pinned-pkg is now pinned to git+file://${BASEDIR}/no-source-dir#master (version dev) +### rm -r OPAM/no-source-dir/.opam-switch/sources/pinned-pkg +### opam pin +pinned-pkg.dev (uninstalled) git git+file://${BASEDIR}/no-source-dir#master (at error while fetching current revision) From 2d5464be1bb6f4c5e6dbdeee50cc95c49781d834 Mon Sep 17 00:00:00 2001 From: Kate Date: Tue, 15 Jul 2025 13:41:19 +0100 Subject: [PATCH 2/2] Improve the error message of opam pin when the source of the pinned package doesn't exist --- master_changes.md | 1 + src/client/opamPinCommand.ml | 9 +++++---- tests/reftests/autopin.test | 2 +- tests/reftests/pin.test | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/master_changes.md b/master_changes.md index 797c005ece2..03582d57032 100644 --- a/master_changes.md +++ b/master_changes.md @@ -45,6 +45,7 @@ users) * Fix `opam config subst` so it works with absolute paths [#6936 @NathanReb - fix #6925] ## Pin + * Improve the error message of `opam pin list` when the source of the pinned package doesn't exist [#6597 @kit-ty-kate] ## List diff --git a/src/client/opamPinCommand.ml b/src/client/opamPinCommand.ml index 0ee804e4836..34e4a51eefb 100644 --- a/src/client/opamPinCommand.ml +++ b/src/client/opamPinCommand.ml @@ -766,12 +766,13 @@ let list st ~short = match url.OpamUrl.backend with | #OpamUrl.version_control -> let srcdir = OpamSwitchState.source_dir st nv in - let color, rev = + let prefix, color, rev = match OpamProcess.Job.run (OpamRepository.revision srcdir url) with - | None -> (`red, "error while fetching current revision") - | Some ver -> (`magenta, ver) + | None -> + ("", `red, "error while fetching current revision") + | Some ver -> ("at ", `magenta, ver) in - Some (Printf.sprintf "(at %s)" (OpamConsole.colorise color (rev))) + Some (Printf.sprintf "(%s%s)" prefix (OpamConsole.colorise color rev)) | _ -> None in [ OpamPackage.to_string nv; diff --git a/tests/reftests/autopin.test b/tests/reftests/autopin.test index e8efca88bb3..5dba5fa2ee0 100644 --- a/tests/reftests/autopin.test +++ b/tests/reftests/autopin.test @@ -459,4 +459,4 @@ The following actions will be performed: Proceed with 2 installations? [Y/n] n # Return code 10 # ### opam pin list -abort-install.dev (uninstalled) git git+file://${BASEDIR}/abort-install#master (at error while fetching current revision) +abort-install.dev (uninstalled) git git+file://${BASEDIR}/abort-install#master (error while fetching current revision) diff --git a/tests/reftests/pin.test b/tests/reftests/pin.test index 328f35c0a93..f4c0adff65d 100644 --- a/tests/reftests/pin.test +++ b/tests/reftests/pin.test @@ -1674,4 +1674,4 @@ name: "pinned-pkg" pinned-pkg is now pinned to git+file://${BASEDIR}/no-source-dir#master (version dev) ### rm -r OPAM/no-source-dir/.opam-switch/sources/pinned-pkg ### opam pin -pinned-pkg.dev (uninstalled) git git+file://${BASEDIR}/no-source-dir#master (at error while fetching current revision) +pinned-pkg.dev (uninstalled) git git+file://${BASEDIR}/no-source-dir#master (error while fetching current revision)