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.java87
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java42
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java38
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java362
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java134
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java18
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java25
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java18
8 files changed, 634 insertions, 90 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 6f57a62787..1646c7b481 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
@@ -49,14 +49,13 @@ import java.io.File;
import java.io.IOException;
import java.util.Iterator;
+import org.eclipse.jgit.api.CherryPickResult.CherryPickStatus;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.JGitInternalException;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
-import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
/**
@@ -104,19 +103,73 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertFalse(history.hasNext());
}
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
- db.lockDirCache(), branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
+ @Test
+ public void testCherryPickDirtyIndex() throws Exception {
+ Git git = new Git(db);
+ RevCommit sideCommit = prepareCherryPick(git);
+
+ // modify and add file a
+ writeTrashFile("a", "a(modified)");
+ git.add().addFilepattern("a").call();
+ // do not commit
+
+ doCherryPickAndCheckResult(git, sideCommit,
+ MergeFailureReason.DIRTY_INDEX);
+ }
+
+ @Test
+ public void testCherryPickDirtyWorktree() throws Exception {
+ Git git = new Git(db);
+ RevCommit sideCommit = prepareCherryPick(git);
+
+ // modify file a
+ writeTrashFile("a", "a(modified)");
+ // do not add and commit
+
+ doCherryPickAndCheckResult(git, sideCommit,
+ MergeFailureReason.DIRTY_WORKTREE);
}
+ private RevCommit prepareCherryPick(final Git git) throws Exception {
+ // create, add and commit file a
+ writeTrashFile("a", "a");
+ git.add().addFilepattern("a").call();
+ RevCommit firstMasterCommit = git.commit().setMessage("first master")
+ .call();
+
+ // create and checkout side branch
+ createBranch(firstMasterCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+ // modify, add and commit file a
+ writeTrashFile("a", "a(side)");
+ git.add().addFilepattern("a").call();
+ RevCommit sideCommit = git.commit().setMessage("side").call();
+
+ // checkout master branch
+ checkoutBranch("refs/heads/master");
+ // modify, add and commit file a
+ writeTrashFile("a", "a(master)");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("second master").call();
+ return sideCommit;
+ }
+
+ private void doCherryPickAndCheckResult(final Git git,
+ final RevCommit sideCommit, final MergeFailureReason reason)
+ throws Exception {
+ // get current index state
+ String indexState = indexState(CONTENT);
+
+ // cherry-pick
+ CherryPickResult result = git.cherryPick().include(sideCommit.getId())
+ .call();
+ assertEquals(CherryPickStatus.FAILED, result.getStatus());
+ // staged file a causes DIRTY_INDEX
+ assertEquals(1, result.getFailingPaths().size());
+ assertEquals(reason, result.getFailingPaths().get("a"));
+ assertEquals("a(modified)", read(new File(db.getWorkTree(), "a")));
+ // index shall be unchanged
+ assertEquals(indexState, indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 2761989c71..94f0906a30 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -49,20 +49,16 @@ import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
-import java.io.IOException;
import java.util.Iterator;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.InvalidMergeHeadsException;
-import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants;
-import org.eclipse.jgit.lib.ObjectId;
-import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.merge.MergeStrategy;
+import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class MergeCommandTest extends RepositoryTestCase {
@@ -163,7 +159,6 @@ public class MergeCommandTest extends RepositoryTestCase {
}
}
-
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
@@ -670,7 +665,8 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(sideCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
- checkMergeFailedResult(result, indexState, fileA);
+ checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
+ indexState, fileA);
}
@Test
@@ -707,7 +703,8 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(sideCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
- checkMergeFailedResult(result, indexState, fileA);
+ checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
+ indexState, fileA);
}
@Test
@@ -741,7 +738,8 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(sideCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
- checkMergeFailedResult(result, indexState, fileA);
+ checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
+ indexState, fileA);
}
@Test
@@ -777,7 +775,8 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(sideCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
- checkMergeFailedResult(result, indexState, fileA);
+ checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
+ indexState, fileA);
}
private RevCommit addAllAndCommit(final Git git) throws Exception {
@@ -786,8 +785,10 @@ public class MergeCommandTest extends RepositoryTestCase {
}
private void checkMergeFailedResult(final MergeResult result,
+ final MergeFailureReason reason,
final String indexState, final File fileA) throws Exception {
assertEquals(MergeStatus.FAILED, result.getMergeStatus());
+ assertEquals(reason, result.getFailingPaths().get("a"));
assertEquals("a(modified)", read(fileA));
assertFalse(new File(db.getWorkTree(), "b").exists());
assertEquals("c", read(new File(db.getWorkTree(), "c")));
@@ -795,25 +796,4 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(null, result.getConflicts());
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
-
- private void createBranch(ObjectId objectId, String branchName) throws IOException {
- RefUpdate updateRef = db.updateRef(branchName);
- updateRef.setNewObjectId(objectId);
- updateRef.update();
- }
-
- private void checkoutBranch(String branchName) throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db,
- head.getTree().getId(), db.lockDirCache(),
- branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
- }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index a25afc7c22..12b2f210e8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -56,9 +56,12 @@ import java.io.IOException;
import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
@@ -108,6 +111,37 @@ public class PullCommandTest extends RepositoryTestCase {
}
@Test
+ public void testPullMerge() throws Exception {
+ PullResult res = target.pull().call();
+ // nothing to update since we don't have different data yet
+ assertTrue(res.getFetchResult().getTrackingRefUpdates().isEmpty());
+ assertTrue(res.getMergeResult().getMergeStatus()
+ .equals(MergeStatus.ALREADY_UP_TO_DATE));
+
+ writeToFile(sourceFile, "Source change");
+ source.add().addFilepattern("SomeFile.txt");
+ RevCommit sourceCommit = source.commit()
+ .setMessage("Source change in remote").call();
+
+ File targetFile2 = new File(dbTarget.getWorkTree(), "OtherFile.txt");
+ writeToFile(targetFile2, "Unconflicting change");
+ target.add().addFilepattern("OtherFile.txt").call();
+ RevCommit targetCommit = target.commit()
+ .setMessage("Unconflicting change in local").call();
+
+ res = target.pull().call();
+
+ MergeResult mergeResult = res.getMergeResult();
+ ObjectId[] mergedCommits = mergeResult.getMergedCommits();
+ assertEquals(targetCommit.getId(), mergedCommits[0]);
+ assertEquals(sourceCommit.getId(), mergedCommits[1]);
+ RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
+ .getNewHead());
+ String message = "Merge branch 'master' of " + db.getWorkTree();
+ assertEquals(message, mergeCommit.getShortMessage());
+ }
+
+ @Test
public void testPullConflict() throws Exception {
PullResult res = target.pull().call();
// nothing to update since we don't have different data yet
@@ -129,7 +163,7 @@ public class PullCommandTest extends RepositoryTestCase {
res = target.pull().call();
- String sourceChangeString = "Source change\n>>>>>>> branch 'refs/heads/master' of "
+ String sourceChangeString = "Source change\n>>>>>>> branch 'master' of "
+ target.getRepository().getConfig().getString("remote",
"origin", "url");
@@ -174,7 +208,7 @@ public class PullCommandTest extends RepositoryTestCase {
res = target.pull().call();
- String sourceChangeString = "Master change\n>>>>>>> branch 'refs/heads/master' of local repository";
+ String sourceChangeString = "Master change\n>>>>>>> branch 'master' of local repository";
assertNull(res.getFetchResult());
assertEquals(res.getMergeResult().getMergeStatus(),
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index f1a3f783fa..2b7d0e5caf 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -57,6 +57,7 @@ import java.io.InputStreamReader;
import org.eclipse.jgit.api.RebaseCommand.Action;
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
+import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.UnmergedPathsException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
@@ -67,6 +68,7 @@ import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Before;
@@ -84,28 +86,6 @@ public class RebaseCommandTest extends RepositoryTestCase {
this.git = new Git(db);
}
- private void createBranch(ObjectId objectId, String branchName)
- throws IOException {
- RefUpdate updateRef = db.updateRef(branchName);
- updateRef.setNewObjectId(objectId);
- updateRef.update();
- }
-
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
- db.lockDirCache(), branch.getTree().getId());
- dco.setFailOnConflict(true);
- dco.checkout();
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- refUpdate.link(branchName);
- }
-
private void checkoutCommit(RevCommit commit) throws IllegalStateException,
IOException {
RevWalk walk = new RevWalk(db);
@@ -900,6 +880,344 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}
+ @Test
+ public void testRebaseWithUntrackedFile() throws Exception {
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / create untracked file3
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file3", "untracked file3");
+
+ // rebase
+ assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master")
+ .call().getStatus());
+ }
+
+ @Test
+ @SuppressWarnings("null")
+ public void testRebaseWithUnstagedTopicChange() throws Exception {
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file2
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "unstaged file2");
+
+ // rebase
+ JGitInternalException exception = null;
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ } catch (JGitInternalException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ assertEquals("Checkout conflict with files: \nfile2",
+ exception.getMessage());
+ }
+
+ @Test
+ @SuppressWarnings("null")
+ public void testRebaseWithUncommittedTopicChange() throws Exception {
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file2 and add
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "uncommitted file2");
+ git.add().addFilepattern("file2").call();
+ // do not commit
+
+ // rebase
+ JGitInternalException exception = null;
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ } catch (JGitInternalException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ assertEquals("Checkout conflict with files: \nfile2",
+ exception.getMessage());
+ }
+
+ @Test
+ @SuppressWarnings("null")
+ public void testRebaseWithUnstagedMasterChange() throws Exception {
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file1
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile(FILE1, "unstaged modified file1");
+
+ // rebase
+ JGitInternalException exception = null;
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ } catch (JGitInternalException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ assertEquals("Checkout conflict with files: \nfile1",
+ exception.getMessage());
+ }
+
+ @Test
+ @SuppressWarnings("null")
+ public void testRebaseWithUncommittedMasterChange() throws Exception {
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file1 and add
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile(FILE1, "uncommitted modified file1");
+ git.add().addFilepattern(FILE1).call();
+ // do not commit
+
+ // rebase
+ JGitInternalException exception = null;
+ try {
+ git.rebase().setUpstream("refs/heads/master").call();
+ } catch (JGitInternalException e) {
+ exception = e;
+ }
+ assertNotNull(exception);
+ assertEquals("Checkout conflict with files: \nfile1",
+ exception.getMessage());
+ }
+
+ @Test
+ public void testRebaseWithUnstagedMasterChangeBaseCommit() throws Exception {
+ // create file0 + file1, add and commit
+ writeTrashFile("file0", "file0");
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file0", "unstaged modified file0");
+
+ // rebase
+ assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master")
+ .call().getStatus());
+ }
+
+ @Test
+ public void testRebaseWithUncommittedMasterChangeBaseCommit()
+ throws Exception {
+ // create file0 + file1, add and commit
+ File file0 = writeTrashFile("file0", "file0");
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0 and add
+ checkoutBranch("refs/heads/topic");
+ write(file0, "unstaged modified file0");
+ git.add().addFilepattern("file0").call();
+ // do not commit
+
+ // get current index state
+ String indexState = indexState(CONTENT);
+
+ // rebase
+ RebaseResult result = git.rebase().setUpstream("refs/heads/master")
+ .call();
+ assertEquals(Status.FAILED, result.getStatus());
+ // staged file0 causes DIRTY_INDEX
+ assertEquals(1, result.getFailingPaths().size());
+ assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths()
+ .get("file0"));
+ assertEquals("unstaged modified file0", read(file0));
+ // index shall be unchanged
+ assertEquals(indexState, indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ }
+
+ @Test
+ public void testRebaseWithUnstagedMasterChangeOtherCommit()
+ throws Exception {
+ // create file0, add and commit
+ writeTrashFile("file0", "file0");
+ git.add().addFilepattern("file0").call();
+ git.commit().setMessage("commit0").call();
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file0", "unstaged modified file0");
+
+ // rebase
+ assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master")
+ .call().getStatus());
+ }
+
+ @Test
+ public void testRebaseWithUncommittedMasterChangeOtherCommit()
+ throws Exception {
+ // create file0, add and commit
+ File file0 = writeTrashFile("file0", "file0");
+ git.add().addFilepattern("file0").call();
+ git.commit().setMessage("commit0").call();
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0 and add
+ checkoutBranch("refs/heads/topic");
+ write(file0, "unstaged modified file0");
+ git.add().addFilepattern("file0").call();
+ // do not commit
+
+ // get current index state
+ String indexState = indexState(CONTENT);
+
+ // rebase
+ RebaseResult result = git.rebase().setUpstream("refs/heads/master")
+ .call();
+ assertEquals(Status.FAILED, result.getStatus());
+ // staged file0 causes DIRTY_INDEX
+ assertEquals(1, result.getFailingPaths().size());
+ assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths()
+ .get("file0"));
+ assertEquals("unstaged modified file0", read(file0));
+ // index shall be unchanged
+ assertEquals(indexState, indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ }
+
private int countPicks() throws IOException {
int count = 0;
File todoFile = new File(db.getDirectory(),
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
new file mode 100644
index 0000000000..faca7ea3ab
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com>
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.eclipse.jgit.api;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.NoFilepatternException;
+import org.eclipse.jgit.lib.RepositoryTestCase;
+import org.junit.Test;
+
+public class StatusCommandTest extends RepositoryTestCase {
+
+ @Test
+ public void testEmptyStatus() throws IOException {
+ Git git = new Git(db);
+
+ Status stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(0, stat.getUntracked().size());
+ }
+
+ @Test
+ public void testDifferentStates() throws IOException,
+ NoFilepatternException, GitAPIException {
+ Git git = new Git(db);
+ writeTrashFile("a", "content of a");
+ writeTrashFile("b", "content of b");
+ writeTrashFile("c", "content of c");
+ git.add().addFilepattern("a").addFilepattern("b").call();
+ Status stat = git.status().call();
+ assertEquals(set("a", "b"), stat.getAdded());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(set("c"), stat.getUntracked());
+ git.commit().setMessage("initial").call();
+
+ writeTrashFile("a", "modified content of a");
+ writeTrashFile("b", "modified content of b");
+ writeTrashFile("d", "content of d");
+ git.add().addFilepattern("a").addFilepattern("d").call();
+ writeTrashFile("a", "again modified content of a");
+ stat = git.status().call();
+ assertEquals(set("d"), stat.getAdded());
+ assertEquals(set("a"), stat.getChanged());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(set("b", "a"), stat.getModified());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(set("c"), stat.getUntracked());
+ git.add().addFilepattern(".").call();
+ git.commit().setMessage("second").call();
+
+ stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(0, stat.getRemoved().size());
+ assertEquals(0, stat.getUntracked().size());
+
+ deleteTrashFile("a");
+ assertFalse(new File(git.getRepository().getWorkTree(), "a").exists());
+ git.add().addFilepattern("a").setUpdate(true).call();
+ writeTrashFile("a", "recreated content of a");
+ stat = git.status().call();
+ assertEquals(0, stat.getAdded().size());
+ assertEquals(0, stat.getChanged().size());
+ assertEquals(0, stat.getMissing().size());
+ assertEquals(0, stat.getModified().size());
+ assertEquals(set("a"), stat.getRemoved());
+ assertEquals(set("a"), stat.getUntracked());
+ git.commit().setMessage("t").call();
+
+ }
+
+ public static Set<String> set(String... elements) {
+ Set<String> ret = new HashSet<String>();
+ for (String element : elements)
+ ret.add(element);
+ return ret;
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index 481a645765..160eb653b5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
@@ -53,9 +53,7 @@ import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.NoWorkTreeException;
-import org.eclipse.jgit.lib.RefUpdate.Result;
import org.eclipse.jgit.revwalk.RevCommit;
-import org.eclipse.jgit.revwalk.RevWalk;
import org.junit.Test;
public class DirCacheCheckoutTest extends ReadTreeTest {
@@ -159,20 +157,4 @@ public class DirCacheCheckoutTest extends ReadTreeTest {
assertTrue(dc.checkout());
return dc;
}
-
- private void checkoutBranch(String branchName)
- throws IllegalStateException, IOException {
- RevWalk walk = new RevWalk(db);
- RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
- RevCommit branch = walk.parseCommit(db.resolve(branchName));
- DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
- db.lockDirCache(), branch.getTree());
- dco.setFailOnConflict(true);
- assertTrue(dco.checkout());
- walk.release();
- // update the HEAD
- RefUpdate refUpdate = db.updateRef(Constants.HEAD);
- assertEquals(Result.FORCED, refUpdate.link(branchName));
- }
-
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
index ee4165dfb7..934c76cbb5 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
@@ -60,8 +60,11 @@ import java.util.TreeSet;
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
+import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.FileUtils;
@@ -374,4 +377,26 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
FileUtils.delete(tmp);
}
}
+
+ protected void createBranch(ObjectId objectId, String branchName)
+ throws IOException {
+ RefUpdate updateRef = db.updateRef(branchName);
+ updateRef.setNewObjectId(objectId);
+ updateRef.update();
+ }
+
+ protected void checkoutBranch(String branchName)
+ throws IllegalStateException, IOException {
+ RevWalk walk = new RevWalk(db);
+ RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
+ RevCommit branch = walk.parseCommit(db.resolve(branchName));
+ DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(),
+ db.lockDirCache(), branch.getTree().getId());
+ dco.setFailOnConflict(true);
+ dco.checkout();
+ walk.release();
+ // update the HEAD
+ RefUpdate refUpdate = db.updateRef(Constants.HEAD);
+ refUpdate.link(branchName);
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java
index 7151af156a..8b042bd67c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/BlockListTest.java
@@ -282,6 +282,24 @@ public class BlockListTest {
}
@Test
+ public void testAddAllFromOtherList() {
+ BlockList<Integer> src = new BlockList<Integer>(4);
+ int cnt = BlockList.BLOCK_SIZE * 2;
+
+ for (int i = 0; i < cnt; i++)
+ src.add(Integer.valueOf(42 + i));
+ src.add(Integer.valueOf(1));
+
+ BlockList<Integer> dst = new BlockList<Integer>(4);
+ dst.add(Integer.valueOf(255));
+ dst.addAll(src);
+ assertEquals(cnt + 2, dst.size());
+ for (int i = 0; i < cnt; i++)
+ assertEquals(Integer.valueOf(42 + i), dst.get(i + 1));
+ assertEquals(Integer.valueOf(1), dst.get(dst.size() - 1));
+ }
+
+ @Test
public void testFastIterator() {
BlockList<Integer> list = new BlockList<Integer>(4);
int cnt = BlockList.BLOCK_SIZE * 3;