git cl: add --gerrit and --rietveld options to force codereview.

This makes it possible to override the codereview set in:
 * repository codereview.settings
 * cached/set in local .git/config, either repo-wide or
   current branch only.

Examples:

    cd $SOME_RIETVELD_USING_REPO
    # Enable Gerrit codereview on it. Contact Infra-Git admin:
    # https://bugs.chromium.org/p/chromium/issues/entry?template=Infra-Git

    # Uploading
    git cl upload --gerrit --squash
    # Hack, hack, re-upload uses Gerrit automatically.
    git cl upload --squash

    # Patching
    git new-branch patched-in-issue
    git cl patch --gerrit XXXXXX

    # (Re-)setting issue
    git cl issue --gerrit 0
    git cl issue --gerrit XXXXXX

R=andybons@chromium.org,sergiyb@chromium.org
BUG=598681

Review URL: https://codereview.chromium.org/1880243003

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@299901 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 8eacfbb..295d1a0 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -1093,7 +1093,7 @@
     self.mock(git_common, 'is_dirty_git_tree', lambda x: True)
     self.assertNotEqual(git_cl.main(['diff']), 0)
 
-  def _patch_common(self, is_gerrit=False):
+  def _patch_common(self, is_gerrit=False, force_codereview=False):
     self.mock(git_cl._RietveldChangelistImpl, 'GetMostRecentPatchset',
               lambda x: '60001')
     self.mock(git_cl._RietveldChangelistImpl, 'GetPatchSetDiff',
@@ -1122,17 +1122,23 @@
               lambda *args: 'Description')
     self.mock(git_cl, 'IsGitVersionAtLeast', lambda *args: True)
 
-    self.calls = [
-      ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
-      ((['git', 'config', 'branch.master.rietveldissue'],), ''),
-      ((['git', 'config', 'branch.master.gerritissue'],), ''),
-      ((['git', 'config', 'rietveld.autoupdate'],), ''),
-    ]
-    if is_gerrit:
-      self.calls += [
-        ((['git', 'config', 'gerrit.host'],), 'true'),
+    if not force_codereview:
+      # These calls detect codereview to use.
+      self.calls = [
+        ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
+        ((['git', 'config', 'branch.master.rietveldissue'],), ''),
+        ((['git', 'config', 'branch.master.gerritissue'],), ''),
+        ((['git', 'config', 'rietveld.autoupdate'],), ''),
       ]
     else:
+      self.calls = []
+
+    if is_gerrit:
+      if not force_codereview:
+        self.calls += [
+          ((['git', 'config', 'gerrit.host'],), 'true'),
+        ]
+    else:
       self.calls += [
         ((['git', 'config', 'gerrit.host'],), ''),
         ((['git', 'config', 'rietveld.server'],), 'codereview.example.com'),
@@ -1182,6 +1188,25 @@
     ]
     self.assertEqual(git_cl.main(['patch', '123456']), 0)
 
+  def test_patch_force_codereview(self):
+    self._patch_common(is_gerrit=True, force_codereview=True)
+    self.calls += [
+      ((['git', 'fetch', 'https://chromium.googlesource.com/my/repo',
+         'refs/changes/56/123456/7'],), ''),
+      ((['git', 'cherry-pick', 'FETCH_HEAD'],), ''),
+      ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
+      ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''),
+      ((['git', 'config', 'branch.master.gerritserver'],), ''),
+      ((['git', 'config', 'branch.master.merge'],), 'master'),
+      ((['git', 'config', 'branch.master.remote'],), 'origin'),
+      ((['git', 'config', 'remote.origin.url'],),
+       'https://chromium.googlesource.com/my/repo'),
+      ((['git', 'config', 'branch.master.gerritserver',
+        'https://chromium-review.googlesource.com'],), ''),
+      ((['git', 'config', 'branch.master.gerritpatchset', '7'],), ''),
+    ]
+    self.assertEqual(git_cl.main(['patch', '--gerrit', '123456']), 0)
+
   def test_gerrit_patch_url_successful(self):
     self._patch_common(is_gerrit=True)
     self.calls += [