Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop using the untracked local opam file on opam pin ./local-vcs #6409

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ users)
* Add a test showing the behaviour when a pin depend is unpinned [#6380 @rjbou]
* Add a test to ensure `opam upgrade <pkg>` will not upgrade unrelated things [#6373 @kit-ty-kate]
* Add a test in init to show ocaml system compiler selection behaviour [#6307 @kit-ty-kate @rjbou]
* Add a test showing the behaviour of `opam pin add ./local-vcs#some-other-branch` [#6409 @rjbou]

### Engine

Expand Down Expand Up @@ -230,6 +231,8 @@ users)
* `OpamDownload.get_output`: fix `wget` option for `POST` requests [#6036 @rjbou]
* `OpamDownload.get_output`: use long form for `curl` `POST` request option [#6036 @rjbou]
* `OpamDownload.download`: more fine grained HTTP request error code detection for curl [#6036 @rjbou]
* `OpamRepository.revision`: now returns a `string` instead of a `version` [#6409 @kit-ty-kate]
* `OpamRepositoryBackend.S.revision`: now returns a `string` instead of a `version` [#6409 @kit-ty-kate]

## opam-state
* `OpamStateConfig`: Make the `?lock_kind` parameters non-optional to avoid breaking the library users after they upgrade their opam root [#5488 @kit-ty-kate]
Expand Down
3 changes: 1 addition & 2 deletions src/client/opamAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,7 @@ let make_command st opam ?dir ?text_command (cmd, args) =
let rev = OpamProcess.Job.run (OpamRepository.revision src u) in
Printf.sprintf "pinned(%s%s)"
(OpamUrl.to_string_w_subpath (OpamFile.URL.subpath url) u)
(OpamStd.Option.to_string
(fun r -> "#"^OpamPackage.Version.to_string r) rev)
(OpamStd.Option.to_string (fun r -> "#"^r) rev)
else
match
OpamRepositoryState.find_package_opt st.switch_repos
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamAdminCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ let index_command cli =
let module VCS = (val OpamRepository.find_backend_by_kind vcs) in
match OpamProcess.Job.run (VCS.revision repo_root) with
| None -> date ()
| Some hash -> OpamPackage.Version.to_string hash
| Some hash -> hash
in
let repo_def = OpamFile.Repo.with_stamp repo_stamp repo_def in
OpamFile.Repo.write repo_file repo_def;
Expand Down
3 changes: 1 addition & 2 deletions src/client/opamListCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ let detail_printer ?prettify ?normalise ?(sort=false) st nv =
OpamSwitchState.url st nv >>| OpamFile.URL.url >>= fun url ->
OpamSwitchState.source_dir st nv |>
OpamFilename.opt_dir >>= fun srcdir ->
OpamProcess.Job.run (OpamRepository.revision srcdir url) >>|
OpamPackage.Version.to_string
OpamProcess.Job.run (OpamRepository.revision srcdir url)
in
OpamStd.Option.default "" hash_opt
| Raw -> OpamFile.OPAM.write_to_string (get_opam st nv)
Expand Down
19 changes: 6 additions & 13 deletions src/client/opamPinCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,15 @@ let get_source_definition ?version ?subpath ?locked st nv url =
let root = st.switch_global.root in
let srcdir = OpamPath.Switch.pinned_package root st.switch nv.name in
let fix opam =
OpamFile.OPAM.with_url url @@
(match version with
| Some v -> OpamFile.OPAM.with_version v
| None -> fun o -> o) @@
opam
let opam = OpamFile.OPAM.with_url url opam in
match version with
| Some v -> OpamFile.OPAM.with_version v opam
| None -> opam
in
let open OpamProcess.Job.Op in
OpamUpdate.fetch_dev_package url srcdir ?subpath nv @@| function
| Not_available (_,s) -> raise (Fetch_Fail s)
| Up_to_date _ | Result _ ->
let srcdir =
let u = OpamFile.URL.url url in
match OpamUrl.local_dir u, u.OpamUrl.backend with
| Some dir, #OpamUrl.version_control -> dir
| _, _ -> srcdir
in
| Up_to_date () | Result () ->
let srcdir = OpamFilename.SubPath.(srcdir /? subpath) in
match OpamPinned.find_opam_file_in_source ?locked nv.name srcdir with
| None -> None
Expand Down Expand Up @@ -771,7 +764,7 @@ let list st ~short =
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)
| Some ver -> (`magenta, ver)
in
Some (Printf.sprintf "(at %s)" (OpamConsole.colorise color (rev)))
| _ -> None
Expand Down
2 changes: 1 addition & 1 deletion src/client/opamSwitchCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ let freeze_url src_dir nv url =
(OpamUrl.to_string url_t)
| Some hash ->
OpamFile.URL.with_url
{ url_t with hash = Some (OpamPackage.Version.to_string hash) }
{ url_t with hash = Some hash }
url)
| `http ->
(match OpamFile.URL.checksum url with
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamRepository.mli
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ val pull_file_to_cache:
val cache_file: dirname -> OpamHash.t -> filename

(** Get the optional revision associated to a backend (git hash, etc.). *)
val revision: dirname -> url -> version option OpamProcess.job
val revision: dirname -> url -> string option OpamProcess.job

(** Get the version-control branch for that url. Only applicable for local,
version controlled URLs. Returns [None] in other cases. *)
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamRepositoryBackend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module type S = sig
repository_name -> ?cache_dir:dirname -> dirname -> url ->
update OpamProcess.job
val repo_update_complete: dirname -> url -> unit OpamProcess.job
val revision: dirname -> version option OpamProcess.job
val revision: dirname -> string option OpamProcess.job
val sync_dirty:
?subpath:subpath -> dirname -> url -> filename option download OpamProcess.job
val get_remote_url:
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamRepositoryBackend.mli
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ module type S = sig
(** Return the (optional) revision of a given repository. Only useful for VCS
backends. Is not expected to work with [fetch_repo_update], which doesn't
update the VCS commit information. *)
val revision: dirname -> version option OpamProcess.job
val revision: dirname -> string option OpamProcess.job

(** Like {!pull_url}, except for locally-bound version control backends, where
it should get the latest, uncommitted source. First, it performs a
Expand Down
3 changes: 1 addition & 2 deletions src/repository/opamVCS.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ module Make (VCS: VCS) = struct
Done (Result None))

let revision repo_root =
VCS.revision repo_root @@+ fun r ->
Done (OpamStd.Option.map OpamPackage.Version.of_string r)
VCS.revision repo_root

let sync_dirty ?subpath repo_root repo_url =
let filter_subpath files =
Expand Down
40 changes: 39 additions & 1 deletion tests/reftests/pin.test
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ vcs-local is now pinned to git+file://${BASEDIR}/vcs-local#master (version dev)
### test -f OPAM/vcs-local/.opam-switch/sources/vcs-local/untracked
# Return code 1 #
### opam show vcs-local --field build:,url.src:
build: "false"
build:
url.src: "git+file://${BASEDIR}/vcs-local#master"
### :C:b: double pinning when the opam file is opam/opam
### <pin:double/opam/opam>
Expand Down Expand Up @@ -1035,3 +1035,41 @@ The following actions will be performed:
-> installed dep2.2
-> installed dep1.dev
Done.
### :C:d: local directory pinned with non selected branch
### mkdir local
### git -C local init -q --initial-branch=master
### git -C local config core.autocrlf false
### git -C local commit -qm "init" --allow-empty
### git -C local checkout -b fst master
Switched to a new branch 'fst'
### <pin:local/fst.opam>
opam-version: "2.0"
synopsis: "I'm the first package"
### git -C local add fst.opam
### git -C local commit -qm "fst"
### git -C local checkout -b snd master
Switched to a new branch 'snd'
### <pin:local/snd.opam>
opam-version: "2.0"
synopsis: "I'm the second package"
### git -C local add snd.opam
### git -C local commit -qm "snd"
### git -C local checkout fst
Switched to branch 'fst'
### opam switch create local-magic --empty
### git -C local branch --show-current
fst
### opam pin fst ./local#fst -n
[NOTE] Package fst does not exist in opam repositories registered in the current switch.
[fst.dev] synchronised (git+file://${BASEDIR}/local#fst)
fst is now pinned to git+file://${BASEDIR}/local#fst (version dev)
### opam show fst --field synopsis
I'm the first package
### git -C local branch --show-current
fst
### opam pin snd ./local#snd -n
[NOTE] Package snd does not exist in opam repositories registered in the current switch.
[snd.dev] synchronised (git+file://${BASEDIR}/local#snd)
snd is now pinned to git+file://${BASEDIR}/local#snd (version dev)
### opam show snd --field synopsis
I'm the second package
Loading