summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobin Rosenberg <robin.rosenberg@dewire.com>2013-10-19 09:55:58 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2013-10-19 09:55:58 -0400
commitc01a66debaea2fb6366ff1c9b23dd33be7af69ef (patch)
tree61a6094a15d5f1230c9d68703e399d74a4621c0a
parent8de3512890480dbed07fa6d46aef722c1ddda442 (diff)
parentb15c617d0f1c098c06b3579d00e8d505047a153d (diff)
downloadjgit-c01a66debaea2fb6366ff1c9b23dd33be7af69ef.tar.gz
jgit-c01a66debaea2fb6366ff1c9b23dd33be7af69ef.zip
Merge changes I5a5a2387,I04805ce2
* changes: Describe HEAD if no explicit target was set Allow to set target of DescribeCommand
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java18
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java22
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java1
4 files changed, 25 insertions, 17 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
index 88f6108926..eb598e80fd 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
@@ -42,16 +42,19 @@
*/
package org.eclipse.jgit.api;
-import org.eclipse.jgit.api.errors.GitAPIException;
-import org.eclipse.jgit.junit.RepositoryTestCase;
-import org.eclipse.jgit.lib.ObjectId;
-import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
-import static org.junit.Assert.*;
+import org.eclipse.jgit.api.errors.GitAPIException;
+import org.eclipse.jgit.api.errors.RefNotFoundException;
+import org.eclipse.jgit.junit.RepositoryTestCase;
+import org.eclipse.jgit.lib.ObjectId;
+import org.junit.Test;
public class DescribeCommandTest extends RepositoryTestCase {
@@ -63,7 +66,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
git = new Git(db);
}
- @Test(expected = IllegalArgumentException.class)
+ @Test(expected = RefNotFoundException.class)
public void noTargetSet() throws Exception {
git.describe().call();
}
@@ -87,6 +90,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertNameStartsWith(c4, "3e563c5");
// the value verified with git-describe(1)
assertEquals("t2-1-g3e563c5", describe(c4));
+
+ // test default target
+ assertEquals("t2-1-g3e563c5", git.describe().call());
}
/**
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
index e0daa4d126..706dce7ce1 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
@@ -478,7 +478,6 @@ systemConfigFileInvalid=Systen wide config file {0} is invalid {1}
tagAlreadyExists=tag ''{0}'' already exists
tagNameInvalid=tag name {0} is invalid
tagOnRepoWithoutHEADCurrentlyNotSupported=Tag on repository without HEAD currently not supported
-targetIsNotSet=Target is not set
theFactoryMustNotBeNull=The factory must not be null
timerAlreadyTerminated=Timer already terminated
topologicalSortRequired=Topological sort required.
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
index ec85c5abe0..c2bf744108 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -48,6 +48,7 @@ import org.eclipse.jgit.api.errors.RefNotFoundException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.JGitText;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
@@ -107,7 +108,7 @@ public class DescribeCommand extends GitCommand<String> {
* @throws IOException
* a pack file or loose object could not be read.
*/
- DescribeCommand setTarget(ObjectId target) throws IOException {
+ public DescribeCommand setTarget(ObjectId target) throws IOException {
this.target = w.parseCommit(target);
return this;
}
@@ -126,7 +127,8 @@ public class DescribeCommand extends GitCommand<String> {
* @throws IOException
* a pack file or loose object could not be read.
*/
- DescribeCommand setTarget(String rev) throws IOException, RefNotFoundException {
+ public DescribeCommand setTarget(String rev) throws IOException,
+ RefNotFoundException {
ObjectId id = repo.resolve(rev);
if (id == null)
throw new RefNotFoundException(MessageFormat.format(JGitText.get().refNotResolved, rev));
@@ -134,14 +136,16 @@ public class DescribeCommand extends GitCommand<String> {
}
/**
- * Describes the specified commit.
+ * Describes the specified commit. Target defaults to HEAD if no commit was
+ * set explicitly.
*
- * @return if there's a tag that points to the commit being described, this tag name
- * is returned. Otherwise additional suffix is added to the nearest tag, just
- * like git-describe(1).
+ * @return if there's a tag that points to the commit being described, this
+ * tag name is returned. Otherwise additional suffix is added to the
+ * nearest tag, just like git-describe(1).
* <p/>
- * If none of the ancestors of the commit being described has any tags at all,
- * then this method returns null, indicating that there's no way to describe this tag.
+ * If none of the ancestors of the commit being described has any
+ * tags at all, then this method returns null, indicating that
+ * there's no way to describe this tag.
*/
@Override
public String call() throws GitAPIException {
@@ -149,7 +153,7 @@ public class DescribeCommand extends GitCommand<String> {
checkCallable();
if (target == null)
- throw new IllegalArgumentException(JGitText.get().targetIsNotSet);
+ setTarget(Constants.HEAD);
Map<ObjectId, Ref> tags = new HashMap<ObjectId, Ref>();
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
index 7b88090201..8ac971ab62 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
@@ -540,7 +540,6 @@ public class JGitText extends TranslationBundle {
/***/ public String tagAlreadyExists;
/***/ public String tagNameInvalid;
/***/ public String tagOnRepoWithoutHEADCurrentlyNotSupported;
- /***/ public String targetIsNotSet;
/***/ public String theFactoryMustNotBeNull;
/***/ public String timerAlreadyTerminated;
/***/ public String topologicalSortRequired;