Index: git_cl.py |
diff --git a/git_cl.py b/git_cl.py |
index 4c91b6c762147b7ce5c886df94d8fdd906995725..84308a35908ba06edaf1f5d372a7d70cfcd45ded 100755 |
--- a/git_cl.py |
+++ b/git_cl.py |
@@ -1749,6 +1749,34 @@ def RietveldUpload(options, args, cl, change): |
upload_args.extend(['--base_url', remote_url]) |
remote, remote_branch = cl.GetRemoteBranch() |
if remote and remote_branch: |
+ if options.target_branch: |
+ # Cannonicalize branch references to the equivalent local full symbolic |
+ # refs, which are then translated into the remote full symbolic refs |
+ # below. |
+ if '/' not in options.target_branch: |
+ remote_branch = 'refs/remotes/%s/%s' % (remote, options.target_branch) |
+ else: |
+ prefix_replacements = (('^((refs/)?remotes/)?branch-heads/', |
agable
2015/01/22 22:59:11
nit: would prefer these be formatted as
prefix_re
Mike Wittman
2015/01/23 23:54:47
Done.
|
+ 'refs/remotes/branch-heads/'), |
+ ('^((refs/)?remotes/)?%s/' % remote, |
+ 'refs/remotes/%s/' % remote), |
+ ('^(refs/)?heads/', |
+ 'refs/remotes/%s/' % remote)) |
+ |
+ match = None |
+ for regex, replacement in prefix_replacements: |
+ match = re.search(regex, options.target_branch) |
+ if match: |
+ remote_branch = options.target_branch.replace(match.group(0), |
+ replacement) |
+ break |
+ if not match: |
+ # This is a branch path but not one we recognize; use as-is. |
+ remote_branch = options.target_branch |
+ elif not remote_branch.startswith('refs/remotes/branch-heads'): |
+ # Default to master for refs that are not branches. |
+ remote_branch = 'refs/remotes/%s/master' % remote |
+ |
# Create the true path to the remote branch. |
# Does the following translation: |
# * refs/remotes/origin/refs/diff/test -> refs/diff/test |
@@ -1842,8 +1870,8 @@ def CMDupload(parser, args): |
help='set the review private (rietveld only)') |
parser.add_option('--target_branch', |
'--target-branch', |
- help='When uploading to gerrit, remote branch to ' |
- 'use for CL. Default: master') |
+ help='Remote branch to use for CL. ' + |
agable
2015/01/22 22:59:11
"to use for" is awkward and not super specific. No
Mike Wittman
2015/01/23 23:54:47
Cleaned this up by referring to a metavar.
|
+ 'Default: remote branch head, or master') |
agable
2015/01/22 22:59:11
nit: indentation
Mike Wittman
2015/01/23 23:54:47
Done.
|
parser.add_option('--email', default=None, |
help='email address to use to connect to Rietveld') |
parser.add_option('--tbr-owners', dest='tbr_owners', action='store_true', |
@@ -1852,9 +1880,6 @@ def CMDupload(parser, args): |
add_git_similarity(parser) |
(options, args) = parser.parse_args(args) |
- if options.target_branch and not settings.GetIsGerrit(): |
- parser.error('Use --target_branch for non gerrit repository.') |
- |
if is_dirty_git_tree('upload'): |
return 1 |