Browse Source

Describe HEAD if no explicit target was set

Change-Id: I5a5a238709df813ec07278bb3b4f9ea5c85c0883
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-3.2
Matthias Sohn 11 years ago
parent
commit
b15c617d0f
  1. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java
  2. 1
      org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
  3. 17
      org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
  4. 1
      org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DescribeCommandTest.java

@ -42,16 +42,19 @@
*/ */
package org.eclipse.jgit.api; package org.eclipse.jgit.api;
import org.eclipse.jgit.api.errors.GitAPIException; import static org.junit.Assert.assertEquals;
import org.eclipse.jgit.junit.RepositoryTestCase; import static org.junit.Assert.assertNull;
import org.eclipse.jgit.lib.ObjectId; import static org.junit.Assert.assertTrue;
import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; 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 { public class DescribeCommandTest extends RepositoryTestCase {
@ -63,7 +66,7 @@ public class DescribeCommandTest extends RepositoryTestCase {
git = new Git(db); git = new Git(db);
} }
@Test(expected = IllegalArgumentException.class) @Test(expected = RefNotFoundException.class)
public void noTargetSet() throws Exception { public void noTargetSet() throws Exception {
git.describe().call(); git.describe().call();
} }
@ -87,6 +90,9 @@ public class DescribeCommandTest extends RepositoryTestCase {
assertNameStartsWith(c4, "3e563c5"); assertNameStartsWith(c4, "3e563c5");
// the value verified with git-describe(1) // the value verified with git-describe(1)
assertEquals("t2-1-g3e563c5", describe(c4)); assertEquals("t2-1-g3e563c5", describe(c4));
// test default target
assertEquals("t2-1-g3e563c5", git.describe().call());
} }
/** /**

1
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 tagAlreadyExists=tag ''{0}'' already exists
tagNameInvalid=tag name {0} is invalid tagNameInvalid=tag name {0} is invalid
tagOnRepoWithoutHEADCurrentlyNotSupported=Tag on repository without HEAD currently not supported tagOnRepoWithoutHEADCurrentlyNotSupported=Tag on repository without HEAD currently not supported
targetIsNotSet=Target is not set
theFactoryMustNotBeNull=The factory must not be null theFactoryMustNotBeNull=The factory must not be null
timerAlreadyTerminated=Timer already terminated timerAlreadyTerminated=Timer already terminated
topologicalSortRequired=Topological sort required. topologicalSortRequired=Topological sort required.

17
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.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException; import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.internal.JGitText; import org.eclipse.jgit.internal.JGitText;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
@ -135,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 * @return if there's a tag that points to the commit being described, this
* is returned. Otherwise additional suffix is added to the nearest tag, just * tag name is returned. Otherwise additional suffix is added to the
* like git-describe(1). * nearest tag, just like git-describe(1).
* <p/> * <p/>
* If none of the ancestors of the commit being described has any tags at all, * If none of the ancestors of the commit being described has any
* then this method returns null, indicating that there's no way to describe this tag. * tags at all, then this method returns null, indicating that
* there's no way to describe this tag.
*/ */
@Override @Override
public String call() throws GitAPIException { public String call() throws GitAPIException {
@ -150,7 +153,7 @@ public class DescribeCommand extends GitCommand<String> {
checkCallable(); checkCallable();
if (target == null) if (target == null)
throw new IllegalArgumentException(JGitText.get().targetIsNotSet); setTarget(Constants.HEAD);
Map<ObjectId, Ref> tags = new HashMap<ObjectId, Ref>(); Map<ObjectId, Ref> tags = new HashMap<ObjectId, Ref>();

1
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java

@ -540,7 +540,6 @@ public class JGitText extends TranslationBundle {
/***/ public String tagAlreadyExists; /***/ public String tagAlreadyExists;
/***/ public String tagNameInvalid; /***/ public String tagNameInvalid;
/***/ public String tagOnRepoWithoutHEADCurrentlyNotSupported; /***/ public String tagOnRepoWithoutHEADCurrentlyNotSupported;
/***/ public String targetIsNotSet;
/***/ public String theFactoryMustNotBeNull; /***/ public String theFactoryMustNotBeNull;
/***/ public String timerAlreadyTerminated; /***/ public String timerAlreadyTerminated;
/***/ public String topologicalSortRequired; /***/ public String topologicalSortRequired;

Loading…
Cancel
Save