You can use the clean/smudge filter in git attributes to do this:
http://git-scm.com/book/ch7-2.html#Keyword-Expansion
You can specify a custom keyword that you "clean" when you add or commit files. When you take the file out of the repo it will "smudge" the keyword with the info you want. I'll explain my approach here.
Here is the part of the XML file holding the Git hash. This is what it looks like after smudge.
Code: Select all
<text x="95.885" y="10.16" size="1.4224" layer="21" rot="R180">GIT 73d710e</text>
Code: Select all
<text x="95.885" y="10.16" size="1.4224" layer="21" rot="R180">%GIT_COMMIT_ID%</text>
Code: Select all
my_ultimate_board.brd filter=hasher
I call it the "hasher". This command is then specified either in the global git config or under the project config:
Code: Select all
[filter "hasher"]
smudge = sed \"s/GIT %GIT_COMMIT_ID%/GIT `git rev-parse --verify HEAD --short`/\"
clean = sed \"s/GIT [0-9a-z]\\{7\\}/GIT %GIT_COMMIT_ID%/\"
I just used simple sed regexp replace commands to find and replace the hash/keyword. You can use whatever command you like/have or script. You can also alter the git command as you please. Maybe use git describe etc.
One problem with this approach is that after you commit the file the new commit id won't be available until after you checkout the file again. So remember that.
To get the id into eagle I save the file, commit, delete the file and checkout the file again. Then I can make the gerbers or whatever I publish with the current commit id.
Thats it. Hope this comes in handy and if you find a better approach or enhance this, let me/us know.