Skip to content

Commit

Permalink
Detect file creation/deletion when parsing patch files created with d…
Browse files Browse the repository at this point in the history
…iff -N
  • Loading branch information
kit-ty-kate committed Oct 4, 2024
1 parent ae28123 commit 7cde69d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/fname.mll
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,17 @@ and lex_filename buf = parse

{
let parse s =
let filename, _date =
let filename, date =
match String.cut '\t' s with
| None -> (s, "")
| Some x -> x
in
if filename = "/dev/null" then
if filename = "/dev/null" ||
String.is_prefix ~prefix:"1970-" date ||
String.is_prefix ~prefix:"1969-" date ||
String.is_suffix ~suffix:" 1970" date ||
String.is_suffix ~suffix:" 1969" date then
(* See https://github.com/hannesm/patch/issues/8 *)
Ok None
else
let lexbuf = Lexing.from_string filename in
Expand Down
6 changes: 3 additions & 3 deletions test/test.ml
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ diff -ruaN a/test b/test
|}

let macos_diff_N_deletion =
operations [Patch.Edit ("a/test", "b/test")] macos_diff_N_deletion
operations [Patch.Delete "a/test"] macos_diff_N_deletion

let openbsd_diff_N_deletion = {|\
diff -ruaN a/test b/test
Expand All @@ -910,7 +910,7 @@ diff -ruaN a/test b/test
|}

let openbsd_diff_N_deletion =
operations [Patch.Edit ("a/test", "b/test")] openbsd_diff_N_deletion
operations [Patch.Delete "a/test"] openbsd_diff_N_deletion

let gnu_diff_N_deletion = {|\
diff -ruaN a/test b/test
Expand All @@ -921,7 +921,7 @@ diff -ruaN a/test b/test
|}

let gnu_diff_N_deletion =
operations [Patch.Edit ("a/test", "b/test")] gnu_diff_N_deletion
operations [Patch.Delete "a/test"] gnu_diff_N_deletion

let busybox_diff_N_deletion = {|\
--- a/test
Expand Down

0 comments on commit 7cde69d

Please sign in to comment.