@ -7,7 +7,6 @@
import contextlib
import contextlib
import datetime
import datetime
import itertools
import json
import json
import logging
import logging
import os
import os
@ -1416,14 +1415,13 @@ class TestGitCl(TestCase):
def _gerrit_upload_calls ( cls , description , reviewers , squash ,
def _gerrit_upload_calls ( cls , description , reviewers , squash ,
squash_mode = ' default ' ,
squash_mode = ' default ' ,
expected_upstream_ref = ' origin/refs/heads/master ' ,
expected_upstream_ref = ' origin/refs/heads/master ' ,
push_opts= None , title = None , notify = False ,
ref_suffix= ' ' , title = None , notify = False ,
post_amend_description = None , issue = None , cc = None ,
post_amend_description = None , issue = None , cc = None ,
git_mirror = None ) :
git_mirror = None ) :
if post_amend_description is None :
if post_amend_description is None :
post_amend_description = description
post_amend_description = description
calls = [ ]
calls = [ ]
cc = cc or [ ]
cc = cc or [ ]
push_opts = push_opts or [ ]
if squash_mode == ' default ' :
if squash_mode == ' default ' :
calls . extend ( [
calls . extend ( [
@ -1445,14 +1443,14 @@ class TestGitCl(TestCase):
' fake_ancestor_sha..HEAD ' ] , ) ,
' fake_ancestor_sha..HEAD ' ] , ) ,
description ) ]
description ) ]
if squash :
if squash :
title = ' Initial upload'
title = ' Initial _ upload'
else :
else :
if not title :
if not title :
calls + = [
calls + = [
( ( [ ' git ' , ' show ' , ' -s ' , ' --format= %s ' , ' HEAD ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' show ' , ' -s ' , ' --format= %s ' , ' HEAD ' ] , ) , ' ' ) ,
( ( ' ask_for_data ' , ' Title for patchset []: ' ) , ' User input ' ) ,
( ( ' ask_for_data ' , ' Title for patchset []: ' ) , ' User input ' ) ,
]
]
title = ' User input'
title = ' User _ input'
if not git_footers . get_footer_change_id ( description ) and not squash :
if not git_footers . get_footer_change_id ( description ) and not squash :
calls + = [
calls + = [
# DownloadGerritHook(False)
# DownloadGerritHook(False)
@ -1499,10 +1497,20 @@ class TestGitCl(TestCase):
]
]
if title :
if title :
push_opts + = [ ' m= ' + title ]
if ref_suffix :
ref_suffix + = ' ,m= ' + title
else :
ref_suffix = ' % m= ' + title
notify_suffix = ' notify= %s ' % ( ' ALL ' if notify else ' NONE ' )
if ref_suffix :
ref_suffix + = ' , ' + notify_suffix
else :
ref_suffix = ' % ' + notify_suffix
push_opts + = [ ' notify= %s ' % ( ' ALL ' if notify else ' NONE ' ) ]
if reviewers :
push_opts + = [ ' r= %s ' % email for email in sorted ( reviewers or [ ] ) ]
ref_suffix + = ' , ' + ' , ' . join ( ' r= %s ' % email
for email in sorted ( reviewers ) )
if git_mirror is None :
if git_mirror is None :
calls + = [
calls + = [
@ -1521,23 +1529,22 @@ class TestGitCl(TestCase):
]
]
calls + = [
calls + = [
( ( [ ' git ' , ' push ' ] +
( ( [ ' git ' , ' push ' ,
list ( itertools . chain ( * ( [ ' -o ' , opt ] for opt in sorted ( push_opts ) ) ) ) +
' https://chromium.googlesource.com/yyy/zzz ' ,
[ ' https://chromium.googlesource.com/yyy/zzz ' ,
ref_to_push + ' :refs/for/refs/heads/master ' + ref_suffix ] , ) ,
ref_to_push + ' :refs/for/refs/heads/master ' ] , ) ,
( ' remote: \n '
( ' remote: \n '
' remote: Processing changes: ( \ ) \n '
' remote: Processing changes: ( \ ) \n '
' remote: Processing changes: (|) \n '
' remote: Processing changes: (|) \n '
' remote: Processing changes: (/) \n '
' remote: Processing changes: (/) \n '
' remote: Processing changes: (-) \n '
' remote: Processing changes: (-) \n '
' remote: Processing changes: new: 1 (/) \n '
' remote: Processing changes: new: 1 (/) \n '
' remote: Processing changes: new: 1, done \n '
' remote: Processing changes: new: 1, done \n '
' remote: \n '
' remote: \n '
' remote: New Changes: \n '
' remote: New Changes: \n '
' remote: https://chromium-review.googlesource.com/123456 XXX. \n '
' remote: https://chromium-review.googlesource.com/123456 XXX. \n '
' remote: \n '
' remote: \n '
' To https://chromium.googlesource.com/yyy/zzz \n '
' To https://chromium.googlesource.com/yyy/zzz \n '
' * [new branch] hhhh -> refs/for/refs/heads/master \n ' ) ) ,
' * [new branch] hhhh -> refs/for/refs/heads/master \n ' ) ) ,
]
]
if squash :
if squash :
calls + = [
calls + = [
@ -1565,7 +1572,7 @@ class TestGitCl(TestCase):
squash = True ,
squash = True ,
squash_mode = None ,
squash_mode = None ,
expected_upstream_ref = ' origin/refs/heads/master ' ,
expected_upstream_ref = ' origin/refs/heads/master ' ,
push_opts= None ,
ref_suffix= ' ' ,
title = None ,
title = None ,
notify = False ,
notify = False ,
post_amend_description = None ,
post_amend_description = None ,
@ -1612,7 +1619,7 @@ class TestGitCl(TestCase):
description , reviewers , squash ,
description , reviewers , squash ,
squash_mode = squash_mode ,
squash_mode = squash_mode ,
expected_upstream_ref = expected_upstream_ref ,
expected_upstream_ref = expected_upstream_ref ,
push_opts= push_opts , title = title , notify = notify ,
ref_suffix= ref_suffix , title = title , notify = notify ,
post_amend_description = post_amend_description ,
post_amend_description = post_amend_description ,
issue = issue , cc = cc , git_mirror = git_mirror )
issue = issue , cc = cc , git_mirror = git_mirror )
# Uncomment when debugging.
# Uncomment when debugging.
@ -1645,6 +1652,20 @@ class TestGitCl(TestCase):
squash = False ,
squash = False ,
squash_mode = ' override_nosquash ' )
squash_mode = ' override_nosquash ' )
def test_gerrit_patch_bad_chars ( self ) :
self . mock ( git_cl . sys , ' stdout ' , StringIO . StringIO ( ) )
self . _run_gerrit_upload_test (
[ ' -f ' , ' -t ' , ' Don \' t put bad cha,.rs ' ] ,
' desc \n \n BUG= \n \n Change-Id: I123456789 ' ,
squash = False ,
squash_mode = ' override_nosquash ' ,
title = ' Dont_put_bad_chars ' )
self . assertIn (
' WARNING: Patchset title may only contain alphanumeric chars '
' and spaces. You can edit it in the UI. See https://crbug.com/663787. \n '
' Cleaned up title: Dont put bad chars \n ' ,
git_cl . sys . stdout . getvalue ( ) )
def test_gerrit_reviewers_cmd_line ( self ) :
def test_gerrit_reviewers_cmd_line ( self ) :
self . _run_gerrit_upload_test (
self . _run_gerrit_upload_test (
[ ' -r ' , ' foo@example.com ' , ' --send-mail ' ] ,
[ ' -r ' , ' foo@example.com ' , ' --send-mail ' ] ,
@ -1663,7 +1684,7 @@ class TestGitCl(TestCase):
[ ' reviewer@example.com ' , ' another@example.com ' ] ,
[ ' reviewer@example.com ' , ' another@example.com ' ] ,
squash = False ,
squash = False ,
squash_mode = ' override_nosquash ' ,
squash_mode = ' override_nosquash ' ,
push_opts= [ ' l=Code-Review+1 ' ] ,
ref_suffix= ' % l=Code-Review+1 ' ,
cc = [ ' more@example.com ' , ' people@example.com ' ] )
cc = [ ' more@example.com ' , ' people@example.com ' ] )
def test_gerrit_upload_squash_first_is_default ( self ) :
def test_gerrit_upload_squash_first_is_default ( self ) :