I'm trying to understand why I'm getting two different results relative to git tags when running my bitbucket-pipelines.yml file. Currently my project has tags running from 1.0.0 - 1.0.25
. The .yml file looks like this...
pipelines:
branches:
diff-test:
- step:
script:
- export PREVIOUS_GIT_HASH=`git rev-list --tags --skip=2 --max-count=1`
- export PREVIOUS_GIT_TAG=`git describe ${PREVIOUS_GIT_HASH} --abbrev=0`
- export GIT_TAG=`git describe --tags --abbrev=0`
- echo ${PREVIOUS_GIT_TAG} ${GIT_TAG}
# A develop step/script happens here but it's irrelevant...
master:
- step:
script:
# set the most recent tag as an environment variable.
- export GIT_TAG=`git describe --tags --abbrev=0`
- zip -FSr ${BITBUCKET_REPO_SLUG}-${GIT_TAG}.zip ./ -x@exclude.lst
- curl -u ${BB_AUTH_STRING} -X POST "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${BITBUCKET_REPO_SLUG}-${GIT_TAG}.zip"
When I push to master, the tag appended to the download artifact is correct (1.0.25). However, when I push to diff-test
, the tags that are echo'd out are 1.0.14
and 1.0.15
.
In the git documentation, it for describe
, it says --tags: Instead of using only the annotated tags, use any tag found in refs/tags namespace. This option enables matching a lightweight (non-annotated) tag.
.
My question is - What causes the tags to appear different depending on what branch I push to?
Git describe gives information about a specific commit, and everything else (i.e. tag) is relative to that commit. It will not report tags that don't exist in that commit's ancestry. Because branches have different ancestries, describing commits in different branches may yield different results.
From the documentation (emphasis mine):
The command finds the most recent tag that is reachable from a commit.