summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorBernard Leach <leachbj@bouncycastle.org>2011-05-19 21:04:20 +1000
committerChris Aniszczyk <caniszczyk@gmail.com>2011-05-19 09:04:09 -0500
commit37fe0988b26b7893888a073a33ccf0865723ca8b (patch)
treea0c95d87ed278711369bad16712843e3f4aacbf7 /org.eclipse.jgit.test
parentf953a35e9a1f279ca038955243c07fd84fb6ae23 (diff)
downloadjgit-37fe0988b26b7893888a073a33ccf0865723ca8b.tar.gz
jgit-37fe0988b26b7893888a073a33ccf0865723ca8b.zip
Add reset with paths support to ResetCommand
Bug: 338701 Change-Id: Id7cbce47131b459e632ddc2c9a94628c7d0b75cd Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java83
1 files changed, 76 insertions, 7 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
index 578b98170f..f79592f223 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.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;
@@ -58,6 +59,7 @@ import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.api.errors.NoMessageException;
import org.eclipse.jgit.api.errors.WrongRepositoryStateException;
import org.eclipse.jgit.dircache.DirCache;
+import org.eclipse.jgit.dircache.DirCacheEntry;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -66,6 +68,7 @@ import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.util.FileUtils;
+import org.junit.Assert;
import org.junit.Test;
public class ResetCommandTest extends RepositoryTestCase {
@@ -74,10 +77,14 @@ public class ResetCommandTest extends RepositoryTestCase {
private RevCommit initialCommit;
+ private RevCommit secondCommit;
+
private File indexFile;
private File untrackedFile;
+ private DirCacheEntry prestage;
+
public void setupRepository() throws IOException, NoFilepatternException,
NoHeadException, NoMessageException, ConcurrentRefUpdateException,
JGitInternalException, WrongRepositoryStateException {
@@ -95,7 +102,10 @@ public class ResetCommandTest extends RepositoryTestCase {
// add file and commit it
git.add().addFilepattern("a.txt").call();
- git.commit().setMessage("adding a.txt").call();
+ secondCommit = git.commit().setMessage("adding a.txt").call();
+
+ prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(
+ indexFile.getName());
// modify file and add to index
writer.print("new content");
@@ -178,6 +188,66 @@ public class ResetCommandTest extends RepositoryTestCase {
assertReflog(prevHead, head);
}
+ @Test
+ public void testPathsReset() throws Exception {
+ setupRepository();
+
+ DirCacheEntry preReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+ assertNotNull(preReset);
+
+ git.add().addFilepattern(untrackedFile.getName()).call();
+
+ // 'a.txt' has already been modified in setupRepository
+ // 'notAddedToIndex.txt' has been added to repository
+ git.reset().addPath(indexFile.getName())
+ .addPath(untrackedFile.getName()).call();
+
+ DirCacheEntry postReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+ assertNotNull(postReset);
+ Assert.assertNotSame(preReset.getObjectId(), postReset.getObjectId());
+ Assert.assertEquals(prestage.getObjectId(), postReset.getObjectId());
+
+ // check that HEAD hasn't moved
+ ObjectId head = db.resolve(Constants.HEAD);
+ assertTrue(head.equals(secondCommit));
+ // check if files still exist
+ assertTrue(untrackedFile.exists());
+ assertTrue(indexFile.exists());
+ assertTrue(inHead(indexFile.getName()));
+ assertTrue(inIndex(indexFile.getName()));
+ assertFalse(inIndex(untrackedFile.getName()));
+ }
+
+ @Test
+ public void testPathsResetWithRef() throws Exception {
+ setupRepository();
+
+ DirCacheEntry preReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+ assertNotNull(preReset);
+
+ git.add().addFilepattern(untrackedFile.getName()).call();
+
+ // 'a.txt' has already been modified in setupRepository
+ // 'notAddedToIndex.txt' has been added to repository
+ // reset to the inital commit
+ git.reset().setRef(initialCommit.getName())
+ .addPath(indexFile.getName())
+ .addPath(untrackedFile.getName()).call();
+
+ // check that HEAD hasn't moved
+ ObjectId head = db.resolve(Constants.HEAD);
+ assertTrue(head.equals(secondCommit));
+ // check if files still exist
+ assertTrue(untrackedFile.exists());
+ assertTrue(indexFile.exists());
+ assertTrue(inHead(indexFile.getName()));
+ assertFalse(inIndex(indexFile.getName()));
+ assertFalse(inIndex(untrackedFile.getName()));
+ }
+
private void assertReflog(ObjectId prevHead, ObjectId head)
throws IOException {
// Check the reflog for HEAD
@@ -187,9 +257,8 @@ public class ResetCommandTest extends RepositoryTestCase {
assertEquals(expectedHeadMessage, actualHeadMessage);
assertEquals(head.getName(), db.getReflogReader(Constants.HEAD)
.getLastEntry().getNewId().getName());
- assertEquals(prevHead.getName(), db
- .getReflogReader(Constants.HEAD).getLastEntry().getOldId()
- .getName());
+ assertEquals(prevHead.getName(), db.getReflogReader(Constants.HEAD)
+ .getLastEntry().getOldId().getName());
// The reflog for master contains the same as the one for HEAD
String actualMasterMessage = db.getReflogReader("refs/heads/master")
@@ -198,9 +267,9 @@ public class ResetCommandTest extends RepositoryTestCase {
assertEquals(expectedMasterMessage, actualMasterMessage);
assertEquals(head.getName(), db.getReflogReader(Constants.HEAD)
.getLastEntry().getNewId().getName());
- assertEquals(prevHead.getName(),
- db.getReflogReader("refs/heads/master").getLastEntry()
- .getOldId().getName());
+ assertEquals(prevHead.getName(), db
+ .getReflogReader("refs/heads/master").getLastEntry().getOldId()
+ .getName());
}
/**