summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorSebastian Schuberth <sschuberth@gmail.com>2019-03-15 15:27:18 +0100
committerSebastian Schuberth <sschuberth@gmail.com>2019-05-31 17:11:15 +0200
commit237c76fddfbca59062c495ce4b3e05ea61b1cd7e (patch)
treef6294596aa2ee4c2fde4047265aea22943fd6a5d /org.eclipse.jgit
parent0cac83466842a26a4901151b9db11a9a7428dc5a (diff)
downloadjgit-237c76fddfbca59062c495ce4b3e05ea61b1cd7e.tar.gz
jgit-237c76fddfbca59062c495ce4b3e05ea61b1cd7e.zip
DescribeCommand: Support the "always" option
See: https://git-scm.com/docs/git-describe#Documentation/git-describe.txt---always Extend the tests accordingly. Change-Id: Ibfcda338a246c8cba0df6b6e7b9bad76c9f8b593 Signed-off-by: Sebastian Schuberth <sschuberth@gmail.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java25
1 files changed, 23 insertions, 2 deletions
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 659812450a..db3a3d947d 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/DescribeCommand.java
@@ -112,6 +112,11 @@ public class DescribeCommand extends GitCommand<String> {
private boolean useTags;
/**
+ * Whether to show a uniquely abbreviated commit hash as a fallback or not.
+ */
+ private boolean always;
+
+ /**
* Constructor for DescribeCommand.
*
* @param repo
@@ -197,6 +202,21 @@ public class DescribeCommand extends GitCommand<String> {
return this;
}
+ /**
+ * Always describe the commit by eventually falling back to a uniquely
+ * abbreviated commit hash if no other name matches.
+ *
+ * @param always
+ * <code>true</code> enables falling back to a uniquely
+ * abbreviated commit hash
+ * @return {@code this}
+ * @since 5.4
+ */
+ public DescribeCommand setAlways(boolean always) {
+ this.always = always;
+ return this;
+ }
+
private String longDescription(Ref tag, int depth, ObjectId tip)
throws IOException {
return String.format(
@@ -399,8 +419,9 @@ public class DescribeCommand extends GitCommand<String> {
}
// if all the nodes are dominated by all the tags, the walk stops
- if (candidates.isEmpty())
- return null;
+ if (candidates.isEmpty()) {
+ return always ? w.getObjectReader().abbreviate(target).name() : null;
+ }
Candidate best = Collections.min(candidates,
(Candidate o1, Candidate o2) -> o1.depth - o2.depth);