Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add tag in "export-subst" file

Tags:

git

Situation

We have a git workflow, where all release versions are stacked on the master branch, and when a commit is ready for deployment, we add a tag to it, then use git archive to build a bundle to be deployed.

We use a version.txt file, marked in .gitattributes with the option export-subst, to keep track of which commit was used to build a given archive.

Question

If I write $Format:%d$ in version.txt, and export a tagged commit, I will have something like (HEAD, tag, master) written in the resulting file.

How can I have the tag alone ?

[edit] There is a git command which already produces that :

git describe --tags HEAD

This will output :

latest_tag            #if HEAD is tagged

latest_tag-5-g03cc91b #if HEAD is not tagged,
                      #and the latest tag is 5 commits ago on commit g03cc91b

Is there some way to have a slug replaced with this output in version.txt ?

like image 422
LeGEC Avatar asked Oct 29 '13 13:10

LeGEC


People also ask

What should be included in Gitattributes?

gitattributes file allows you to specify the files and paths attributes that should be used by git when performing git actions, such as git commit , etc. In other words git automatically saves the file according to the attributes specified, every time a file is created or saved.

How do I export a file from Git?

Step 1: Go to your git bash. and then to the repo you want to extract or export. Here, we are going to export this repo named 'Ada August-a Challenge' and it's main branch. Step 2: Now export it to your preferred format and location, here we will export it to the same location in .

What is the use of Git attributes?

Using attributes, you can do things like specify separate merge strategies for individual files or directories in your project, tell Git how to diff non-text files, or have Git filter content before you check it into or out of Git.

What is a git archive?

Git archive is a helpful utility for creating distributable packages of git repositories. Git archive can target specific refs of a repository and only package the contents of that ref. Git archive has several output formats that can utilize added compression.


1 Answers

You could use a content filter driver which would on git checkout automatically do the exact change you want.

content filter river: smudge

(From Pro Git book 7.2 Customizing Git - Git Attributes)

You declare in a .gitattributes file a smudge script which will do the substitution for a special marker (that you want to be replaced with git describe --tags HEAD), without touching the other markers to be modified by export-subst on git archive.

Then you call git archive, which should (not tested) replace the rest.

like image 68
VonC Avatar answered Sep 19 '22 03:09

VonC