Get latest Git tag from a repository using Phing
Asked Answered
M

1

7

I'm new to phing and building a script to automate some build tasks.

Is there a way to retrieve just the most recently added tag to a git repo? I can pull up a list of all my tags but cannot seem to filter it down to the latest one.

Here's the relevant code that fetches my git tags:

    <gittag 
        repository="${repo.dir.resolved}" 
        list="true" 
        outputProperty="versionTag" 
        pattern="v*" />

The output of the above results in a list of tags (prefixed by "v"):

[gittag] git-tag output: v1.0.0
v1.0.1
v1.0.2

Any ideas on how I can get this down to just the v1.0.2?

Matriarch answered 13/11, 2011 at 17:1 Comment(0)
M
7

Managed to get this done as follows:

    <exec 
        outputProperty="latestVersion" 
        command="git describe --tags `git rev-list --tags --max-count=1`" 
        dir="${repo.dir.resolved}"/>

It does work, though I'm open to suggestions if this can be improved!

Matriarch answered 13/11, 2011 at 17:59 Comment(3)
I was going to suggest this as well.Cavity
The only suggestion I would have is to extend the GitTag task and submit the changes for inclusion.Cavity
Thannks @Cavity - I will look into it!Matriarch

© 2022 - 2024 — McMap. All rights reserved.