aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDariusz Luksza <dariusz@luksza.org>2011-07-07 00:27:14 +0200
committerChris Aniszczyk <caniszczyk@gmail.com>2011-07-12 11:14:28 -0500
commit1d1f5727716bf8626869064812a05a3e39e1d0f2 (patch)
treeacc0f81118b3477e36da37a13635f3f72e057340 /org.eclipse.jgit.test
parent1d4a1fe772745e80312543c0e4bf36974df49d4e (diff)
downloadjgit-1d1f5727716bf8626869064812a05a3e39e1d0f2.tar.gz
jgit-1d1f5727716bf8626869064812a05a3e39e1d0f2.zip
Add support for reseting on directories
Reset command should works recursively and allows reset all changed files in given directory. Bug: 348524 Change-Id: I441db34f226be36548c61cef77958995971498de Signed-off-by: Dariusz Luksza <dariusz@luksza.org> 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.java46
1 files changed, 43 insertions, 3 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 f79592f223..e6d689a18a 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
@@ -93,6 +93,16 @@ public class ResetCommandTest extends RepositoryTestCase {
git = new Git(db);
initialCommit = git.commit().setMessage("initial commit").call();
+ // create nested file
+ File dir = new File(db.getWorkTree(), "dir");
+ FileUtils.mkdir(dir);
+ File nestedFile = new File(dir, "b.txt");
+ FileUtils.createNewFile(nestedFile);
+
+ PrintWriter nesterFileWriter = new PrintWriter(nestedFile);
+ nesterFileWriter.print("content");
+ nesterFileWriter.flush();
+
// create file
indexFile = new File(db.getWorkTree(), "a.txt");
FileUtils.createNewFile(indexFile);
@@ -101,8 +111,9 @@ public class ResetCommandTest extends RepositoryTestCase {
writer.flush();
// add file and commit it
- git.add().addFilepattern("a.txt").call();
- secondCommit = git.commit().setMessage("adding a.txt").call();
+ git.add().addFilepattern("dir").addFilepattern("a.txt").call();
+ secondCommit = git.commit().setMessage("adding a.txt and dir/b.txt")
+ .call();
prestage = DirCache.read(db.getIndexFile(), db.getFS()).getEntry(
indexFile.getName());
@@ -110,7 +121,9 @@ public class ResetCommandTest extends RepositoryTestCase {
// modify file and add to index
writer.print("new content");
writer.close();
- git.add().addFilepattern("a.txt").call();
+ nesterFileWriter.print("new content");
+ nesterFileWriter.close();
+ git.add().addFilepattern("a.txt").addFilepattern("dir").call();
// create a file not added to the index
untrackedFile = new File(db.getWorkTree(),
@@ -221,6 +234,33 @@ public class ResetCommandTest extends RepositoryTestCase {
}
@Test
+ public void testPathsResetOnDirs() throws Exception {
+ setupRepository();
+
+ DirCacheEntry preReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry("dir/b.txt");
+ assertNotNull(preReset);
+
+ git.add().addFilepattern(untrackedFile.getName()).call();
+
+ // 'dir/b.txt' has already been modified in setupRepository
+ git.reset().addPath("dir").call();
+
+ DirCacheEntry postReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry("dir/b.txt");
+ assertNotNull(postReset);
+ Assert.assertNotSame(preReset.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(inHead("dir/b.txt"));
+ assertTrue(inIndex("dir/b.txt"));
+ }
+
+ @Test
public void testPathsResetWithRef() throws Exception {
setupRepository();