aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java57
2 files changed, 97 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index 9f92c045c0..469739c57c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -44,6 +44,7 @@ package org.eclipse.jgit.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
@@ -54,7 +55,10 @@ import org.eclipse.jgit.api.CherryPickResult.CherryPickStatus;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
+import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
@@ -183,6 +187,42 @@ public class CherryPickCommandTest extends RepositoryTestCase {
.exists());
}
+ @Test
+ public void testCherryPickOverExecutableChangeOnNonExectuableFileSystem()
+ throws Exception {
+ Git git = new Git(db);
+ File file = writeTrashFile("test.txt", "a");
+ assertNotNull(git.add().addFilepattern("test.txt").call());
+ assertNotNull(git.commit().setMessage("commit1").call());
+
+ assertNotNull(git.checkout().setCreateBranch(true).setName("a").call());
+
+ writeTrashFile("test.txt", "b");
+ assertNotNull(git.add().addFilepattern("test.txt").call());
+ RevCommit commit2 = git.commit().setMessage("commit2").call();
+ assertNotNull(commit2);
+
+ assertNotNull(git.checkout().setName(Constants.MASTER).call());
+
+ DirCache cache = db.lockDirCache();
+ cache.getEntry("test.txt").setFileMode(FileMode.EXECUTABLE_FILE);
+ cache.write();
+ assertTrue(cache.commit());
+ cache.unlock();
+
+ assertNotNull(git.commit().setMessage("commit3").call());
+
+ db.getFS().setExecute(file, false);
+ git.getRepository()
+ .getConfig()
+ .setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_FILEMODE, false);
+
+ CherryPickResult result = git.cherryPick().include(commit2).call();
+ assertNotNull(result);
+ assertEquals(CherryPickStatus.OK, result.getStatus());
+ }
+
private RevCommit prepareCherryPick(final Git git) throws Exception {
// create, add and commit file a
writeTrashFile("a", "a");
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
index aed48aa5fb..b6377482dc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/FileRepositoryBuilderTest.java
@@ -45,13 +45,16 @@ package org.eclipse.jgit.storage.file;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.FileWriter;
import java.io.IOException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
@@ -108,4 +111,58 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
assertNotNull(e.getMessage());
}
}
+
+ @Test
+ public void absoluteGitDirRef() throws Exception {
+ FileRepository repo1 = createWorkRepository();
+ File dir = createTempDirectory("dir");
+ File dotGit = new File(dir, Constants.DOT_GIT);
+ new FileWriter(dotGit).append(
+ "gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+
+ builder.setWorkTree(dir);
+ builder.setMustExist(true);
+ FileRepository repo2 = builder.build();
+
+ assertEquals(repo1.getDirectory(), repo2.getDirectory());
+ assertEquals(dir, repo2.getWorkTree());
+ }
+
+ @Test
+ public void relativeGitDirRef() throws Exception {
+ FileRepository repo1 = createWorkRepository();
+ File dir = new File(repo1.getWorkTree(), "dir");
+ assertTrue(dir.mkdir());
+ File dotGit = new File(dir, Constants.DOT_GIT);
+ new FileWriter(dotGit).append("gitdir: ../" + Constants.DOT_GIT)
+ .close();
+
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+ builder.setWorkTree(dir);
+ builder.setMustExist(true);
+ FileRepository repo2 = builder.build();
+
+ assertEquals(repo1.getDirectory(), repo2.getDirectory());
+ assertEquals(dir, repo2.getWorkTree());
+ }
+
+ @Test
+ public void scanWithGitDirRef() throws Exception {
+ FileRepository repo1 = createWorkRepository();
+ File dir = createTempDirectory("dir");
+ File dotGit = new File(dir, Constants.DOT_GIT);
+ new FileWriter(dotGit).append(
+ "gitdir: " + repo1.getDirectory().getAbsolutePath()).close();
+ FileRepositoryBuilder builder = new FileRepositoryBuilder();
+
+ builder.setWorkTree(dir);
+ builder.findGitDir(dir);
+ assertEquals(repo1.getDirectory(), builder.getGitDir());
+ builder.setMustExist(true);
+ FileRepository repo2 = builder.build();
+
+ assertEquals(repo1.getDirectory(), repo2.getDirectory());
+ assertEquals(dir, repo2.getWorkTree());
+ }
}