Installs pre-commit hooks for OCaml projects that run dune fmt automatically
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

precommit: escape slashes in sed patterns for filter-branch

Fixes sed failing on patterns containing forward slashes like URLs.

+11 -2
+11 -2
lib/precommit.ml
··· 336 336 if not (file_exists ~fs (Filename.concat dir ".git")) then 337 337 Error (Printf.sprintf "%s: No .git directory found" dir) 338 338 else 339 - (* Build sed command to delete all AI attribution patterns from messages *) 339 + (* Build sed command to delete all AI attribution patterns from messages. 340 + Escape forward slashes in patterns for sed compatibility. *) 341 + let escape_slashes s = 342 + let buf = Buffer.create (String.length s) in 343 + String.iter 344 + (fun c -> 345 + if c = '/' then Buffer.add_string buf "\\/" else Buffer.add_char buf c) 346 + s; 347 + Buffer.contents buf 348 + in 340 349 let sed_args = 341 350 ai_message_patterns 342 - |> List.map (fun p -> "-e '/" ^ p ^ "/d'") 351 + |> List.map (fun p -> "-e '/" ^ escape_slashes p ^ "/d'") 343 352 |> String.concat " " 344 353 in 345 354 (* Build env-filter to replace AI authors with current user *)