git-repo/subcmds
Doug Anderson 37282b4b9c Support repo-level pre-upload hook and prep for future hooks.
All repo-level hooks are expected to live in a single project at the
top level of that project.  The name of the hooks project is provided
in the manifest.xml.  The manifest also lists which hooks are enabled
to make it obvious if a file somehow failed to sync down (or got
deleted).

Before running any hook, we will prompt the user to make sure that it
is OK.  A user can deny running the hook, allow once, or allow
"forever" (until hooks change).  This tries to keep with the git
spirit of not automatically running anything on the user's computer
that got synced down.  Note that individual repo commands can add
always options to avoid these prompts as they see fit (see below for
the 'upload' options).

When hooks are run, they are loaded into the current interpreter (the
one running repo) and their main() function is run.  This mechanism is
used (instead of using subprocess) to make it easier to expand to a
richer hook interface in the future.  During loading, the
interpreter's sys.path is updated to contain the directory containing
the hooks so that hooks can be split into multiple files.

The upload command has two options that control hook behavior:
  - no-verify=False, verify=False (DEFAULT):
    If stdout is a tty, can prompt about running upload hooks if needed.
    If user denies running hooks, the upload is cancelled.  If stdout is
    not a tty and we would need to prompt about upload hooks, upload is
    cancelled.
  - no-verify=False, verify=True:
    Always run upload hooks with no prompt.
  - no-verify=True, verify=False:
    Never run upload hooks, but upload anyway (AKA bypass hooks).
  - no-verify=True, verify=True:
    Invalid

Sample bit of manifest.xml code for enabling hooks (assumes you have a
project named 'hooks' where hooks are stored):
  <repo-hooks in-project="hooks" enabled-list="pre-upload" />

Sample main() function in pre-upload.py in hooks directory:
  def main(project_list, **kwargs):
    print ('These projects will be uploaded: %s' %
           ', '.join(project_list))
    print ('I am being a good boy and ignoring anything in kwargs\n'
           'that I don\'t understand.')
    print 'I fail 50% of the time.  How flaky.'
    if random.random() <= .5:
      raise Exception('Pre-upload hook failed.  Have a nice day.')

Change-Id: I5cefa2cd5865c72589263cf8e2f152a43c122f70
2011-03-11 11:53:23 -08:00
..
__init__.py Initial Contribution 2008-10-21 07:00:00 -07:00
abandon.py Modify 'repo abandon' to be more like 'repo checkout' and 'repo start' 2009-04-18 15:15:24 -07:00
branches.py branches: Enable output of multiple projects 2010-05-04 07:51:28 -07:00
checkout.py Improve checkout performance for the common unmodified case 2009-04-18 15:04:41 -07:00
diff.py Initial Contribution 2008-10-21 07:00:00 -07:00
download.py Fix to display the usage message of the command download when the user 2011-01-09 17:39:22 -08:00
forall.py forall: Silently skip missing projects 2011-01-09 17:39:22 -08:00
grep.py Fix format string bugs in grep 2010-06-17 19:09:37 -07:00
help.py help: Don't show empty Summary or Description sections 2011-01-09 17:39:22 -08:00
init.py sync: Enable use of git clone --reference 2010-10-29 12:08:50 -07:00
manifest.py Add repo manifest -o to save a manifest 2009-03-05 10:32:38 -08:00
prune.py Initial Contribution 2008-10-21 07:00:00 -07:00
rebase.py rebase: Pass through more options 2010-07-15 17:43:02 -07:00
selfupdate.py sync: Run git gc --auto after fetch 2011-01-09 17:39:22 -08:00
smartsync.py Aliasing sync -s to 'smartsync' 2010-05-17 09:58:55 -07:00
stage.py Only display project path in 'repo stage -i' 2009-04-18 11:22:13 -07:00
start.py Require a project or '--all' to be specified when using 'repo start'. 2009-04-22 18:05:50 -07:00
status.py Make 'repo status' show the branch you are currently on 2009-04-18 15:31:36 -07:00
sync.py sync: Run git gc --auto after fetch 2011-01-09 17:39:22 -08:00
upload.py Support repo-level pre-upload hook and prep for future hooks. 2011-03-11 11:53:23 -08:00
version.py Don't permit users to run repo status in a mirror client 2009-03-03 17:47:06 -08:00