2

The application is written in angular js. I want to be able to update the ver={%tag%} to ver=v1 where v1 is the git tag.

for example in index file like this.

<script src="js/controllers/AController.js?ver={%tag%}"></script>
<script src="js/controllers/BController.js"?ver={%tag%}></script>

I want to achieve this functionality when checking out tag in production. So that I don't have to manually update the version number for each file to stay in sync with git tag. If there is a way to do this with git hook. I'll accept that also. But please provide example. This will allow users to get the latest version of the files instead of cached version and will prevent users from manually clearing the cache for changes. Just to let you know I am using bitbucket.

1 Answers1

2

If you know what files are to be updated, you can associate to them a smudge content filter driver, using .gitattributes declaration.

smudge
(image from "Customizing Git - Git Attributes", from "Pro Git book")

The idea is do apply a filter on checkout, which in your case would be a simply sed (to replace the placeholder %tag% with the content of git describe --abbrev=0 --tags to get the latest tag)

The filter declaration in the local config of the repo on the server would look like

[filter "replaceTag"]
        smudge = sed \"s/%tag%/`git describe --abbrev=0 --tags`/g\"
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250