bazelbuild/bazel

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

Open

#10.267 aperta il 18 nov 2019

Vedi su GitHub
 (4 commenti) (1 reazione) (1 assegnatario)Java (4465 fork)batch import
P2help wantedteam-ExternalDepstype: feature request

Metriche repository

Star
 (25.384 star)
Metriche merge PR
 (Merge medio 22g 20h) (77 PR mergiate in 30 g)

Descrizione

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 =

Guida contributor