Add more tests for rebase and externalized missing Strings

Coverage tests showed that we are missing to test certain areas
in the rebase command. Add the missing tests.

Change-Id: Ia4a272d26cde7e1861dac30496e4b6799fc8187a
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
This commit is contained in:
Christian Halstrick 2010-11-24 09:43:38 +01:00
parent c441380f9c
commit 7e298c9ed5
4 changed files with 103 additions and 1 deletions

View File

@ -50,6 +50,8 @@
import org.eclipse.jgit.api.RebaseCommand.Operation;
import org.eclipse.jgit.api.RebaseResult.Status;
import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@ -82,6 +84,21 @@ private void checkoutBranch(String branchName)
refUpdate.link(branchName);
}
private void checkoutCommit(RevCommit commit) throws IllegalStateException,
IOException {
RevWalk walk = new RevWalk(db);
RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD));
DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree(),
db.lockDirCache(), commit.getTree());
dco.setFailOnConflict(true);
dco.checkout();
walk.release();
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
refUpdate.setNewObjectId(commit);
refUpdate.forceUpdate();
}
public void testFastForwardWithNewFile() throws Exception {
Git git = new Git(db);
@ -106,6 +123,39 @@ public void testFastForwardWithNewFile() throws Exception {
assertEquals(Status.UP_TO_DATE, res.getStatus());
}
public void testUpToDate() throws Exception {
Git git = new Git(db);
// create file1 on master
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("Add file1").call();
assertTrue(new File(db.getWorkTree(), "file1").exists());
RebaseResult res = git.rebase().setUpstream(first).call();
assertEquals(Status.UP_TO_DATE, res.getStatus());
}
public void testUnknownUpstream() throws Exception {
Git git = new Git(db);
// create file1 on master
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
git.commit().setMessage("Add file1").call();
assertTrue(new File(db.getWorkTree(), "file1").exists());
try {
git.rebase().setUpstream("refs/heads/xyz")
.call();
fail("expected exception was not thrown");
} catch (RefNotFoundException e) {
// expected exception
}
}
public void testConflictFreeWithSingleFile() throws Exception {
Git git = new Git(db);
@ -142,6 +192,46 @@ public void testConflictFreeWithSingleFile() throws Exception {
db.resolve(Constants.HEAD)).getParent(0));
}
public void testDetachedHead() throws Exception {
Git git = new Git(db);
// create file1 on master
File theFile = writeTrashFile("file1", "1\n2\n3\n");
git.add().addFilepattern("file1").call();
RevCommit second = git.commit().setMessage("Add file1").call();
assertTrue(new File(db.getWorkTree(), "file1").exists());
// change first line in master and commit
writeTrashFile("file1", "1master\n2\n3\n");
checkFile(theFile, "1master\n2\n3\n");
git.add().addFilepattern("file1").call();
RevCommit lastMasterChange = git.commit()
.setMessage("change file1 in master").call();
// create a topic branch based on second commit
createBranch(second, "refs/heads/topic");
checkoutBranch("refs/heads/topic");
// we have the old content again
checkFile(theFile, "1\n2\n3\n");
assertTrue(new File(db.getWorkTree(), "file1").exists());
// change third line in topic branch
writeTrashFile("file1", "1\n2\n3\ntopic\n");
git.add().addFilepattern("file1").call();
RevCommit topicCommit = git.commit()
.setMessage("change file1 in topic").call();
checkoutBranch("refs/heads/master");
checkoutCommit(topicCommit);
assertEquals(topicCommit.getId().getName(), db.getFullBranch());
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
assertEquals(Status.OK, res.getStatus());
checkFile(theFile, "1master\n2\n3\ntopic\n");
assertEquals(lastMasterChange,
new RevWalk(db).parseCommit(db.resolve(Constants.HEAD))
.getParent(0));
}
public void testFilesAddedFromTwoBranches() throws Exception {
Git git = new Git(db);
@ -234,6 +324,15 @@ public void testAbortOnConflict() throws Exception {
// the first one should be included, so we should have left two picks in
// the file
assertEquals(countPicks(), 2);
// rebase should not succeed in this state
try {
git.rebase().setUpstream("refs/heads/master").call();
fail("Expected exception was not thrown");
} catch (WrongRepositoryStateException e) {
// expected
}
// abort should reset to topic branch
res = git.rebase().setOperation(Operation.ABORT).call();
assertEquals(res.getStatus(), Status.ABORTED);

View File

@ -9,6 +9,7 @@ URLNotFound={0} not found
aNewObjectIdIsRequired=A NewObjectId is required.
abbreviationLengthMustBeNonNegative=Abbreviation length must not be negative.
abortingRebase=Aborting rebase: resetting to {0}
abortingRebaseFailed=Could not abort rebase
advertisementCameBefore=advertisement of {0}^{} came before {1}
advertisementOfCameBefore=advertisement of {0}^{} came before {1}
amazonS3ActionFailed={0} of '{1}' failed: {2} {3}

View File

@ -69,6 +69,7 @@ public static JGitText get() {
/***/ public String aNewObjectIdIsRequired;
/***/ public String abbreviationLengthMustBeNonNegative;
/***/ public String abortingRebase;
/***/ public String abortingRebaseFailed;
/***/ public String advertisementCameBefore;
/***/ public String advertisementOfCameBefore;
/***/ public String amazonS3ActionFailed;

View File

@ -434,7 +434,8 @@ private RebaseResult abort() throws IOException {
case NO_CHANGE:
break;
default:
throw new IOException("Could not abort rebase");
throw new JGitInternalException(
JGitText.get().abortingRebaseFailed);
}
}
// cleanup the files