Index: git_cl.py |
=================================================================== |
--- git_cl.py (revision 113303) |
+++ git_cl.py (working copy) |
@@ -47,7 +47,13 @@ |
POSTUPSTREAM_HOOK_PATTERN = '.git/hooks/post-cl-%s' |
DESCRIPTION_BACKUP_FILE = '~/.git_cl_description_backup' |
+GERRIT_FETCH_URL = 'http://git.chromium.org' |
M-A Ruel
2011/12/07 19:21:28
No, don't hard code them. If you look again, there
|
+# Note these are assuming users have set up ~/.ssh/config stanzas |
+# as recommended so that no port numbers are required. |
+GERRIT_PUSH_URL = 'ssh://gerrit.chromium.org' |
+GERRIT_COMMIT_HOOK = 'gerrit.chromium.org:hooks/commit-msg' |
+ |
# Initialized in main() |
settings = None |
@@ -731,11 +737,28 @@ |
keyvals['ORIGIN_URL_CONFIG']]) |
+def GerritConfig(options, args): |
+ """Set up git config for use with Gerrit.""" |
+ |
+ # Install the standard commit-msg hook. |
+ RunCommand(['scp', '-p', GERRIT_COMMIT_HOOK, |
+ os.path.join('.git', 'hooks', 'commit-msg')]) |
+ |
+ # Set the standard URL mapping. |
+ RunGit(['config', |
+ 'url.' + GERRIT_PUSH_URL + '.pushinsteadof', GERRIT_FETCH_URL]) |
+ |
+ |
@usage('[repo root containing codereview.settings]') |
def CMDconfig(parser, args): |
"""edit configuration for this tree""" |
+ parser.add_option('-g', '--gerrit', action='store_true', |
M-A Ruel
2011/12/07 19:21:28
It should be automatic, no need for flags.
|
+ help='Configure for Gerrit rather than Rietveld') |
+ options, args = parser.parse_args(args) |
- _, args = parser.parse_args(args) |
+ if options.gerrit: |
+ return GerritConfig(options, args) |
+ |
if len(args) == 0: |
GetCodereviewSettingsInteractively() |
return 0 |
@@ -863,6 +886,34 @@ |
return 0 |
+def GerritUpload(options, args): |
+ # We assume the remote called "origin" is the one we want. |
+ # It's probably not worthwhile to support different workflows. |
M-A Ruel
2011/12/07 19:21:28
It is.
|
+ remote = 'origin' |
+ |
+ branch = 'master' |
+ if options.for_branch is not None: |
+ branch = options.for_branch |
+ |
+ receive_options = [] |
+ |
+ if options.cc is not None: |
+ receive_options += ['--cc=' + email for email in |
+ options.cc.split(',')] |
+ if options.reviewers is not None: |
+ receive_options += ['--reviewer=' + email for email in |
+ options.reviewers.split(',')] |
+ |
+ git_command = ['push'] |
+ if receive_options: |
+ git_command.append('--receive-pack=git receive-pack ' + |
+ ' '.join(receive_options)) |
+ git_command += [remote, 'HEAD:refs/for/' + branch] |
+ |
+ RunGit(git_command) |
+ return 0 |
+ |
+ |
@usage('[args to "git diff"]') |
def CMDupload(parser, args): |
"""upload the current changelist to codereview""" |
@@ -886,14 +937,30 @@ |
uses message as subject""") |
parser.add_option('-c', '--use-commit-queue', action='store_true', |
help='tell the commit queue to commit this patchset') |
+ parser.add_option('-g', '--gerrit', action='store_true', |
+ help='Send change to Gerrit rather than Rietveld') |
+ parser.add_option('-b', '--for-branch', |
+ help='Gerrit branch to send change to') |
(options, args) = parser.parse_args(args) |
+ # TODO(mcgrathr): Perhaps look at some git-config variable stored |
+ # by GerritConfig to default to gerrit mode? |
+ if options.gerrit and (options.bypass_hooks or |
+ options.message or |
+ options.from_logs or |
+ options.use_commit_queue): |
+ print 'The --gerrit (-g) option is incompatible with most other options.' |
+ return 1 |
+ |
# Make sure index is up-to-date before running diff-index. |
RunGit(['update-index', '--refresh', '-q'], error_ok=True) |
if RunGit(['diff-index', 'HEAD']): |
print 'Cannot upload with a dirty tree. You must commit locally first.' |
return 1 |
+ if options.gerrit: |
+ return GerritUpload(options, args) |
+ |
cl = Changelist() |
if args: |
base_branch = args[0] |