Search code examples
python-3.xgitunit-testingpython-unittest

How can I add a .git directory to a git repository?


I am doing unit tests on a python program who, for QA purposes, gets the repository name and the current commit hash from the .git in the directory

For my unit tests on that program I would like to have a dummy .git directory in the tests directory. That .git repository would have a single initialization commit and a remote that would not be used

When attempting to add a .git to my tool's repository, git seems to ignore it and indicates that there are no differences in the status and commit

How can I add the .git directory to my project repository ? Something like tests/.git


Solution

  • You can't do that. It's inherently forbidden by Git.

    You can store a tar or ZIP archive that contains the repository, and then have your test routine extract it to a temporary location. If you go that route, I recommend to use an uncompressed archive format, because it allows Git's own compression algorithms to work more efficient.