I am trying to make a script which reads all commits since the last release tag in my repository. For reference, I am locked into using git version 2.46.0 because this is on an azure devops host.
So the last few commits on my repository look like this
eeeee Commit 5
ddddd Commit 4 (tag: other-tag)
ccccc Commit 3
bbbbb Commit 2
aaaaa Commit 1 (tag: iteration-1.0.0)
...
I first run git fetch --tags
and run git tags -l
to verify that all the tags I am expecting are present as well as git checkout main
to make sure I am not in a detached head state.
But when I run git describe --abbrev=0 --match="*iteration*"
it says that it cant describe eeeee
. And when I run git log iteration-1.0.0..HEAD
it only returns eeeee
and ddddd
. It seems like git is unable to look past the “other-tag”. When I delete “other-tag”, I get the data that I am expecting on both commands.
I have tried running these commands on the same repository on my dev machine, and the problem isn’t there. Is it a bug with git?
4
You are working on a shallow clone… Being that the case, git is missing a lot of information working locally.
on Azure DevOps, in the classic build pipelines or in the non-deployment job of YAML pipelines, it will automatically add the default checkout task to clone/check out code from the source repository.
By default, the checkout task:
- Does not fetch tags (
fetchTags: false
). - Shallow fetch is configured with a depth of 1 (
fetchDepth: 1
).
For your case, you can disable the Shallow fetch on the checkout task and also set it to fetch tags in your pipeline:
-
If your pipeline is YAML pipeline, you can configure the checkout task like as below.
# azure-pipelines.yml jobs: - job: A steps: - checkout: self fetchDepth: 0 # Disable the Shallow fetch. Equivalent to '--unshallow' option. fetchTags: true # Fetch tags. Equivalent to '--tags' option. . . .
-
If classic build pipeline, enable “Sync tags” option and disable “Shallow fetch” option on the web UI.
Related Azure DevOps documentations:
- steps.checkout definition
- Shallow fetch
- Sync tags