The key is to restore the .git directory before the rest of the Maven 3 build executes. I do this by adding this profile to my build:
Of course, replace "https://bitbucket.org/mrdon/weapon-m.git" with your repository.What this does is check to see if the ".git" directory is missing, which it will be only for Heroku builds as they remove the directory before Maven execution, clone the repo, then move its ".git" directory back where it belongs.
This approach has several notable gotchas:
- Your repository url must contain any authentication information. If your main repo is anonymous accessible, great, otherwise, you'll have to find someway to encode authentication credentials in the URL.
- You'll need to push to your main repo before you push to heroku. This is a shame as I like to run "git push heroku master && git push origin master" to let me rewrite the commit in case the build fails on Heroku, which it occasionally does. However, with this technique, if you want that git information in your build, you'll have to push to your main repo first.
- Only operations that view the history will work correctly. If you tried to run "git status" or manipulated your local copy, git is all confused.