bash - Write "current" git tag to text file -
for tagging versions of software, using git tags. want software display version user, , execute migration code, depends on version used.
therefore, tried use git-hook pre-commit in order generate file version.txt
#!/bin/sh # show recent tag without trailing commit information git describe --tags | awk "{split(\$0,a,\"-\"); print a[1];}" > version.tmp # proceed if version number has changed (i.e. new tag has been created) if [ ! $(cmp --silent version.tmp version.txt) ] echo $? echo updating version.txt. mv -f version.tmp version.txt git add version.txt fi i entered commands
$ git add --all $ git tag -a 1.0 $ git commit it turns out version.txt tagged 1.0does not contain respective version, 1.0, prior version ( 0.9) instead.
what wrong procedure? how else possible keep information git tag (and commit) software?
you have think of commit objects , what's happening those.
in series of statements, you're tagging current head 1.0, version.txt contains 0.9. tagging marker on commit object, , file has "0.9", that's gets tagged.
then on next commit version file gets bumped 1.0, new commit , aren't changing tag 1.0 point it.
it looks you're trying use tag in not quite way it's designed. might reverse procedure, , people change version.txt file, , use post-commit hook add tag. tried , works like:
#!/bin/sh # show recent tag without trailing commit information git describe --tags | awk "{split(\$0,a,\"-\"); print a[1];}" > version.tmp # proceed if version number has changed (i.e. new tag has been created) if [ ! $(cmp --silent version.tmp version.txt) ] newver=$(cat version.txt) echo adding tag $newver git tag -a $newver -m '' rm version.tmp fi you might want @ alternate tag gets moved commit, have in post-commit tagging in pre-commit goes on current head, not 1 commit. hence why had use post-commit above.
personally try , avoid automated tagging / version bumping there kinds of end conditions - happens during amend? if want rebase? but, has own use-cases.
Comments
Post a Comment