Commit 7658eb3c authored by chase@chromium.org's avatar chase@chromium.org

Alter hooks to call into depot_tools lib.

This new method allows us to install pre-cl-upload
and pre-cl-dcommit hook files which should rarely need
to be updated (with luck).  These hooks load the real
hooks lib from depot_tools which takes over execution
of the presubmit tests.

BUG=5339
TEST=hooks are run by git cl upload/dcommit and behave
as expected
Review URL: http://codereview.chromium.org/243118

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@28409 0039d316-1c4b-4281-b951-d872f2087c98
parent 7753d246
......@@ -4,8 +4,6 @@
# found in the LICENSE file.
import os
import re
import subprocess
import sys
# Find depot_tools in PATH, append it to sys.path so we can import.
......@@ -16,60 +14,12 @@ for path in paths.split(':'):
sys.path.append(path)
break
import gclient_scm
import presubmit_support
def Backquote(cmd, cwd=None):
"""Like running `cmd` in a shell script."""
return subprocess.Popen(cmd,
cwd=cwd,
stdout=subprocess.PIPE).communicate()[0].strip()
class ChangeOptions:
def __init__(self, commit=None, upstream_branch=None):
self.commit = commit
self.verbose = None
self.default_presubmit = None
self.may_prompt = None
root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup']))
if not root:
raise Exception("Could not get root directory.")
log = Backquote(['git', 'show', '--name-only',
'--pretty=format:%H%n%s%n%n%b'])
m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL)
if not m:
raise Exception("Could not parse log message: %s" % log)
name = m.group(1)
description = m.group(2)
files = gclient_scm.CaptureGitStatus([root], upstream_branch)
issue = Backquote(['git', 'cl', 'status', '--field=id'])
patchset = None
self.change = presubmit_support.GitChange(name, description, root, files,
issue, patchset)
import git_cl_hooks
# Ensure we were called with the necessary number of arguments.
program_name = os.path.basename(sys.argv[0])
if len(sys.argv) < 2:
if len(sys.argv) != 2:
raise Exception("usage: %s [upstream branch]" % program_name)
# Get arguments from how we were called.
commit = (program_name == 'pre-cl-dcommit')
upstream_branch = sys.argv[1]
# Create our options based on the command-line args and the current checkout.
options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
# Run the presubmit checks.
if presubmit_support.DoPresubmitChecks(options.change,
options.commit,
options.verbose,
sys.stdout,
sys.stdin,
options.default_presubmit,
options.may_prompt):
sys.exit(0)
else:
sys.exit(1)
# Run the hooks library with our arguments.
exec git_cl_hooks.RunHooks(hook_name=program_name, upstream_branch=sys.argv[1])
# Copyright (c) 2009 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import re
import subprocess
import sys
# Imported from depot_tools.
import gclient_scm
import presubmit_support
def Backquote(cmd, cwd=None):
"""Like running `cmd` in a shell script."""
return subprocess.Popen(cmd,
cwd=cwd,
stdout=subprocess.PIPE).communicate()[0].strip()
class ChangeOptions:
def __init__(self, commit=None, upstream_branch=None):
self.commit = commit
self.verbose = None
self.default_presubmit = None
self.may_prompt = None
root = os.path.abspath(Backquote(['git', 'rev-parse', '--show-cdup']))
if not root:
raise Exception("Could not get root directory.")
log = Backquote(['git', 'show', '--name-only',
'--pretty=format:%H%n%s%n%n%b'])
m = re.match(r'^(\w+)\n(.*)$', log, re.MULTILINE|re.DOTALL)
if not m:
raise Exception("Could not parse log message: %s" % log)
name = m.group(1)
description = m.group(2)
files = gclient_scm.CaptureGitStatus([root], upstream_branch)
issue = Backquote(['git', 'cl', 'status', '--field=id'])
patchset = None
self.change = presubmit_support.GitChange(name, description, root, files,
issue, patchset)
def RunHooks(hook_name, upstream_branch):
commit = (hook_name == 'pre-cl-dcommit')
# Create our options based on the command-line args and the current checkout.
options = ChangeOptions(commit=commit, upstream_branch=upstream_branch)
# Run the presubmit checks.
if presubmit_support.DoPresubmitChecks(options.change,
options.commit,
options.verbose,
sys.stdout,
sys.stdin,
options.default_presubmit,
options.may_prompt):
sys.exit(0)
else:
sys.exit(1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment