···267 | None -> None
268 | Some url_str ->
269 if Opam_repo.is_git_url url_str then
270- let url, _branch = Opam_repo.normalize_git_url url_str in
271- Some (pkg_name, url)
272 else None
273 with _ -> None
274 with _ -> None)
···267 | None -> None
268 | Some url_str ->
269 if Opam_repo.is_git_url url_str then
270+ Some (pkg_name, Opam_repo.normalize_git_url url_str)
0271 else None
272 with _ -> None
273 with _ -> None)
+31-4
lib/opam_repo.ml
···32 | false -> url
33 in
34 let uri = Uri.of_string url in
35- let branch = Uri.fragment uri in
36- let uri_without_fragment = Uri.with_fragment uri None in
37- (uri_without_fragment, branch)
000000003839module OP = OpamParserTypes.FullPos
40···47 match item.pelem with
48 | OP.Variable (name, value) when name.pelem = "dev-repo" ->
49 extract_string_value value
0000000000000000050 | _ -> None)
51 items
52···118 | Some url ->
119 if not (is_git_url url) then Error (Not_git_remote (name, url))
120 else
121- let dev_repo, branch = normalize_git_url url in
00122 let depends = find_depends opamfile.file_contents in
123 let synopsis = find_synopsis opamfile.file_contents in
124 Ok (Package.create ~name ~version ~dev_repo ?branch ~depends ?synopsis ())
···32 | false -> url
33 in
34 let uri = Uri.of_string url in
35+ (* Strip fragment from dev-repo URL - branch comes from url field *)
36+ Uri.with_fragment uri None
37+38+(** Extract branch from a URL string with optional #branch fragment *)
39+let extract_branch_from_url url =
40+ let url =
41+ match String.starts_with ~prefix:"git+" url with
42+ | true -> String.sub url 4 (String.length url - 4)
43+ | false -> url
44+ in
45+ Uri.fragment (Uri.of_string url)
4647module OP = OpamParserTypes.FullPos
48···55 match item.pelem with
56 | OP.Variable (name, value) when name.pelem = "dev-repo" ->
57 extract_string_value value
58+ | _ -> None)
59+ items
60+61+(** Find the 'src' field inside a 'url' section *)
62+let find_url_src (items : OP.opamfile_item list) : string option =
63+ List.find_map
64+ (fun (item : OP.opamfile_item) ->
65+ match item.pelem with
66+ | OP.Section sec when sec.section_kind.pelem = "url" ->
67+ (* Look for src field inside the section *)
68+ List.find_map
69+ (fun (inner : OP.opamfile_item) ->
70+ match inner.pelem with
71+ | OP.Variable (name, value) when name.pelem = "src" ->
72+ extract_string_value value
73+ | _ -> None)
74+ sec.section_items.pelem
75 | _ -> None)
76 items
77···143 | Some url ->
144 if not (is_git_url url) then Error (Not_git_remote (name, url))
145 else
146+ let dev_repo = normalize_git_url url in
147+ (* Extract branch from url field's src, not from dev-repo *)
148+ let branch = Option.bind (find_url_src opamfile.file_contents) extract_branch_from_url in
149 let depends = find_depends opamfile.file_contents in
150 let synopsis = find_synopsis opamfile.file_contents in
151 Ok (Package.create ~name ~version ~dev_repo ?branch ~depends ?synopsis ())
+8-6
lib/opam_repo.mli
···69 Accepts URLs starting with "git+" or "git://" or ending with ".git", as well
70 as SSH-style URLs like "git@github.com:...". *)
7172-val normalize_git_url : string -> Uri.t * string option
73(** [normalize_git_url url] normalizes a git URL by removing the "git+" prefix
74- if present, and extracts the branch from the URL fragment if present.
75-76- Returns [(uri, branch)] where [branch] is [Some b] if the URL had a
77- fragment like "#main", or [None] otherwise.
7879 For example, "git+https://example.com/repo.git#main" becomes
80- ("https://example.com/repo.git", Some "main"). *)
000008182val scan_opam_files_for_deps : fs:_ Eio.Path.t -> Fpath.t -> string list
83(** [scan_opam_files_for_deps ~fs dir_path] scans a directory for .opam files
···69 Accepts URLs starting with "git+" or "git://" or ending with ".git", as well
70 as SSH-style URLs like "git@github.com:...". *)
7172+val normalize_git_url : string -> Uri.t
73(** [normalize_git_url url] normalizes a git URL by removing the "git+" prefix
74+ and any fragment (branch) if present.
0007576 For example, "git+https://example.com/repo.git#main" becomes
77+ "https://example.com/repo.git". *)
78+79+val extract_branch_from_url : string -> string option
80+(** [extract_branch_from_url url] extracts the branch from a URL fragment.
81+82+ For example, "git+https://example.com/repo.git#main" returns [Some "main"]. *)
8384val scan_opam_files_for_deps : fs:_ Eio.Path.t -> Fpath.t -> string list
85(** [scan_opam_files_for_deps ~fs dir_path] scans a directory for .opam files