From d959c7886f598c179e5bb0f1ea2c5294fdf9305c Mon Sep 17 00:00:00 2001 From: Andrew Oberstar Date: Thu, 6 Aug 2015 20:56:23 -0500 Subject: [PATCH] Fix #71 Support annotated tags in LogOp Objects in include/exclude on LogOp are still resolved to rev strings. The revstrings are resolved to peeled RevObjects to get the ObjectId of the underlying commit. The peeling gets past the issues with annotated tags. --- src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy | 2 +- src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy | 6 ++++-- .../groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy b/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy index 87883934..3cfdf6a8 100644 --- a/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/operation/LogOp.groovy @@ -91,7 +91,7 @@ class LogOp implements Callable> { ResolveService resolve = new ResolveService(repo) def toObjectId = { rev -> String revstr = resolve.toRevisionString(rev) - JGitUtil.resolveObject(repo, revstr) + JGitUtil.resolveRevObject(repo, revstr, true).getId() } includes.collect(toObjectId).each { object -> diff --git a/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy b/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy index 2dd3260a..712ad084 100644 --- a/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy +++ b/src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy @@ -78,14 +78,16 @@ class JGitUtil { * Resolves a JGit {@code RevObject} using the given revision string. * @param repo the Grgit repository to resolve the object from * @param revstr the revision string to use + * @param peel whether or not to peel the resolved object * @return the resolved object * @throws GrgitException if the object cannot be resolved */ - static RevObject resolveRevObject(Repository repo, String revstr) { + static RevObject resolveRevObject(Repository repo, String revstr, boolean peel = false) { ObjectId id = resolveObject(repo, revstr) RevWalk walk = new RevWalk(repo.jgit.repository) try { - return walk.parseAny(id) + RevObject rev = walk.parseAny(id) + return peel ? walk.peel(rev) : rev } catch (MissingObjectException e) { throw new GrgitException("Supplied object does not exist: ${revstr}", e) } catch (IOException e) { diff --git a/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy b/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy index 587371bd..fd1a9ab9 100644 --- a/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy +++ b/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy @@ -39,6 +39,7 @@ class LogOpSpec extends SimpleGitOpSpec { testFile1 << '2' grgit.add(patterns: ['.']) commits << grgit.commit(message: 'second commit') + grgit.tag.add(name: 'v1.0.0', message: 'annotated tag') grgit.checkout(branch: intToCommit(0).id) testFile1 << '3' @@ -85,4 +86,9 @@ class LogOpSpec extends SimpleGitOpSpec { expect: grgit.log(paths:['2.txt']) == [5, 0].collect(intToCommit) } + + def 'log with annotated tag short name works'() { + expect: + grgit.log(includes: ['v1.0.0']) == [1, 0].collect(intToCommit) + } }