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

fix: Support prefixes other than a/ & b/ when modifying files #10899

Merged
merged 1 commit into from
Sep 10, 2024
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
5 changes: 4 additions & 1 deletion src/dune_patch/dune_patch.ml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ let patches_of_string patch_string =
( Path.Local.split_first_component old_path
, Path.Local.split_first_component new_path )
with
| Some ("a", _old_path), Some ("b", new_path) -> new_path, 1
| Some (_, old_path), Some (_, new_path)
when Path.Local.equal old_path new_path && not (Path.Local.is_root new_path) ->
(* suffixes are the same and not empty *)
new_path, 1
| _, _ -> new_path, 0
in
(* Replace file *)
Expand Down
11 changes: 3 additions & 8 deletions test/expect-tests/dune_patch/dune_patch_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,9 @@ let%expect_test "patching a file without prefix" =
;;

let%expect_test "patching files with freestyle prefix" =
try
test [ "foo.ml", "This is wrong\n" ] ("foo.patch", random_prefix);
check "foo.ml";
[%expect.unreachable]
with
| Dune_util.Report_error.Already_reported ->
print_endline @@ normalize_error_path [%expect.output];
[%expect {| Error: foo.ml: No such file or directory |}]
test [ "foo.ml", "This is wrong\n" ] ("foo.patch", random_prefix);
check "foo.ml";
[%expect {| This is right |}]
;;

let%expect_test "patching files with spaces" =
Expand Down
Loading