summaryrefslogtreecommitdiff
path: root/Tools/Scripts/webkitpy/common/checkout/scm/git.py
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Scripts/webkitpy/common/checkout/scm/git.py')
-rw-r--r--Tools/Scripts/webkitpy/common/checkout/scm/git.py90
1 files changed, 46 insertions, 44 deletions
diff --git a/Tools/Scripts/webkitpy/common/checkout/scm/git.py b/Tools/Scripts/webkitpy/common/checkout/scm/git.py
index 43fdb9c00..802d81db0 100644
--- a/Tools/Scripts/webkitpy/common/checkout/scm/git.py
+++ b/Tools/Scripts/webkitpy/common/checkout/scm/git.py
@@ -61,6 +61,8 @@ class Git(SCM, SVNRepository):
# 1 or 128, mostly.
ERROR_FILE_IS_MISSING = 128
+ executable_name = 'git'
+
def __init__(self, cwd, **kwargs):
SCM.__init__(self, cwd, **kwargs)
self._check_git_architecture()
@@ -89,7 +91,7 @@ class Git(SCM, SVNRepository):
# We could path-search entirely in python or with
# which.py (http://code.google.com/p/which), but this is easier:
- git_path = self.run(['which', 'git']).rstrip()
+ git_path = self.run(['which', self.executable_name]).rstrip()
if self._executable_is_64bit(git_path):
return
@@ -100,14 +102,14 @@ class Git(SCM, SVNRepository):
def in_working_directory(cls, path):
try:
# FIXME: This should use an Executive.
- return run_command(['git', 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
+ return run_command([cls.executable_name, 'rev-parse', '--is-inside-work-tree'], cwd=path, error_handler=Executive.ignore_error).rstrip() == "true"
except OSError, e:
# The Windows bots seem to through a WindowsError when git isn't installed.
return False
def find_checkout_root(self, path):
# "git rev-parse --show-cdup" would be another way to get to the root
- git_output = self._executive.run_command(['git', 'rev-parse', '--git-dir'], cwd=(path or "./"))
+ git_output = self._executive.run_command([self.executable_name, 'rev-parse', '--git-dir'], cwd=(path or "./"))
(checkout_root, dot_git) = self._filesystem.split(git_output)
if not self._filesystem.isabs(checkout_root): # Sometimes git returns relative paths
checkout_root = self._filesystem.join(path, checkout_root)
@@ -125,7 +127,7 @@ class Git(SCM, SVNRepository):
# Pass --get-all for cases where the config has multiple values
# Pass the cwd if provided so that we can handle the case of running webkit-patch outside of the working directory.
# FIXME: This should use an Executive.
- return run_command(["git", "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
+ return run_command([cls.executable_name, "config", "--get-all", key], error_handler=Executive.ignore_error, cwd=cwd).rstrip('\n')
@staticmethod
def commit_success_regexp():
@@ -133,48 +135,48 @@ class Git(SCM, SVNRepository):
def discard_local_commits(self):
# FIXME: This should probably use cwd=self.checkout_root
- self.run(['git', 'reset', '--hard', self.remote_branch_ref()])
+ self.run([self.executable_name, 'reset', '--hard', self.remote_branch_ref()])
def local_commits(self):
- return self.run(['git', 'log', '--pretty=oneline', 'HEAD...' + self.remote_branch_ref()], cwd=self.checkout_root).splitlines()
+ return self.run([self.executable_name, 'log', '--pretty=oneline', 'HEAD...' + self.remote_branch_ref()], cwd=self.checkout_root).splitlines()
def rebase_in_progress(self):
return self._filesystem.exists(self.absolute_path(self._filesystem.join('.git', 'rebase-apply')))
def working_directory_is_clean(self):
- return self.run(['git', 'diff', 'HEAD', '--no-renames', '--name-only'], cwd=self.checkout_root) == ""
+ return self.run([self.executable_name, 'diff', 'HEAD', '--no-renames', '--name-only'], cwd=self.checkout_root) == ""
def clean_working_directory(self):
# FIXME: These should probably use cwd=self.checkout_root.
# Could run git clean here too, but that wouldn't match working_directory_is_clean
- self.run(['git', 'reset', '--hard', 'HEAD'])
+ self.run([self.executable_name, 'reset', '--hard', 'HEAD'])
# Aborting rebase even though this does not match working_directory_is_clean
if self.rebase_in_progress():
- self.run(['git', 'rebase', '--abort'])
+ self.run([self.executable_name, 'rebase', '--abort'])
def status_command(self):
# git status returns non-zero when there are changes, so we use git diff name --name-status HEAD instead.
# No file contents printed, thus utf-8 autodecoding in self.run is fine.
- return ["git", "diff", "--name-status", "--no-renames", "HEAD"]
+ return [self.executable_name, "diff", "--name-status", "--no-renames", "HEAD"]
def _status_regexp(self, expected_types):
return '^(?P<status>[%s])\t(?P<filename>.+)$' % expected_types
def add_list(self, paths, return_exit_code=False):
- return self.run(["git", "add"] + paths, return_exit_code=return_exit_code)
+ return self.run([self.executable_name, "add"] + paths, return_exit_code=return_exit_code)
def delete_list(self, paths):
- return self.run(["git", "rm", "-f"] + paths)
+ return self.run([self.executable_name, "rm", "-f"] + paths)
def exists(self, path):
- return_code = self.run(["git", "show", "HEAD:%s" % path], return_exit_code=True, decode_output=False)
+ return_code = self.run([self.executable_name, "show", "HEAD:%s" % path], return_exit_code=True, decode_output=False)
return return_code != self.ERROR_FILE_IS_MISSING
def _branch_from_ref(self, ref):
return ref.replace('refs/heads/', '')
def _current_branch(self):
- return self._branch_from_ref(self.run(['git', 'symbolic-ref', '-q', 'HEAD'], cwd=self.checkout_root).strip())
+ return self._branch_from_ref(self.run([self.executable_name, 'symbolic-ref', '-q', 'HEAD'], cwd=self.checkout_root).strip())
def _upstream_branch(self):
current_branch = self._current_branch()
@@ -201,14 +203,14 @@ class Git(SCM, SVNRepository):
def changed_files(self, git_commit=None):
# FIXME: --diff-filter could be used to avoid the "extract_filenames" step.
- status_command = ['git', 'diff', '-r', '--name-status', "--no-renames", "--no-ext-diff", "--full-index", self.merge_base(git_commit)]
+ status_command = [self.executable_name, 'diff', '-r', '--name-status', "--no-renames", "--no-ext-diff", "--full-index", self.merge_base(git_commit)]
# FIXME: I'm not sure we're returning the same set of files that SVN.changed_files is.
# Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R)
return self.run_status_and_extract_filenames(status_command, self._status_regexp("ADM"))
def _changes_files_for_commit(self, git_commit):
# --pretty="format:" makes git show not print the commit log header,
- changed_files = self.run(["git", "show", "--pretty=format:", "--name-only", git_commit]).splitlines()
+ changed_files = self.run([self.executable_name, "show", "--pretty=format:", "--name-only", git_commit]).splitlines()
# instead it just prints a blank line at the top, so we skip the blank line:
return changed_files[1:]
@@ -222,13 +224,13 @@ class Git(SCM, SVNRepository):
raise ScriptError(message="Path %s does not exist." % path)
# git rev-list head --remove-empty --limit=5 -- path would be equivalent.
- commit_ids = self.run(["git", "log", "--remove-empty", "--pretty=format:%H", "-%s" % limit, "--", path]).splitlines()
+ commit_ids = self.run([self.executable_name, "log", "--remove-empty", "--pretty=format:%H", "-%s" % limit, "--", path]).splitlines()
return filter(lambda revision: revision, map(self.svn_revision_from_git_commit, commit_ids))
def conflicted_files(self):
# We do not need to pass decode_output for this diff command
# as we're passing --name-status which does not output any data.
- status_command = ['git', 'diff', '--name-status', '--no-renames', '--diff-filter=U']
+ status_command = [self.executable_name, 'diff', '--name-status', '--no-renames', '--diff-filter=U']
return self.run_status_and_extract_filenames(status_command, self._status_regexp("U"))
def added_files(self):
@@ -246,7 +248,7 @@ class Git(SCM, SVNRepository):
def svn_revision(self, path):
_log.debug('Running git.head_svn_revision... (Temporary logging message)')
- git_log = self.run(['git', 'log', '-25', path])
+ git_log = self.run([self.executable_name, 'log', '-25', path])
match = re.search("^\s*git-svn-id:.*@(?P<svn_revision>\d+)\ ", git_log, re.MULTILINE)
if not match:
return ""
@@ -272,14 +274,14 @@ class Git(SCM, SVNRepository):
if self._filesystem.exists(order_file):
order = "-O%s" % order_file
- command = ['git', 'diff', '--binary', "--no-ext-diff", "--full-index", "--no-renames", order, self.merge_base(git_commit), "--"]
+ command = [self.executable_name, 'diff', '--binary', "--no-ext-diff", "--full-index", "--no-renames", order, self.merge_base(git_commit), "--"]
if changed_files:
command += changed_files
return self.prepend_svn_revision(self.run(command, decode_output=False, cwd=self.checkout_root))
def _run_git_svn_find_rev(self, arg):
# git svn find-rev always exits 0, even when the revision or commit is not found.
- return self.run(['git', 'svn', 'find-rev', arg], cwd=self.checkout_root).rstrip()
+ return self.run([self.executable_name, 'svn', 'find-rev', arg], cwd=self.checkout_root).rstrip()
def _string_to_int_or_none(self, string):
try:
@@ -303,21 +305,21 @@ class Git(SCM, SVNRepository):
def contents_at_revision(self, path, revision):
"""Returns a byte array (str()) containing the contents
of path @ revision in the repository."""
- return self.run(["git", "show", "%s:%s" % (self.git_commit_from_svn_revision(revision), path)], decode_output=False)
+ return self.run([self.executable_name, "show", "%s:%s" % (self.git_commit_from_svn_revision(revision), path)], decode_output=False)
def diff_for_revision(self, revision):
git_commit = self.git_commit_from_svn_revision(revision)
return self.create_patch(git_commit)
def diff_for_file(self, path, log=None):
- return self.run(['git', 'diff', 'HEAD', '--no-renames', '--', path], cwd=self.checkout_root)
+ return self.run([self.executable_name, 'diff', 'HEAD', '--no-renames', '--', path], cwd=self.checkout_root)
def show_head(self, path):
- return self.run(['git', 'show', 'HEAD:' + self.to_object_name(path)], decode_output=False)
+ return self.run([self.executable_name, 'show', 'HEAD:' + self.to_object_name(path)], decode_output=False)
def committer_email_for_revision(self, revision):
git_commit = self.git_commit_from_svn_revision(revision)
- committer_email = self.run(["git", "log", "-1", "--pretty=format:%ce", git_commit])
+ committer_email = self.run([self.executable_name, "log", "-1", "--pretty=format:%ce", git_commit])
# Git adds an extra @repository_hash to the end of every committer email, remove it:
return committer_email.rsplit("@", 1)[0]
@@ -325,10 +327,10 @@ class Git(SCM, SVNRepository):
# Assume the revision is an svn revision.
git_commit = self.git_commit_from_svn_revision(revision)
# I think this will always fail due to ChangeLogs.
- self.run(['git', 'revert', '--no-commit', git_commit], error_handler=Executive.ignore_error)
+ self.run([self.executable_name, 'revert', '--no-commit', git_commit], error_handler=Executive.ignore_error)
def revert_files(self, file_paths):
- self.run(['git', 'checkout', 'HEAD'] + file_paths)
+ self.run([self.executable_name, 'checkout', 'HEAD'] + file_paths)
def _assert_can_squash(self, working_directory_is_clean):
squash = Git.read_git_config('webkit-patch.commit-should-always-squash', cwd=self.checkout_root)
@@ -362,7 +364,7 @@ class Git(SCM, SVNRepository):
if not force_squash:
self._assert_can_squash(working_directory_is_clean)
- self.run(['git', 'reset', '--soft', self.remote_merge_base()], cwd=self.checkout_root)
+ self.run([self.executable_name, 'reset', '--soft', self.remote_merge_base()], cwd=self.checkout_root)
self.commit_locally_with_message(message)
return self.push_local_commits_to_server(username=username, password=password)
@@ -385,16 +387,16 @@ class Git(SCM, SVNRepository):
# We wrap in a try...finally block so if anything goes wrong, we clean up the branches.
commit_succeeded = True
try:
- self.run(['git', 'checkout', '-q', '-b', MERGE_BRANCH_NAME, self.remote_branch_ref()])
+ self.run([self.executable_name, 'checkout', '-q', '-b', MERGE_BRANCH_NAME, self.remote_branch_ref()])
for commit in commit_ids:
# We're on a different branch now, so convert "head" to the branch name.
commit = re.sub(r'(?i)head', branch_name, commit)
# FIXME: Once changed_files and create_patch are modified to separately handle each
# commit in a commit range, commit each cherry pick so they'll get dcommitted separately.
- self.run(['git', 'cherry-pick', '--no-commit', commit])
+ self.run([self.executable_name, 'cherry-pick', '--no-commit', commit])
- self.run(['git', 'commit', '-m', message])
+ self.run([self.executable_name, 'commit', '-m', message])
output = self.push_local_commits_to_server(username=username, password=password)
except Exception, e:
log("COMMIT FAILED: " + str(e))
@@ -403,31 +405,31 @@ class Git(SCM, SVNRepository):
finally:
# And then swap back to the original branch and clean up.
self.clean_working_directory()
- self.run(['git', 'checkout', '-q', branch_name])
+ self.run([self.executable_name, 'checkout', '-q', branch_name])
self.delete_branch(MERGE_BRANCH_NAME)
return output
def svn_commit_log(self, svn_revision):
svn_revision = self.strip_r_from_svn_revision(svn_revision)
- return self.run(['git', 'svn', 'log', '-r', svn_revision])
+ return self.run([self.executable_name, 'svn', 'log', '-r', svn_revision])
def last_svn_commit_log(self):
- return self.run(['git', 'svn', 'log', '--limit=1'])
+ return self.run([self.executable_name, 'svn', 'log', '--limit=1'])
def svn_blame(self, path):
- return self.run(['git', 'svn', 'blame', path])
+ return self.run([self.executable_name, 'svn', 'blame', path])
# Git-specific methods:
def _branch_ref_exists(self, branch_ref):
- return self.run(['git', 'show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0
+ return self.run([self.executable_name, 'show-ref', '--quiet', '--verify', branch_ref], return_exit_code=True) == 0
def delete_branch(self, branch_name):
if self._branch_ref_exists('refs/heads/' + branch_name):
- self.run(['git', 'branch', '-D', branch_name])
+ self.run([self.executable_name, 'branch', '-D', branch_name])
def remote_merge_base(self):
- return self.run(['git', 'merge-base', self.remote_branch_ref(), 'HEAD'], cwd=self.checkout_root).strip()
+ return self.run([self.executable_name, 'merge-base', self.remote_branch_ref(), 'HEAD'], cwd=self.checkout_root).strip()
def remote_branch_ref(self):
# Use references so that we can avoid collisions, e.g. we don't want to operate on refs/heads/trunk if it exists.
@@ -444,10 +446,10 @@ class Git(SCM, SVNRepository):
return first_remote_branch_ref.split(':')[1]
def commit_locally_with_message(self, message):
- self.run(['git', 'commit', '--all', '-F', '-'], input=message, cwd=self.checkout_root)
+ self.run([self.executable_name, 'commit', '--all', '-F', '-'], input=message, cwd=self.checkout_root)
def push_local_commits_to_server(self, username=None, password=None):
- dcommit_command = ['git', 'svn', 'dcommit']
+ dcommit_command = [self.executable_name, 'svn', 'dcommit']
if (not username or not password) and not self.has_authorization_for_realm(SVN.svn_server_realm):
raise AuthenticationError(SVN.svn_server_host, prompt_for_password=True)
if username:
@@ -469,14 +471,14 @@ class Git(SCM, SVNRepository):
if '...' in commitish:
raise ScriptError(message="'...' is not supported (found in '%s'). Did you mean '..'?" % commitish)
elif '..' in commitish:
- commit_ids += reversed(self.run(['git', 'rev-list', commitish]).splitlines())
+ commit_ids += reversed(self.run([self.executable_name, 'rev-list', commitish]).splitlines())
else:
# Turn single commits or branch or tag names into commit ids.
- commit_ids += self.run(['git', 'rev-parse', '--revs-only', commitish]).splitlines()
+ commit_ids += self.run([self.executable_name, 'rev-parse', '--revs-only', commitish]).splitlines()
return commit_ids
def commit_message_for_local_commit(self, commit_id):
- commit_lines = self.run(['git', 'cat-file', 'commit', commit_id]).splitlines()
+ commit_lines = self.run([self.executable_name, 'cat-file', 'commit', commit_id]).splitlines()
# Skip the git headers.
first_line_after_headers = 0
@@ -487,4 +489,4 @@ class Git(SCM, SVNRepository):
return CommitMessage(commit_lines[first_line_after_headers:])
def files_changed_summary_for_commit(self, commit_id):
- return self.run(['git', 'diff-tree', '--shortstat', '--no-renames', '--no-commit-id', commit_id])
+ return self.run([self.executable_name, 'diff-tree', '--shortstat', '--no-renames', '--no-commit-id', commit_id])