@ -758,76 +758,6 @@ class TestGitCl(TestCase):
return [ ( ( [ ' git ' , ' config ' , ' rietveld.autoupdate ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' config ' , ' gerrit.host ' ] , ) , ' True ' if gerrit else ' ' ) ]
@classmethod
def _upload_calls ( cls , private , no_autocc ) :
return ( cls . _rietveld_git_base_calls ( ) +
cls . _git_upload_calls ( private , no_autocc ) )
@classmethod
def _rietveld_upload_no_rev_calls ( cls ) :
return ( cls . _rietveld_git_base_calls ( ) + [
( ( [ ' git ' , ' config ' , ' core.editor ' ] , ) , ' ' ) ,
] )
@classmethod
def _rietveld_git_base_calls ( cls ) :
stat_call = ( ( [ ' git ' , ' diff ' , ' --no-ext-diff ' , ' --stat ' ,
' -l100000 ' , ' -C50 ' , ' fake_ancestor_sha ' , ' HEAD ' ] , ) , ' +dat ' )
return cls . _is_gerrit_calls ( ) + [
( ( [ ' git ' , ' symbolic-ref ' , ' HEAD ' ] , ) , ' master ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.rietveldissue ' ] , ) , CERR1 ) ,
( ( [ ' git ' , ' config ' , ' branch.master.gerritissue ' ] , ) , CERR1 ) ,
( ( [ ' git ' , ' config ' , ' rietveld.server ' ] , ) ,
' codereview.example.com ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.merge ' ] , ) , ' master ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.remote ' ] , ) , ' origin ' ) ,
( ( [ ' get_or_create_merge_base ' , ' master ' , ' master ' ] , ) ,
' fake_ancestor_sha ' ) ,
] + cls . _git_sanity_checks ( ' fake_ancestor_sha ' , ' master ' ) + [
( ( [ ' git ' , ' rev-parse ' , ' --show-cdup ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' rev-parse ' , ' HEAD ' ] , ) , ' 12345 ' ) ,
( ( [ ' git ' , ' -c ' , ' core.quotePath=false ' , ' diff ' ,
' --name-status ' , ' --no-renames ' , ' -r ' , ' fake_ancestor_sha... ' , ' . ' ] , ) ,
' M \t .gitignore \n ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.rietveldpatchset ' ] , ) , CERR1 ) ,
( ( [ ' git ' , ' log ' , ' --pretty=format: %s % n % n % b ' ,
' fake_ancestor_sha... ' ] , ) ,
' foo ' ) ,
( ( [ ' git ' , ' config ' , ' user.email ' ] , ) , ' me@example.com ' ) ,
stat_call ,
( ( [ ' git ' , ' log ' , ' --pretty=format: %s \n \n % b ' ,
' fake_ancestor_sha..HEAD ' ] , ) ,
' desc \n ' ) ,
( ( [ ' git ' , ' config ' , ' rietveld.bug-prefix ' ] , ) , ' ' ) ,
]
@classmethod
def _git_upload_calls ( cls , private , no_autocc ) :
if private or no_autocc :
cc_call = [ ]
else :
cc_call = [ ( ( [ ' git ' , ' config ' , ' rietveld.cc ' ] , ) , ' ' ) ]
if private :
private_call = [ ]
else :
private_call = [
( ( [ ' git ' , ' config ' , ' rietveld.private ' ] , ) , ' ' ) ]
return [
( ( [ ' git ' , ' config ' , ' core.editor ' ] , ) , ' ' ) ,
] + cc_call + private_call + [
( ( [ ' git ' , ' config ' , ' branch.master.base-url ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' config ' , ' remote.origin.url ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' config ' , ' rietveld.project ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.rietveldissue ' , ' 1 ' ] , ) , ' ' ) ,
( ( [ ' git ' , ' config ' , ' branch.master.rietveldserver ' ,
' https://codereview.example.com ' ] , ) , ' ' ) ,
( ( [ ' git ' ,
' config ' , ' branch.master.rietveldpatchset ' , ' 2 ' ] , ) , ' ' ) ,
] + cls . _git_post_upload_calls ( )
@classmethod
def _git_post_upload_calls ( cls ) :
return [
@ -864,156 +794,6 @@ class TestGitCl(TestCase):
' refs/remotes/origin/master ' ] , ) , ' ' ) ,
]
@staticmethod
def _cmd_line ( description , args , private , cc ) :
""" Returns the upload command line passed to upload.RealMain(). """
return [
' upload ' , ' --assume_yes ' , ' --server ' , ' https://codereview.example.com ' ,
' --message ' , description
] + args + [
' --cc ' ,
' , ' . join (
[ ' joe@example.com ' , ' chromium-reviews+test-more-cc@chromium.org ' ] +
cc ) ,
] + ( [ ' --private ' ] if private else [ ] ) + [ ' fake_ancestor_sha ' , ' HEAD ' ]
def _run_reviewer_test (
self ,
upload_args ,
expected_description ,
returned_description ,
final_description ,
reviewers ,
cc = None ) :
""" Generic reviewer test framework. """
self . mock ( git_cl . sys , ' stdout ' , StringIO . StringIO ( ) )
private = ' --private ' in upload_args
cc = cc or [ ]
no_autocc = ' --no-autocc ' in upload_args
self . calls = self . _upload_calls ( private , no_autocc )
def RunEditor ( desc , _ , * * kwargs ) :
self . assertEquals (
' # Enter a description of the change. \n '
' # This will be displayed on the codereview site. \n '
' # The first line will also be used as the subject of the review. \n '
' #--------------------This line is 72 characters long '
' -------------------- \n ' +
expected_description ,
desc )
return returned_description
self . mock ( git_cl . gclient_utils , ' RunEditor ' , RunEditor )
def check_upload ( args ) :
cmd_line = self . _cmd_line ( final_description , reviewers , private , cc )
self . assertEquals ( cmd_line , args )
return 1 , 2
self . mock ( git_cl . upload , ' RealMain ' , check_upload )
git_cl . main ( [ ' upload ' ] + upload_args )
def test_no_reviewer ( self ) :
self . _run_reviewer_test (
[ ] ,
' desc \n \n BUG= ' ,
' # Blah blah comment. \n desc \n \n BUG= ' ,
' desc \n \n BUG= ' ,
[ ] )
def test_private ( self ) :
self . _run_reviewer_test (
[ ' --private ' ] ,
' desc \n \n BUG= ' ,
' # Blah blah comment. \n desc \n \n BUG= \n ' ,
' desc \n \n BUG= ' ,
[ ] )
def test_no_autocc ( self ) :
self . _run_reviewer_test (
[ ' --no-autocc ' ] ,
' desc \n \n BUG= ' ,
' # Blah blah comment. \n desc \n \n BUG= \n ' ,
' desc \n \n BUG= ' ,
[ ] )
def test_reviewers_cmd_line ( self ) :
# Reviewer is passed as-is
description = ' desc \n \n R=foo@example.com \n BUG= '
self . _run_reviewer_test (
[ ' -r ' ' foo@example.com ' ] ,
description ,
' \n %s \n ' % description ,
description ,
[ ' --reviewers=foo@example.com ' ] )
def test_reviewer_tbr_overriden ( self ) :
# Reviewer is overriden with TBR
# Also verifies the regexp work without a trailing LF
description = ' Foo Bar \n \n TBR=reviewer@example.com '
self . _run_reviewer_test (
[ ' -r ' ' foo@example.com ' ] ,
' desc \n \n R=foo@example.com \n BUG= ' ,
description . strip ( ' \n ' ) ,
description ,
[ ' --reviewers=reviewer@example.com ' ] )
def test_reviewer_multiple ( self ) :
# Handles multiple R= or TBR= lines.
description = (
' Foo Bar \n TBR=reviewer@example.com \n BUG= \n R=another@example.com \n '
' CC=more@example.com,people@example.com ' )
self . _run_reviewer_test (
[ ] ,
' desc \n \n BUG= ' ,
description ,
description ,
[ ' --reviewers=another@example.com,reviewer@example.com ' ] ,
cc = [ ' more@example.com ' , ' people@example.com ' ] )
def test_reviewer_send_mail ( self ) :
# --send-mail can be used without -r if R= is used
description = ' Foo Bar \n R=reviewer@example.com '
self . _run_reviewer_test (
[ ' --send-mail ' ] ,
' desc \n \n BUG= ' ,
description . strip ( ' \n ' ) ,
description ,
[ ' --reviewers=reviewer@example.com ' , ' --send_mail ' ] )
def test_reviewer_send_mail_no_rev ( self ) :
# Fails without a reviewer.
stdout = StringIO . StringIO ( )
self . calls = self . _rietveld_upload_no_rev_calls ( ) + [
( ( [ ' DieWithError ' , ' Must specify reviewers to send email. ' ] , ) ,
SystemExitMock ( ) )
]
def RunEditor ( desc , _ , * * kwargs ) :
return desc
self . mock ( git_cl . gclient_utils , ' RunEditor ' , RunEditor )
self . mock ( sys , ' stdout ' , stdout )
with self . assertRaises ( SystemExitMock ) :
git_cl . main ( [ ' upload ' , ' --send-mail ' ] )
self . assertEqual (
' ===================================== \n '
' NOTICE: Rietveld is being deprecated. '
' You can upload changes to Gerrit with \n '
' git cl upload --gerrit \n '
' or set Gerrit to be your default code review tool with \n '
' git config gerrit.host true \n '
' ===================================== \n ' ,
stdout . getvalue ( ) )
def test_bug_on_cmd ( self ) :
self . _run_reviewer_test (
[ ' --bug=500658,proj:123 ' ] ,
' desc \n \n BUG=500658 \n BUG=proj:123 ' ,
' # Blah blah comment. \n desc \n \n BUG=500658 \n BUG=proj:1234 ' ,
' desc \n \n BUG=500658 \n BUG=proj:1234 ' ,
[ ] )
@classmethod
def _gerrit_ensure_auth_calls ( cls , issue = None , skip_auth_check = False ) :
cmd = [ ' git ' , ' config ' , ' --bool ' , ' gerrit.skip-ensure-authenticated ' ]