Skip to content

Commit

Permalink
git: handle exit code 2 for git remote url retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
rjbou committed Mar 6, 2025
1 parent 918c428 commit b8c9682
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 17 deletions.
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
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
26 changes: 22 additions & 4 deletions tests/reftests/lock.test
Original file line number Diff line number Diff line change
Expand Up @@ -1322,11 +1322,29 @@ The following actions will be performed:
-> installed tolock.dev
Done.
### opam lock tolock --keep-local
[ERROR] Command "/usr/bin/git remote get-url origin" failed:
"/usr/bin/git remote get-url origin" exited with code 2 "error: No such remote 'origin'"
# Return code 99 #
[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
# tolock.opam.locked not found
authors: "the testing team"
bug-reports: "https://nobug"
build: ["test" "-f" "content"]
depends: ["a-doc-dep" {= "dev" & with-doc} "a-simple-dep" {= "dev"} "a-test-dep" {= "dev" & with-test} "foo" {= "2"}]
description: "Two words."
dev-repo: "hg+https://[email protected]"
homepage: "egapemoh"
license: "MIT"
maintainer: "[email protected]"
name: "tolock"
opam-version: "2.0"
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
### <pin:local-one/local-one.opam>
opam-version: "2.0"
Expand Down

0 comments on commit b8c9682

Please sign in to comment.