Since it is common to take a GitUbuntuRepository instance env property
and then adjust it, make sure that modifying the dictionary returned
from the property getter does not modify the dictionary owned by the
instance itself. This adds some robustness against this common use
pattern.
Instead of using the GitUbuntuRepository.git_run method, use the top
level one instead.
This reduces dependency on the state of the GitUbuntuRepository class
instance with the goal of making this method into a classmethod.
This change should result in no functional changes. It does change the
resulting git call from using --work-tree to setting GIT_WORKTREE
instead. However this should not change git's behaviour, and we already
have tests for this method to help ensure this.
Instead of having two separate implementations, have the
GitUbuntuRepository.git_run method use the top level git_run function
for its implementation.
This should not introduce any functional changes.
The only differences now between the method and the function are:
1. The caller doesn't have to look up the underlying pygit2.Repository
on the GitUbuntuRepository directly, so it's a useful shortcut.
2. To preserve existing behaviour that currently doesn't have tests,
the method uses an initial environment identical to the process
environment at the time of construction of the GitUbuntuRepository
instance, instead of the environment at the time of the functional
call. This is intentionally left for a future change to simplify
things after we have better test coverage.
As part of the drive to reduce stored state to improve testability,
derive self.env when we need it instead of working out in advance in the
constructor.
This is intended to have no functional changes.
GIT_WORK_TREE will end up differently normalised now, such as in
trailing slashes, since in testing pygit2.Repository.workdir was not
normalised like this and so a normalised assertion was needed. This
should not result in any change to git's behaviour.