Skip to content

Commit

Permalink
Fix #71 Support annotated tags in LogOp
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ajoberstar committed Aug 7, 2015
1 parent cba650d commit d959c78
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class LogOp implements Callable<List<Commit>> {
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 ->
Expand Down
6 changes: 4 additions & 2 deletions src/main/groovy/org/ajoberstar/grgit/util/JGitUtil.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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)
}
}

0 comments on commit d959c78

Please sign in to comment.