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

Allow resolving unprefixed refs #332

Merged
Merged
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 CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

### Fixed

- Fix resolving refs of locally pinned repositories (#326, #332, @hannesm,
@Leonidas-from-XIV)

### Removed

### Security
Expand Down
19 changes: 13 additions & 6 deletions lib/git.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,19 @@ module Ls_remote = struct
let result = search_ref (prefix ^ ref) parsed_lines in
interpret_search_result result
in
match (search "refs/tags/", search "refs/heads/") with
| Some _, Some _ -> Error `Multiple_such_refs
| Some commit, None | None, Some commit -> Ok commit
| None, None when is_commit ref parsed_lines -> Ok ref
| None, None when looks_like_commit ref -> log_approx ()
| None, None -> Error `No_such_ref)
match (search "", search "refs/tags/", search "refs/heads/") with
| Some _, Some _, Some _
| Some _, Some _, None
| Some _, None, Some _
| None, Some _, Some _ ->
Error `Multiple_such_refs
| Some commit, None, None
| None, Some commit, None
| None, None, Some commit ->
Ok commit
| None, None, None when is_commit ref parsed_lines -> Ok ref
| None, None, None when looks_like_commit ref -> log_approx ()
| None, None, None -> Error `No_such_ref)

let parse_ref_output_line ~symref line =
match String.extract_blank_separated_words line with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
opam-version: "2.0"
synopsis: "Dummy package for testing"
maintainer: ["[email protected]"]
authors: ["Marek Kubica"]
dev-repo: "git+http://example.com/opam-monorepo-test-other"
depends: [
"dune"
]
31 changes: 31 additions & 0 deletions test/bin/pinning.t/run.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
We have a simple project which depends on another package

$ opam show --just-file -fdepends ./this/this.opam
dune, opam-monorepo-test-other

`git ls-remote` is a bit stupid and for some reason requires a valid `.git`
folder and the dune cram tests don't have one. So let's create one here:

$ git init > /dev/null 2>&1

Now let's create a git pin:

$ cd opam-monorepo-test-other
$ git init > /dev/null 2>&1
$ git add opam-monorepo-test-other.opam
$ git commit -m "Initial commit" > /dev/null
$ cd ..

Let's add this pin and pin it to `HEAD`.

$ cd this
$ opam pin --yes --no-action add --kind git opam-monorepo-test-other '../opam-monorepo-test-other#HEAD' > /dev/null 2>&1

Locking with this pin should work.

$ opam-monorepo lock > /dev/null 2>&1

We need to clean up since this modifies global state.

$ opam pin remove opam-monorepo-test-other > /dev/null
$ cd ..
5 changes: 5 additions & 0 deletions test/bin/pinning.t/this/this.opam
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
opam-version: "2.0"
depends: [
"dune"
"opam-monorepo-test-other"
]