Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-10-01 20:33:26 +0000
committerThomas Wolf2019-10-04 06:21:49 +0000
commita5cd7803c4fb1f38e682fb8133f8c28605d0e9d8 (patch)
tree5c0e0b1ad7fc61fb71a9f496af5815754e81bc76 /org.eclipse.egit.ui.test
parent576ac49aef75a2eda816d6bb537ea7a6f283b685 (diff)
downloadegit-a5cd7803c4fb1f38e682fb8133f8c28605d0e9d8.tar.gz
egit-a5cd7803c4fb1f38e682fb8133f8c28605d0e9d8.tar.xz
egit-a5cd7803c4fb1f38e682fb8133f8c28605d0e9d8.zip
Preserve executable bit when editing index entries
Only change the mode to REGULAR_FILE if the existing entry is not a file. Bug: 551679 Change-Id: I8f6b61bef1c46c9cc343ce1d891b79594d4590a4 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui.test')
-rw-r--r--org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
index 83308efcd2..c535801204 100644
--- a/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
+++ b/org.eclipse.egit.ui.test/src/org/eclipse/egit/ui/internal/CompareUtilsTest.java
@@ -12,6 +12,8 @@ package org.eclipse.egit.ui.internal;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.io.IOException;
@@ -22,6 +24,7 @@ import java.nio.charset.StandardCharsets;
import org.eclipse.compare.ITypedElement;
import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.CommitOperation;
@@ -33,9 +36,14 @@ import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.attributes.FilterCommand;
import org.eclipse.jgit.attributes.FilterCommandFactory;
import org.eclipse.jgit.attributes.FilterCommandRegistry;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.treewalk.TreeWalk;
+import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.eclipse.jgit.util.IO;
import org.junit.Before;
import org.junit.Test;
@@ -95,6 +103,39 @@ public class CompareUtilsTest extends LocalRepositoryTestCase {
}
@Test
+ public void testIndexEditExecutable() throws Exception {
+ assumeTrue(repository.getFS().supportsExecute());
+ IFile testFile = touch("a");
+ File rawFile = new File(testFile.getLocation().toOSString());
+ repository.getFS().setExecute(rawFile, true);
+ testFile.refreshLocal(IResource.DEPTH_ZERO, null);
+ stage(testFile);
+ assertEquals("Executable bit should be set", FileMode.EXECUTABLE_FILE,
+ getIndexEntryMode(FILE1_PATH));
+ ITypedElement element = CompareUtils.getIndexTypedElement(testFile);
+ assert (element instanceof EditableRevision);
+ EditableRevision revision = (EditableRevision) element;
+ try (InputStream in = revision.getContents()) {
+ assertEquals("a", get(in));
+ }
+ revision.setContent("xx".getBytes(StandardCharsets.UTF_8));
+ // Get the index entry again and check the executable bit
+ assertEquals("Executable bit should be set", FileMode.EXECUTABLE_FILE,
+ getIndexEntryMode(FILE1_PATH));
+ }
+
+ private FileMode getIndexEntryMode(String path) throws Exception {
+ DirCache dc = repository.readDirCache();
+ try (TreeWalk w = new TreeWalk(repository)) {
+ w.addTree(new DirCacheIterator(dc));
+ w.setFilter(PathFilterGroup.createFromStrings(path));
+ w.setRecursive(true);
+ assertTrue(path + " not in index", w.next());
+ return w.getFileMode();
+ }
+ }
+
+ @Test
public void testIndexEditWithAttributes() throws Exception {
IFile testFile = touch("a");
stage(testFile);

Back to the top