Merge ~racb/git-ubuntu:derive-env into git-ubuntu:master

Proposed by Robie Basak
Status: Superseded
Proposed branch: ~racb/git-ubuntu:derive-env
Merge into: git-ubuntu:master
Diff against target: 80 lines (+37/-10)
1 file modified
gitubuntu/git_repository.py (+37/-10)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
git-ubuntu developers Pending
Review via email: mp+337269@code.launchpad.net

This proposal has been superseded by a proposal from 2018-02-12.

Commit message

Make Jenkins happy

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:a71ff92849ae06203ce7c2c5d7bdce355f042560
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/279/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/279/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:4d1d2bdb1d514bcf5bf0ac3e736bf88ff372dbca
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/281/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Style Check
    SUCCESS: Unit Tests
    SUCCESS: Integration Tests
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/git-ubuntu-ci/281/rebuild

review: Approve (continuous-integration)

Unmerged commits

4d1d2bd... by Robie Basak

Replace self._env with a derived property

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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/gitubuntu/git_repository.py b/gitubuntu/git_repository.py
index f3bd406..d2768f8 100644
--- a/gitubuntu/git_repository.py
+++ b/gitubuntu/git_repository.py
@@ -779,10 +779,24 @@ class GitUbuntuRepository:
779 self._local_dir = local_dir779 self._local_dir = local_dir
780780
781 self.raw_repo = pygit2.init_repository(self._local_dir)781 self.raw_repo = pygit2.init_repository(self._local_dir)
782 # We rely on raw_repo.workdir to be identical to self._local_dir to
783 # avoid changing previous behaviour in the setting of GIT_WORK_TREE, so
784 # assert that it is so. This may not be the case if the git repository
785 # has a different workdir stored in its configuration or if the git
786 # repository is a bare repository. We didn't handle these cases before
787 # anyway, so with this assertion we can fail noisily and early.
788 assert (
789 os.path.normpath(self.raw_repo.workdir) ==
790 os.path.normpath(self._local_dir)
791 )
782792
783 self._env = os.environ.copy()793 # Since previous behaviour of this class depended on the state of the
784 self._env['GIT_DIR'] = self.raw_repo.path794 # environment at the time it was constructed, save this for later use
785 self._env['GIT_WORK_TREE'] = self._local_dir795 # (for example in deriving the environment to use for calls to the git
796 # CLI). This permits the behaviour to remain identical for now.
797 # Eventually we can break previous behaviour and eliminate the need for
798 # this.
799 self._initial_env = os.environ.copy()
786800
787 self.set_git_attributes()801 self.set_git_attributes()
788802
@@ -1224,7 +1238,20 @@ class GitUbuntuRepository:
12241238
1225 @property1239 @property
1226 def env(self):1240 def env(self):
1227 return self._env1241 return self._derive_env()
1242
1243 @lru_cache()
1244 def _derive_env(self):
1245 """Determine what the git CLI environment should be
1246
1247 This depends on the initial environment saved from the constructor and
1248 the paths associated with self.raw_repo, neither of which should change
1249 in the lifetime of this class instance.
1250 """
1251 env = self._initial_env.copy()
1252 env['GIT_DIR'] = self.raw_repo.path
1253 env['GIT_WORK_TREE'] = self.raw_repo.workdir
1254 return env
12281255
1229 @property1256 @property
1230 def local_dir(self):1257 def local_dir(self):
@@ -1308,9 +1335,9 @@ class GitUbuntuRepository:
1308 return stdout.strip()1335 return stdout.strip()
13091336
1310 def git_run(self, args, env=None, **kwargs):1337 def git_run(self, args, env=None, **kwargs):
1311 # Explicitly take a copy of self._env so the following update doesn't1338 # Explicitly take a copy of self.env so the following update doesn't
1312 # accidentally update the main instance _env dictionary in-place1339 # accidentally update the main instance env dictionary in-place
1313 combined_env = dict(self._env)1340 combined_env = dict(self.env)
1314 if env is not None:1341 if env is not None:
1315 combined_env.update(env)1342 combined_env.update(env)
1316 return run(['git'] + args, env=combined_env, **kwargs)1343 return run(['git'] + args, env=combined_env, **kwargs)
@@ -1626,9 +1653,9 @@ class GitUbuntuRepository:
1626 def clean_repository_state(self):1653 def clean_repository_state(self):
1627 """Cleanup working tree"""1654 """Cleanup working tree"""
1628 runq(['git', 'checkout', '--orphan', 'master'],1655 runq(['git', 'checkout', '--orphan', 'master'],
1629 check=False, env=self._env)1656 check=False, env=self.env)
1630 runq(['git', 'reset', '--hard'], env=self._env)1657 runq(['git', 'reset', '--hard'], env=self.env)
1631 runq(['git', 'clean', '-f', '-d'], env=self._env)1658 runq(['git', 'clean', '-f', '-d'], env=self.env)
16321659
1633 def get_all_changelog_versions_from_treeish(self, treeish):1660 def get_all_changelog_versions_from_treeish(self, treeish):
1634 changelog = self.get_changelog_from_treeish(treeish)1661 changelog = self.get_changelog_from_treeish(treeish)

Subscribers

People subscribed via source and target branches