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

Unified Diff: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py

Issue 2663623003: Simplify the initialization of Git objects in Host. (Closed)
Patch Set: Created 3 years, 11 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
Index: third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py
diff --git a/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py b/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py
index 442173fb86d31016846e588b3f92eaaf9ec7738b..e3b6a7051dae4fd05ab379a1e4ad5a727b7c6785 100644
--- a/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py
+++ b/third_party/WebKit/Tools/Scripts/webkitpy/common/checkout/scm/git.py
@@ -48,12 +48,45 @@ class Git(object):
executable_name = 'git'
- def __init__(self, cwd, executive=None, filesystem=None):
- self.cwd = cwd
+ def __init__(self, cwd=None, executive=None, filesystem=None):
self._executive = executive or Executive()
self._filesystem = filesystem or FileSystem()
+
+ self.cwd = cwd or self._filesystem.abspath(self._filesystem.getcwd())
+ if not Git.in_working_directory(self.cwd, executive=self._executive):
+ module_directory = self._filesystem.abspath(
+ self._filesystem.dirname(self._filesystem.path_to_module(self.__module__)))
+ _log.info('The current directory (%s) is not in a git repo, trying directory %s.',
+ cwd, module_directory)
+ if Git.in_working_directory(module_directory, executive=self._executive):
+ self.cwd = module_directory
+ _log.error('Failed to find Git repo for %s or %s', cwd, module_directory)
+
+ self._init_executable_name()
self.checkout_root = self.find_checkout_root(self.cwd)
+ def _init_executable_name(self):
+ # FIXME: This is a hack and should be removed.
+ try:
+ self._executive.run_command(['git', 'help'])
+ except OSError:
+ try:
+ self._executive.run_command(['git.bat', 'help'])
+ # The Win port uses the depot_tools package, which contains a number
+ # of development tools, including Python and git. Instead of using a
+ # real git executable, depot_tools indirects via a batch file, called
+ # git.bat. This batch file allows depot_tools to auto-update the real
+ # git executable, which is contained in a subdirectory.
+ #
+ # That's all fine and good, except that subprocess.popen can detect
+ # the difference between a real git executable and batch file when we
+ # don't provide use shell=True. Rather than use shell=True on Windows,
+ # We hack the git.bat name into the SVN class.
jeffcarp 2017/01/31 22:24:56 The 'SVN class' reference is no longer accurate (w
qyearsley 2017/02/01 00:58:47 Gah, I'm not sure, I think it might originally hav
+ _log.debug('Engaging git.bat Windows hack.')
+ self.executable_name = 'git.bat'
+ except OSError:
+ _log.debug('Failed to engage git.bat Windows hack.')
+
def _run_git(self,
command_args,
cwd=None,

Powered by Google App Engine
This is Rietveld 408576698