upload: add support for standard --dry-run

Change-Id: I69ea2f3170ba17bfb9e0e3771db4ecc66a736797
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/255856
Tested-by: Mike Frysinger <vapier@google.com>
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
diff --git a/project.py b/project.py
index 06606fa..86c9ef0 100644
--- a/project.py
+++ b/project.py
@@ -198,6 +198,7 @@
     return self._base_exists
 
   def UploadForReview(self, people,
+                      dryrun=False,
                       auto_topic=False,
                       hashtags=(),
                       draft=False,
@@ -207,8 +208,9 @@
                       dest_branch=None,
                       validate_certs=True,
                       push_options=None):
-    self.project.UploadForReview(self.name,
-                                 people,
+    self.project.UploadForReview(branch=self.name,
+                                 people=people,
+                                 dryrun=dryrun,
                                  auto_topic=auto_topic,
                                  hashtags=hashtags,
                                  draft=draft,
@@ -1332,6 +1334,7 @@
 
   def UploadForReview(self, branch=None,
                       people=([], []),
+                      dryrun=False,
                       auto_topic=False,
                       hashtags=(),
                       draft=False,
@@ -1369,6 +1372,8 @@
     if url is None:
       raise UploadError('review not configured')
     cmd = ['push']
+    if dryrun:
+      cmd.append('-n')
 
     if url.startswith('ssh://'):
       cmd.append('--receive-pack=gerrit receive-pack')
diff --git a/subcmds/upload.py b/subcmds/upload.py
index 633ddc8..6ef4955 100644
--- a/subcmds/upload.py
+++ b/subcmds/upload.py
@@ -181,6 +181,9 @@
                  type='string', action='store', dest='dest_branch',
                  metavar='BRANCH',
                  help='Submit for review on this target branch.')
+    p.add_option('-n', '--dry-run',
+                 dest='dryrun', default=False, action='store_true',
+                 help='Do everything except actually upload the CL.')
     p.add_option('--no-cert-checks',
                  dest='validate_certs', action='store_false', default=True,
                  help='Disable verifying ssl certs (unsafe).')
@@ -423,6 +426,7 @@
             continue
 
         branch.UploadForReview(people,
+                               dryrun=opt.dryrun,
                                auto_topic=opt.auto_topic,
                                hashtags=hashtags,
                                draft=opt.draft,