Skip to content

Commit

Permalink
Make it so pin list display the current revision of the pinned repo
Browse files Browse the repository at this point in the history
  • Loading branch information
desumn authored and rjbou committed Nov 27, 2024
1 parent 84a949f commit 962546c
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 92 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ users)
## Config

## Pin
* [NEW] Make it so pin list display the current revision of a pinned repository in a new column [#6274 @desumn - fix #5533]

## List

Expand Down
5 changes: 4 additions & 1 deletion src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3199,7 +3199,10 @@ let pin_doc = "Pin a given package to a specific version or source."
let pin ?(unpin_only=false) cli =
let doc = pin_doc in
let commands = [
cli_original, "list", `list, [], "Lists pinned packages.";
cli_original, "list", `list, [],
"Lists pinned packages. \
If the source is a remote repository, \
displays the hash representing its state.";
cli_from cli2_1, "scan", `scan, ["DIR"],
"Lists available packages to pin in directory.";
cli_original, "add", `add, ["PACKAGE"; "TARGET"],
Expand Down
17 changes: 16 additions & 1 deletion src/client/opamPinCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -764,10 +764,25 @@ let list st ~short =
(OpamPackage.version_to_string inst))]
with Not_found -> OpamConsole.colorise `yellow "(uninstalled)", []
in
let vcs_revision =
let open OpamStd.Option.Op in
url >>| OpamFile.URL.url >>= fun url ->
match url.OpamUrl.backend with
| #OpamUrl.version_control ->
let srcdir = OpamSwitchState.source_dir st nv in
let color, rev =
match OpamProcess.Job.run (OpamRepository.revision srcdir url) with
| None -> (`red, "error while fetching current revision")
| Some ver -> (`magenta, OpamPackage.Version.to_string ver)
in
Some (Printf.sprintf "(at %s)" (OpamConsole.colorise color (rev)))
| _ -> None
in
[ OpamPackage.to_string nv;
state;
OpamConsole.colorise `blue kind;
String.concat " " (target::extra) ]
String.concat " " (target::extra);
OpamStd.Option.default "" vcs_revision ]
with Not_found ->
[ OpamPackage.to_string nv;
OpamConsole.colorise `red " (no definition found)" ]
Expand Down
26 changes: 13 additions & 13 deletions tests/reftests/pin.test
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ The following actions will be performed:
-> installed no-url.ved
Done.
### : list
### opam pin list
nip-git.ved git git+file://${BASEDIR}/nip-git#master
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master
### opam pin list | ' \(at [0-9a-f]+\)$' -> ' (at HASH)'
nip-git.ved git git+file://${BASEDIR}/nip-git#master (at HASH)
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master (at HASH)
nip-path.ved rsync file://${BASEDIR}/nip-path
nip-path2.ved rsync file://${BASEDIR}/nip-path2
nip-path3.ved rsync file://${BASEDIR}/nip-path3
Expand Down Expand Up @@ -332,11 +332,11 @@ The following actions will be performed:
[NOTE] Pinning command successful, but your installed packages may be out of sync.
# Return code 31 #
### : list
### opam pin list
### opam pin list | ' \(at [0-9a-f]+\)$' -> ' (at HASH)'
nip.1 version 1
nip-git.ved rsync file://${BASEDIR}/nip-git
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master
nip-git3.ved git git+file://${BASEDIR}/nip-git3#master
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master (at HASH)
nip-git3.ved git git+file://${BASEDIR}/nip-git3#master (at HASH)
nip-path.ved rsync file://${BASEDIR}/nip-path
nip-path3.ved rsync file://${BASEDIR}/nip-path3
no-url.1 (uninstalled) local definition
Expand Down Expand Up @@ -407,8 +407,8 @@ The following actions will be performed:
-> installed nip-path2.ved
Done.
### : list
### opam pin list
nip-git.ved git git+file://${BASEDIR}/nip-git#master
### opam pin list | ' \(at [0-9a-f]+\)$' -> ' (at HASH)'
nip-git.ved git git+file://${BASEDIR}/nip-git#master (at HASH)
nip-git2.ved rsync file://${BASEDIR}/nip-git2
nip-path.ved rsync file://${BASEDIR}/nip-path
nip-path2.ved rsync file://${BASEDIR}/nip-path2
Expand Down Expand Up @@ -452,8 +452,8 @@ Done.
# Name # Installed # Synopsis
nip-path ved pinned to version ved at file://${BASEDIR}/nip-path
nip-path2 ved pinned to version ved at file://${BASEDIR}/nip-path2
### opam pin list
nip-git4.ved (uninstalled) git git+file://${BASEDIR}/nip-git4#master
### opam pin list | ' \(at [0-9a-f]+\)$' -> ' (at HASH)'
nip-git4.ved (uninstalled) git git+file://${BASEDIR}/nip-git4#master (at HASH)
nip-path.ved rsync file://${BASEDIR}/nip-path
nip-path2.ved rsync file://${BASEDIR}/nip-path2
### find OPAM/actions/lib -name '*.t' | sort
Expand Down Expand Up @@ -570,11 +570,11 @@ The following actions will be performed:
### :::::::::::::::::::::::
### opam switch kinds
### : pin list
### opam pin list
### opam pin list | ' \(at [0-9a-f]+\)$' -> ' (at HASH)'
nip.1 version 1
nip-git.ved rsync file://${BASEDIR}/nip-git
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master
nip-git3.ved git git+file://${BASEDIR}/nip-git3#master
nip-git2.ved git git+file://${BASEDIR}/nip-git2#master (at HASH)
nip-git3.ved git git+file://${BASEDIR}/nip-git3#master (at HASH)
nip-path.ved rsync file://${BASEDIR}/nip-path
nip-path3.ved rsync file://${BASEDIR}/nip-path3
no-url.1 (uninstalled) local definition
Expand Down
Loading

0 comments on commit 962546c

Please sign in to comment.