bazelbuild / bazelbuild/bazel

native patch fails to apply multi-file patches without file headers

Open
#10,267 4 comments 1 reaction 1 assignee Claimed by @meteorcloudy View on GitHub
help wanted P2 team-ExternalDeps type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

`patch(1)` can apply the following patch, but the repository rule ctx's `patch` method can't:
```
--- a/newfile 1969-12-31 16:00:00.000000000 -0800
+++ b/newfile 2019-11-18 09:41:29.206408378 -0800
@@ -0,0 +1,2 @@
+I'm a new file
+hello, world
--- a/newfile2 1969-12-31 16:00:00.000000000 -0800
+++ b/newfile2 2019-11-18 09:46:48.146505886 -0800
@@ -0,0 +1,2 @@
+foo
+bar
```

Here's a test for `PatchUtil`:
```
diff --git a/src/test/java/com/google/devtools/build/lib/bazel/repository/PatchUtilTest.java b/src/test/java/com/google/devtools/build/lib/bazel/repository/PatchUtilTest.java
index 5fbcace554..e888c947bb 100644
--- a/src/test/java/com/google/devtools/build/lib/bazel/repository/PatchUtilTest.java
+++ b/src/test/java/com/google/devtools/build/lib/bazel/repository/PatchUtilTest.java
@@ -65,6 +65,29 @@ public class PatchUtilTest {
assertThat(PatchUtil.readFile(newFile)).containsExactlyElementsIn(newFileContent);
}

+ @Test
+ public void addTwoFiles() throws Exception {
+ Path patchFile =
+ scratch.file(
+ "/root/patchfile",
+ "--- a/newfile 1969-12-31 16:00:00.000000000 -0800",
+ "+++ b/newfile 2019-11-18 09:41:29.206408378 -0800",
+ "@@ -0,0 +1,2 @@",
+ "+I'm a new file",
+ "+hello, world",
+ "--- a/newfile2 1969-12-31 16:00:00.000000000 -0800",
+ "+++ b/newfile2 2019-11-18 09:46:48.146505886 -0800",
+ "@@ -0,0 +1,2 @@",
+ "+foo",
+ "+bar");
+
+ PatchUtil.apply(patchFile, 1, root);
+ assertThat(PatchUtil.readFile(root.getRelative("newfile")))
+ .containsExactlyElementsIn(ImmutableList.of("I'm a new file", "hello, world"));
+ assertThat(PatchUtil.readFile(root.getRelative("newfile2")))
+ .containsExactlyElementsIn(ImmutableList.of("foo", "bar"));
+ }
+
@Test
public void testAddOneLineFile() throws IOException, PatchFailedException {
Path patchFile =
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.