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?
Returns the latest tag in the current branch. To get the latest annotated tag which targets only the current commit in the current branch, use git describe --exact-match --abbrev=0 .
In order to find the latest Git tag available on your repository, you have to use the “git describe” command with the “–tags” option. This way, you will be presented with the tag that is associated with the latest commit of your current checked out branch.
The `git describe` command finds the most recent tag that is reachable from a commit. If the tag is on the current commit, then only the tag is shown. Otherwise, it shows the tag name appended with the number of additional commits and the abbreviated SHA of the current commit.
Listing the available tags in Git is straightforward. Just type git tag (with optional -l or --list ). You can also search for tags that match a particular pattern. The command finds the most recent tag that is reachable from a commit.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With