question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Git tags - support for multiple versions on same commit

See original GitHub issue

I think that the current mechanism for getting tags (improved in #77) doesn’t pick the biggest version if you tag the same commit multiple times for the same application but for different versions.

Basically when I bump a version number for my application without doing a commit (not that common but does happen if we update a package’s dependencies) the older tag is getting picked up.

Probably easiest to illustrate just using git and the current “git describe” command:

# git init .
Initialised empty Git repository in /tmp/x/.git/
# touch x && git add x && git commit -m "test"
[master (root-commit) 217feb2] test
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 x
# git tag R_example_1.0.0
# git tag R_example_1.0.1
# git describe --tags --dirty --always --long --match "R_example*"
R_example_1.0.0-0-g217feb2

Here 1.0.0 is getting taken over 1.0.1, clearly I’d like to have 1.0.1 taken over it.

From initial googling there seems to be a way to get the current tags for a commit. I suppose you could take these all in, parse them and pick the biggest? But I guess this doesn’t give you the nice things that describe does (like dirty and commits ahead).

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
SvenRtbgcommented, Mar 27, 2017

Tagging with annotated tags not only adds the timestamp and committer account to this tag (and a message that probably nobody cares about), but also allows Git to pick the more recent tag, i.e. the one added later in time, when running git describe.

0reactions
jeichel-miovisioncommented, Mar 25, 2020

For my purposes I added a block of code after pieces["closest-tag"] = ... to get the most recent tag

...
        pieces["closest-tag"] = full_tag[len(tag_prefix) :]

        # try to find most recent from multiple tags
        points_at_out, rc = run_command(
            GITS, ["tag", "--sort", "committerdate", "--points-at", "%s%s" % (tag_prefix, pieces["closest-tag"])],
            cwd=root
        )
        # --points-at was added in git-2.4.0
        if points_at_out is not None:
            points_at_out = points_at_out.strip().split('\n')
            for version in points_at_out:
                if version.startswith(tag_prefix):
                    pieces["closest-tag"] = version[len(tag_prefix) :]

        # distance: number of commits since tag
        pieces["distance"] = int(mo.group(2))
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

Git - Tagging - Git SCM
Git supports two types of tags: lightweight and annotated. A lightweight tag is very much like a branch that doesn't change — it's...
Read more >
git describe with two tags on the same commit - Stack Overflow
SEARCH STRATEGY For each committish supplied, git describe will first look for a tag which tags exactly that commit. Annotated tags will always ......
Read more >
git - How do you put different versions of your library under ...
Method 2: Branching versions​​ In this method, the main branch would be the development branch. Every now and then that a stable version...
Read more >
Managing Releases with Semantic Versioning and Git Tags
Michael Miles from MIT Sloan shares how to manage software releases with semantic versioning and Git tags. Learn about build numbers and how...
Read more >
Git Tags: Are They Useful and How to Use Them - Bitband
Don't get confused between tags and branches. While both offer a similar service (pointing to a specific commit), a tag is fixed. A...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found