summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDariusz Luksza <dariusz@luksza.org>2012-05-23 02:04:04 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2012-05-23 16:18:33 +0200
commit1bec1f2fae58649bf1d29d5d9e226545fa66f170 (patch)
tree7b28428244d60cadc7d1fd2308a1ae3cc63b421b
parent3da4c6fc58b666d31eafaaec3f1337fc665cd14f (diff)
downloadjgit-1bec1f2fae58649bf1d29d5d9e226545fa66f170.tar.gz
jgit-1bec1f2fae58649bf1d29d5d9e226545fa66f170.zip
Ensure resetting on commit id
When reset command was called with tag name as parameter the resulting HEAD was set to the tag's SHA-1 which is a bug. This patch ensures that repository.resolve() call always returns commit id. Change-Id: I219b898c620a75c497c8652dbf4735fd094c4d7c Signed-off-by: Dariusz Luksza <dariusz@luksza.org> Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java20
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java2
2 files changed, 21 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 f10aaf52e1..27c3549be3 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
@@ -42,6 +42,7 @@
*/
package org.eclipse.jgit.api;
+import static org.eclipse.jgit.api.ResetCommand.ResetType.HARD;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -305,6 +306,25 @@ public class ResetCommandTest extends RepositoryTestCase {
assertFalse(inIndex(untrackedFile.getName()));
}
+ @Test
+ public void testHardResetOnTag() throws Exception {
+ setupRepository();
+ String tagName = "initialtag";
+ git.tag().setName(tagName).setObjectId(secondCommit)
+ .setMessage("message").call();
+
+ DirCacheEntry preReset = DirCache.read(db.getIndexFile(), db.getFS())
+ .getEntry(indexFile.getName());
+ assertNotNull(preReset);
+
+ git.add().addFilepattern(untrackedFile.getName()).call();
+
+ git.reset().setRef(tagName).setMode(HARD).call();
+
+ ObjectId head = db.resolve(Constants.HEAD);
+ assertTrue(head.equals(secondCommit));
+ }
+
private void assertReflog(ObjectId prevHead, ObjectId head)
throws IOException {
// Check the reflog for HEAD
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
index 60776f903c..422056bd6d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java
@@ -150,7 +150,7 @@ public class ResetCommand extends GitCommand<Ref> {
// resolve the ref to a commit
final ObjectId commitId;
try {
- commitId = repo.resolve(ref);
+ commitId = repo.resolve(ref + "^{commit}");
if (commitId == null) {
// @TODO throw an InvalidRefNameException. We can't do that
// now because this would break the API