nixpkgs/pkgs/build-support/fetchpatch
Jeremy Fleischman 1d32087125
fetchpatch: add support for patches to files with apostrophes
We're feeding a list of files from `lsdiff` to `filterdiff` via `xargs`.
That list is newline separated, and looks something like this:

```
$ lsdiff <(curl -s 1e86a219f5.patch)
a/README.md
b/files/The Answer to the Ultimate Question of Life, The Universe, and Everything.txt
```

However, if the list contains files with apostrophes in it, xargs freaks
out:

```
$ echo "there's an apostrophe here" | xargs -I{} python -c "import sys; print(sys.argv)" {}
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
```

The fix is simple, just explicitly specify a delimiter:

```
$ echo "there's an apostrophe here" | xargs -I{} --delimiter='\n' python -c "import sys; print(sys.argv)" {}
['-c', "there's an apostrophe here"]
```

I added 2 tests here:

- `nix-build -A pkgs.tests.fetchpatch.fileWithApostrophe` fails without the code change.
- `nix-build -A pkgs.tests.fetchpatch.fileWithSpace` passes both before
  and after this change, but I wanted to add it to prove that I didn't
  break anything.
2025-05-23 14:32:28 -07:00
..
default.nix fetchpatch: add support for patches to files with apostrophes 2025-05-23 14:32:28 -07:00
tests.nix fetchpatch: add support for patches to files with apostrophes 2025-05-23 14:32:28 -07:00