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

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

Open
benjaminp opened this issue Nov 18, 2019 · 4 comments
Open

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

benjaminp opened this issue Nov 18, 2019 · 4 comments
Assignees
Labels
help wanted Someone outside the Bazel team could own this P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request

Comments

@benjaminp
Copy link
Collaborator

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 =
@dslomov dslomov added team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. untriaged labels Nov 25, 2019
@dslomov
Copy link
Contributor

dslomov commented Nov 25, 2019

/cc @meteorcloudy

@meteorcloudy meteorcloudy added P2 We'll consider working on this in future. (Assignee optional) type: feature request and removed untriaged labels Nov 25, 2019
@meteorcloudy meteorcloudy self-assigned this Nov 25, 2019
@meteorcloudy
Copy link
Member

@benjaminp Thanks for reporting the issue, I'll look into implementing this.

@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
@jheaff1
Copy link
Contributor

jheaff1 commented Aug 16, 2021

Any update on this? I too get errors when using patch files that contain changes to several files

@meteorcloudy
Copy link
Member

Sorry, this is still not fixed. But you can workaround by adding a blank line between the two patch sections.

@philwo philwo removed the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Nov 29, 2021
@meteorcloudy meteorcloudy added the help wanted Someone outside the Bazel team could own this label Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Someone outside the Bazel team could own this P2 We'll consider working on this in future. (Assignee optional) team-ExternalDeps External dependency handling, remote repositiories, WORKSPACE file. type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants