I have a project were I use a rather uncommon tag strategy. We end up with tags being leafs so our history looks like this:
0.3.0 0.3.0
|/ |
| 0.2.0 rather than 0.2.0
|/ |
| 0.1.0 0.1.0
|/ |
The reason why I do this is that our tags should include the dist output whereas during development we don't want to commit such files into version control. So when I run the build, the build tool automatically branches off, adds the build artifacts (dist folder) with a generated commit and then creates the tag there.
This workflow might look odd at first glance but so far I have found it to be quite convenient as we need to have the dist folder in our tags for a downstream deployment process.
Now the problem is, I want to generate release notes automatically, just the problem is, how do I figure out the previous tag in such a scenario? I'm aware of the answers given here but with tags being leafs, this doesn't work that way.
(edit: original rewarded answer down below, here's a much simpler way that tags merge bases so git describe can find them.
doit ()
{
cleanup="`mktemp -t`";
git for-each-ref refs/tags/"$1" --format='
echo git tag -d base/%(refname:short) >> '"$cleanup"'
git tag base/%(refname:short) $(git merge-base HEAD %(refname:short))
' | sh -x;
result=`git describe --tags`;
sh -x "$cleanup";
rm "$cleanup"
echo ${result#base/}
}
doit "0.*"
)
Use latest.awk from this answer this way:
doit ()
{
git rev-list --topo-order --first-parent --children --tags --format=%d \
| awk -f path/to/latest.awk \
| sed -n /$1"/,$ { /"$1"/! {p;q} }"
}
Testing:
~/sandbox/15$ git lgdo --topo-order --tags
* ecb363d (tag: tag4) tag4
* cd9f402 master
| * 26aa94b (tag: tag3) tag3
|/
* a1b6c1b master
| * 8866091(tag: tag2)tag2
|/
* b5d5283 master
| * 29a4e54(tag: tag1)tag1
|/
* cfcd7dc master
* 6120ab4 (tag: empty)
~/sandbox/15$ doit tag2
29a4e54debae973dfc3955d6663f14d6ade73df9 (tag: tag1)
~/sandbox/15$
(edit: and
~/sandbox/15$ git checkout tag4
HEAD is now at ecb363d... tag4
~/sandbox/15$ git describe --tags
tag4
~/sandbox/15$ doit `git describe --tags`
26aa94bad1e37602791c354823cb4a84ff6fc437 (tag: tag3)
~/sandbox/15$
)
(git lgdo being an alias for git log --graph --decorate --oneline, and the "master"s in there being commit-message artifacts of a make-me-some-commits helper)
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