diff options
author | Robin Stocker <robin@nibor.org> | 2013-08-12 15:13:03 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2013-09-13 15:13:12 +0200 |
commit | 02bd26e5a636fe2d9f128860530eda27ac35b334 (patch) | |
tree | 69dd6957af6cd91ef50e6aa38ec41501c5e8308a /org.eclipse.jgit.test | |
parent | 4b8a848a477cc77caf8e74de6d28b3bcbcaed413 (diff) | |
download | jgit-02bd26e5a636fe2d9f128860530eda27ac35b334.tar.gz jgit-02bd26e5a636fe2d9f128860530eda27ac35b334.zip |
ResetCommand: Allow reset on unborn branch when ref not specified
In C Git 1.8.2, "git reset" now also works on an unborn branch (no HEAD
yet) if no explicit ref was specified. In that case, it is treated as a
reset to an empty tree.
This can be useful for callers because "unborn branch" no longer has to
be special-cased to "git rm --cached".
Bug: 414870
Change-Id: Ied750116f767518ae4d48823cf00752b049a8477
Signed-off-by: Robin Stocker <robin@nibor.org>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java | 38 |
1 files changed, 37 insertions, 1 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 da57cb3249..82249766ad 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011-2012, Chris Aniszczyk <caniszczyk@gmail.com> + * Copyright (C) 2011-2013, Chris Aniszczyk <caniszczyk@gmail.com> * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -404,6 +404,27 @@ public class ResetCommandTest extends RepositoryTestCase { } @Test + public void testPathsResetOnUnbornBranch() throws Exception { + git = new Git(db); + writeTrashFile("a.txt", "content"); + git.add().addFilepattern("a.txt").call(); + // Should assume an empty tree, like in C Git 1.8.2 + git.reset().addPath("a.txt").call(); + + DirCache cache = db.readDirCache(); + DirCacheEntry aEntry = cache.getEntry("a.txt"); + assertNull(aEntry); + } + + @Test(expected = JGitInternalException.class) + public void testPathsResetToNonexistingRef() throws Exception { + git = new Git(db); + writeTrashFile("a.txt", "content"); + git.add().addFilepattern("a.txt").call(); + git.reset().setRef("doesnotexist").addPath("a.txt").call(); + } + + @Test public void testHardResetOnTag() throws Exception { setupRepository(); String tagName = "initialtag"; @@ -453,6 +474,21 @@ public class ResetCommandTest extends RepositoryTestCase { assertNull(db.readSquashCommitMsg()); } + @Test + public void testHardResetOnUnbornBranch() throws Exception { + git = new Git(db); + File fileA = writeTrashFile("a.txt", "content"); + git.add().addFilepattern("a.txt").call(); + // Should assume an empty tree, like in C Git 1.8.2 + git.reset().setMode(ResetType.HARD).call(); + + DirCache cache = db.readDirCache(); + DirCacheEntry aEntry = cache.getEntry("a.txt"); + assertNull(aEntry); + assertFalse(fileA.exists()); + assertNull(db.resolve(Constants.HEAD)); + } + private void assertReflog(ObjectId prevHead, ObjectId head) throws IOException { // Check the reflog for HEAD |