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

reftest: untie lock test from OPAMEDITOR hack, and fix lock VCS remote detection #6412

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
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ users)
* Fix sandboxing support in NixOS [#6333 @kit-ty-kate]

## VCS
* [BUG] Fix `git remote get-url` failure, add handling for exit code 2 [#6412 @rjbou]

## Build
* Upgrade to opam-file-format 2.2.0~alpha1 [#6321 @kit-ty-kate]
Expand Down
28 changes: 23 additions & 5 deletions src/client/opamPinCommand.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ exception Fetch_Fail of string

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 internal_pindir = OpamPath.Switch.pinned_package root st.switch nv.name in
let fix opam =
OpamFile.OPAM.with_url url @@
(match version with
Expand All @@ -75,15 +75,31 @@ let get_source_definition ?version ?subpath ?locked st nv url =
opam
in
let open OpamProcess.Job.Op in
OpamUpdate.fetch_dev_package url srcdir ?subpath nv @@| function
OpamUpdate.fetch_dev_package url internal_pindir ?subpath nv @@+ function
| Not_available (_,s) -> raise (Fetch_Fail s)
| Up_to_date _ | Result _ ->
let srcdir =
let opam_dir_lookup () =
let u = OpamFile.URL.url url in
match OpamUrl.local_dir u, u.OpamUrl.backend with
| Some dir, #OpamUrl.version_control -> dir
| _, _ -> srcdir
| Some dir, #OpamUrl.version_control ->
let get_branch d =
let url = OpamUrl.of_string (OpamFilename.Dir.to_string d) in
OpamRepository.revision d
{ url with
OpamUrl.transport = u.transport;
backend = u.backend}
in
get_branch dir @@+ fun local_branch ->
get_branch internal_pindir @@| fun distant_branch ->
(match local_branch, distant_branch with
| Some l, Some d when OpamPackage.Version.equal l d -> dir
| Some _, Some _ -> internal_pindir
| None, Some _ -> internal_pindir
| Some _, None -> dir
| None, None -> dir)
| _, _ -> Done (internal_pindir)
in
opam_dir_lookup () @@| fun srcdir ->
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 @@ -455,6 +471,7 @@ and source_pin
(slog (OpamStd.Option.to_string OpamPackage.Version.to_string)) version
(slog (OpamStd.Option.to_string ~none:"none"
(OpamUrl.to_string_w_subpath subpath))) target_url;
(* OpamConsole.error "I have opam_opt : %s" (OpamStd.Option.to_string OpamFile.OPAM.write_to_string opam_opt); *)
(* let installed_version =
try
Some (OpamPackage.version
Expand Down Expand Up @@ -534,6 +551,7 @@ and source_pin
(OpamStd.Option.to_string OpamUrl.to_string target_url)
(OpamStd.Format.itemize (fun x -> x) [err]));
in
(* OpamConsole.error "Source def I have opam_opt : %s" (OpamStd.Option.to_string OpamFile.OPAM.write_to_string opam_opt); *)
let opam_opt = opam_opt >>| OpamFormatUpgrade.opam_file in

let nv =
Expand Down
30 changes: 17 additions & 13 deletions src/repository/opamGit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -316,22 +316,26 @@ module VCS : OpamVCS.VCS = struct
| { OpamProcess.r_code = 0; OpamProcess.r_stdout = [url]; _ } ->
(let u = OpamUrl.parse ~backend:`git url in
if OpamUrl.local_dir u <> None then Done None else
let hash_in_remote =
match hash with
let hash_in_remote =
match hash with
| None ->
(current_branch repo_root @@+ function
| None | Some "HEAD" -> Done None
| Some hash -> check_remote repo_root hash)
| Some hash -> check_remote repo_root hash
in
hash_in_remote @@+ function
| Some _ as hash ->
Done (Some { u with OpamUrl.hash = hash })
| None ->
(current_branch repo_root @@+ function
| None | Some "HEAD" -> Done None
| Some hash -> check_remote repo_root hash)
| Some hash -> check_remote repo_root hash
in
hash_in_remote @@+ function
| Some _ as hash ->
Done (Some { u with OpamUrl.hash = hash })
| None ->
Done (Some { u with OpamUrl.hash = None })
Done (Some { u with OpamUrl.hash = None })
)
| { OpamProcess.r_code = 0; _ }
| { OpamProcess.r_code = 1; _ } -> Done None
| { OpamProcess.r_code = 1; _ }
| { OpamProcess.r_code = 2; _ }
(* When subcommands such as add, rename, and remove can’t find the remote
in question, the exit status is 2 *)
-> Done None
| r -> OpamSystem.process_error r

end
Expand Down
5 changes: 4 additions & 1 deletion src/state/opamPinned.ml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ let check_locked ?locked default =
locked, Some ext)

let find_opam_file_in_source ?locked name dir =
(* OpamConsole.error "find : %s in %s" (OpamPackage.Name.to_string name) (OpamFilename.Dir.to_string dir); *)
let opt =
OpamStd.List.find_opt OpamFilename.exists
OpamStd.List.find_opt
(* (fun f -> OpamConsole.note "....%s -> %B" (OpamFilename.to_string f) (OpamFilename.exists f); OpamFilename.exists f) *)
OpamFilename.exists
(possible_definition_filenames dir name)
in
opt
Expand Down
69 changes: 48 additions & 21 deletions tests/reftests/lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -1247,39 +1247,63 @@ depends: [
"a-doc-dep" {with-doc}
]
build: [ "test" "-f" "content" ]
### <add-pindepends.sh>
cat >> tolock/tolock.opam << EOF
pin-depends: [
[ "a-simple-dep.dev" "git+https://github.com/dbuenzli/cmdliner#f239981642a" ]
[ "a-test-dep.dev" "git+https://github.com/dbuenzli/cmdliner#1de361182ab" ]
[ "a-doc-dep.dev" "git+https://github.com/dbuenzli/cmdliner#e8f8890fe48" ]
[ "a-simple-dep.dev" "git+file://$BASEDIR/pindep#simple" ]
[ "a-test-dep.dev" "git+file://$BASEDIR/pindep#test" ]
[ "a-doc-dep.dev" "git+file://$BASEDIR/pindep#doc" ]
]
EOF
### sh add-pindepends.sh
### <tolock/content>
it's here
### <pin:opam-file>
opam-version: "2.0"
version: "dev"
### OPAMEDITOR="cp -f ${BASEDIR}/opam-file"
### : -- :
### mkdir pindep
### git -C pindep init -q --initial-branch=master
### git -C pindep config core.autocrlf false
### git -C pindep commit -qm "init" --allow-empty
### git -C pindep checkout -b simple master
Switched to a new branch 'simple'
### <pin:pindep/a-simple-dep.opam>
opam-version: "2.0"
version: "dev"
### git -C pindep add a-simple-dep.opam
### git -C pindep commit -qm "simple"
### git -C pindep checkout -b test master
Switched to a new branch 'test'
### <pin:pindep/a-test-dep.opam>
opam-version: "2.0"
version: "dev"
### git -C pindep add a-test-dep.opam
### git -C pindep commit -qm "test"
### git -C pindep checkout -b doc master
Switched to a new branch 'doc'
### <pin:pindep/a-doc-dep.opam>
opam-version: "2.0"
version: "dev"
### git -C pindep add a-doc-dep.opam
### git -C pindep commit -qm "doc"
### : -- :
### opam install ./tolock --with-test --with-doc
[NOTE] Package tolock does not exist in opam repositories registered in the current switch.
The following additional pinnings are required by tolock.dev:
- a-simple-dep.dev at git+https://github.com/dbuenzli/cmdliner#f239981642a
- a-test-dep.dev at git+https://github.com/dbuenzli/cmdliner#1de361182ab
- a-doc-dep.dev at git+https://github.com/dbuenzli/cmdliner#e8f8890fe48
- a-simple-dep.dev at git+file://${BASEDIR}/pindep#simple
- a-test-dep.dev at git+file://${BASEDIR}/pindep#test
- a-doc-dep.dev at git+file://${BASEDIR}/pindep#doc
Pin and install them? [Y/n] y
[NOTE] Package a-simple-dep does not exist in opam repositories registered in the current switch.
[a-simple-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-simple-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-simple-dep", export it with "opam show a-simple-dep --raw"
a-simple-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#f239981642a (version dev)
a-simple-dep is now pinned to git+file://${BASEDIR}/pindep#simple (version dev)
[NOTE] Package a-test-dep does not exist in opam repositories registered in the current switch.
[a-test-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-test-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-test-dep", export it with "opam show a-test-dep --raw"
a-test-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#1de361182ab (version dev)
a-test-dep is now pinned to git+file://${BASEDIR}/pindep#test (version dev)
[NOTE] Package a-doc-dep does not exist in opam repositories registered in the current switch.
[a-doc-dep.dev] synchronised (no changes)
[NOTE] No package definition found for a-doc-dep.dev: please complete the template
You can edit this file again with "opam pin edit a-doc-dep", export it with "opam show a-doc-dep --raw"
a-doc-dep is now pinned to git+https://github.com/dbuenzli/cmdliner#e8f8890fe48 (version dev)
a-doc-dep is now pinned to git+file://${BASEDIR}/pindep#doc (version dev)
tolock is now pinned to file://${BASEDIR}/tolock (version dev)
The following actions will be performed:
=== install 5 packages
Expand All @@ -1290,17 +1314,20 @@ The following actions will be performed:
- install tolock dev (pinned)

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
-> retrieved a-doc-dep.dev (no changes)
-> installed a-doc-dep.dev
-> retrieved a-simple-dep.dev (no changes)
-> installed a-simple-dep.dev
-> retrieved a-test-dep.dev (no changes)
-> installed a-test-dep.dev
-> installed foo.2
-> retrieved tolock.dev (file://${BASEDIR}/tolock)
-> installed tolock.dev
Done.
### opam lock tolock
### opam lock tolock --keep-local
[ERROR] Can't retrieve remote informations for a-doc-dep.dev
[NOTE] Dependency a-doc-dep.dev is pinned to local target git+file://${BASEDIR}/pindep#doc, keeping it.
[ERROR] Can't retrieve remote informations for a-simple-dep.dev
[NOTE] Dependency a-simple-dep.dev is pinned to local target git+file://${BASEDIR}/pindep#simple, keeping it.
[ERROR] Can't retrieve remote informations for a-test-dep.dev
[NOTE] Dependency a-test-dep.dev is pinned to local target git+file://${BASEDIR}/pindep#test, keeping it.
Generated lock files for:
- tolock.dev: ${BASEDIR}/tolock.opam.locked
### opam-cat tolock.opam.locked
Expand All @@ -1315,7 +1342,7 @@ license: "MIT"
maintainer: "[email protected]"
name: "tolock"
opam-version: "2.0"
pin-depends: [["a-doc-dep.dev" "git+https://github.com/dbuenzli/cmdliner#e8f8890fe48"] ["a-simple-dep.dev" "git+https://github.com/dbuenzli/cmdliner#f239981642a"] ["a-test-dep.dev" "git+https://github.com/dbuenzli/cmdliner#1de361182ab"]]
pin-depends: [["a-doc-dep.dev" "git+file://${BASEDIR}/pindep#doc"] ["a-simple-dep.dev" "git+file://${BASEDIR}/pindep#simple"] ["a-test-dep.dev" "git+file://${BASEDIR}/pindep#test"]]
synopsis: "A word"
version: "dev"
### : Keep local pins as pin-depends
Expand Down
38 changes: 38 additions & 0 deletions tests/reftests/pin.test
Original file line number Diff line number Diff line change
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