Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(680)

Unified Diff: recipe_engine/package.py

Issue 1849903002: Perform Git operations without changing CWD. (Closed) Base URL: https://github.com/luci/recipes-py@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | unittests/package_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_engine/package.py
diff --git a/recipe_engine/package.py b/recipe_engine/package.py
index 57f279070e0a20621d11a7d1a1da650df2b24542..9d5d6287a794333920a867b2db8914585505dc65 100644
--- a/recipe_engine/package.py
+++ b/recipe_engine/package.py
@@ -196,6 +196,9 @@ class GitRepoSpec(RepoSpec):
'branch="%(branch)s", revision="%(revision)s", '
'path="%(path)s"}' % self.__dict__)
+ def run_git(self, cwd, *args):
+ _run_cmd([self._git, '--git-dir', os.path.join(cwd, '.git')] + list(args))
+
def checkout(self, context):
dep_dir = self._dep_dir(context)
logging.info('Freshening repository %s' % dep_dir)
@@ -206,11 +209,11 @@ class GitRepoSpec(RepoSpec):
raise UncleanFilesystemError('%s exists but is not a git repo' % dep_dir)
try:
- subprocess.check_output([self._git, 'rev-parse', '-q', '--verify',
- '%s^{commit}' % self.revision], cwd=dep_dir)
+ self.run_git(dep_dir, 'rev-parse', '-q', '--verify',
+ '%s^{commit}' % self.revision)
except subprocess.CalledProcessError:
- _run_cmd([self._git, 'fetch'], cwd=dep_dir)
- _run_cmd([self._git, 'reset', '-q', '--hard', self.revision], cwd=dep_dir)
+ self.run_git(dep_dir, 'fetch')
+ self.run_git(dep_dir, 'reset', '-q', '--hard', self.revision)
def check_checkout(self, context):
dep_dir = self._dep_dir(context)
@@ -259,7 +262,7 @@ class GitRepoSpec(RepoSpec):
def _raw_updates(self, context, subdir):
self.checkout(context)
- _run_cmd([self._git, 'fetch'], cwd=self._dep_dir(context))
+ self.run_git(self._dep_dir(context), fetch)
Paweł Hajdan Jr. 2016/03/31 17:35:37 Shouldn't fetch be changed to 'fetch'? Just checki
dnj 2016/03/31 17:47:50 Done.
args = [self._git, 'rev-list', '--reverse',
'%s..origin/%s' % (self.revision, self.branch)]
if subdir:
« no previous file with comments | « no previous file | unittests/package_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698