import_patches_applied_tree: use correct quilt env
When quilt runs, we must use GitUbuntuRepository:quilt_env in order to
make sure that QUILT_* environment variables are set correctly.
Otherwise we rely on the importer runner having the correct quilt
environment set, which may not be the case.
Also see LP 1734137: separately we need to ensure that any /etc/quiltrc
or ~/.quiltrc is ignored correctly, but I'm treating that as a separate
bug as it needs a more significant refactor to wrap all quilt calls. We
should fix that bug before declaring hash stability, but it isn't as
important as this fix as that one is less likely to be a problem in
practice on our production importer.
Take a treeish instead of a commit hash hex string and provide a wrapper
for old callers.
This is one step towards a move to using pure objects in most
parameters.
It's needed now so that the importer can also use quilt_env providing
only a treeish object. I could also have changed the method definition
to something intermediary, but as this is the eventual goal anyway,
might as well do it now.
It looks like this was an accidental regression in commit 0f3c9430.
'version' refers to the last set version in the for loop above, instead
of 'spi.version' which is the current package being imported.
'version' thus referred to the previously found tag, which of course
always exists. The code therefore assumed that the current version
doesn't need importing since the tag already exists, which is wrong.
Unfortunately this area of code doesn't have effective test coverage yet
and it isn't practical to add it here yet. My importer testing spike
will separately have to refactor and cover this. In the meantime a fix
without a test will have to do.
If a source package unpacks to contain any files or directories named
'.git', it cannot be represented in a git repository as-is because the
name '.git' is reserved by git and git will not permit it to be an entry
in a git tree object.
Instead we losslessly escape these names by prepending a '.' recursively.
Instead of raising an exception immediately if lp_user cannot be
determined at instantiation time of GitUbuntuRepository, proceed with
_lp_user set to None.
The associated lp_user attribute getter will raise a RuntimeError if
_lp_user isn't set.
Other methods that use lp_user will check _lp_user first and raise a
more specific RuntimeError if _lp_user isn't set.
We can have confidence that this doesn't introduce a regression since
there should not be any code path which could proceed before without
successfully instantiating a GitUbuntuRepository. All this change does
is defer that exception (that must not have been happening in successful
use cases previously).
This allows for easier testability since we can now instantiate a
GitUbuntuRepository in tests without having to make sure that lp_user is
set first.