Bladeren bron

Allow setting FileMode to executable when applying patches in ApplyCommand

git-apply allows modifying file modes in patched files using either
"new mode" or "new file mode" headers. This patch adds support for
setting files as executables and vice-versa.

Change-Id: I24848966b46f686f540a8efa8150b42e0d9c3ad1
Signed-off-by: Nadav Cohen <nadavcoh@gmail.com>
tags/v4.4.0.201605250940-rc1
Nadav Cohen 8 jaren geleden
bovenliggende
commit
e81592e076

+ 9
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M1.patch Bestand weergeven

diff --git a/M1 b/M1
new file mode 100755
index 0000000..de98044
--- /dev/null
+++ b/M1
@@ -0,0 +1,3 @@
+a
+b
+c

+ 3
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M1_PostImage Bestand weergeven

a
b
c

+ 10
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M2.patch Bestand weergeven

diff --git a/M2 b/M2
old mode 100644
new mode 100755
index 0000000..de98044
--- a/M2
+++ b/M2
@@ -1,3 +1,1 @@
a
-b
-c

+ 1
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M2_PostImage Bestand weergeven

a

+ 3
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M2_PreImage Bestand weergeven

a
b
c

+ 10
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M3.patch Bestand weergeven

diff --git a/M3 b/M3
old mode 100755
new mode 100644
index 0000000..de98044
--- a/M3
+++ b/M3
@@ -1,1 +1,3 @@
a
+b
+c

+ 3
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M3_PostImage Bestand weergeven

a
b
c

+ 1
- 0
org.eclipse.jgit.test/tst-rsrc/org/eclipse/jgit/diff/M3_PreImage Bestand weergeven

a

+ 28
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java Bestand weergeven



import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;


import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
b.getString(0, b.size(), false)); b.getString(0, b.size(), false));
} }


@Test
public void testAddM1() throws Exception {
ApplyResult result = init("M1", false, true);
assertEquals(1, result.getUpdatedFiles().size());
assertTrue(result.getUpdatedFiles().get(0).canExecute());
checkFile(new File(db.getWorkTree(), "M1"),
b.getString(0, b.size(), false));
}

@Test
public void testModifyM2() throws Exception {
ApplyResult result = init("M2", true, true);
assertEquals(1, result.getUpdatedFiles().size());
assertTrue(result.getUpdatedFiles().get(0).canExecute());
checkFile(new File(db.getWorkTree(), "M2"),
b.getString(0, b.size(), false));
}

@Test
public void testModifyM3() throws Exception {
ApplyResult result = init("M3", true, true);
assertEquals(1, result.getUpdatedFiles().size());
assertFalse(result.getUpdatedFiles().get(0).canExecute());
checkFile(new File(db.getWorkTree(), "M3"),
b.getString(0, b.size(), false));
}

@Test @Test
public void testModifyX() throws Exception { public void testModifyX() throws Exception {
ApplyResult result = init("X"); ApplyResult result = init("X");

+ 3
- 0
org.eclipse.jgit/src/org/eclipse/jgit/api/ApplyCommand.java Bestand weergeven

import org.eclipse.jgit.diff.DiffEntry.ChangeType; import org.eclipse.jgit.diff.DiffEntry.ChangeType;
import org.eclipse.jgit.diff.RawText; import org.eclipse.jgit.diff.RawText;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.patch.FileHeader; import org.eclipse.jgit.patch.FileHeader;
import org.eclipse.jgit.patch.HunkHeader; import org.eclipse.jgit.patch.HunkHeader;
FileWriter fw = new FileWriter(f); FileWriter fw = new FileWriter(f);
fw.write(sb.toString()); fw.write(sb.toString());
fw.close(); fw.close();

getRepository().getFS().setExecute(f, fh.getNewMode() == FileMode.EXECUTABLE_FILE);
} }


private static boolean isChanged(List<String> ol, List<String> nl) { private static boolean isChanged(List<String> ol, List<String> nl) {

Laden…
Annuleren
Opslaan