robertdfrench / git-pr

Pull requests without Git(Hub|Lab)
GNU General Public License v3.0
0 stars 1 forks source link

Create a git repo for each test #48

Closed robertdfrench closed 3 years ago

robertdfrench commented 3 years ago

This is a proof of concept for re-introducing the tempdir package and using it to create a git repository for each test. By adding a working_dir field to the Git client wrapper, it can run all of its git commands with the -C flag, as in:

git -C /tmp/dir/git-pr-test-12345 branch -va

According to GIT(1), the -C <DIR> option instructs git to run as though it had been launched from DIR, even if DIR is not the current working directory of the parent process. Given that we cannot change the working directory of cargo test (since it runs tests as threads of a single process, and the notion of a "working directory" is a process-level property), this should give us exactly what we want.

Caveat. The temporary repositories do not seem to actually get deleted on my mac. The TempDir docs seem to anticipate this:

Various platform-specific conditions may cause TempDir to fail to delete the underlying directory.

So, perhaps this is all for naught. 🤷

robertdfrench commented 3 years ago

@calebwherry this now "works", in the sense that every Git object has a TempDir member which will have the opportunity to attempt cleanup when the Git object goes out of scope. However, there are some refactoring opportunities: