git cl: restart using project~number on Gerrit.

This fixes Gerrit project detection based on remote URL,
accounting for potential 'a/' prefix in the URL path component,
which isn't part of the Gerrit project name.

R=ehmaldonado, mmoss

Bug: 876964, 876910
Change-Id: I473ae8c6c9e0f2034b350901abd67db151e0a3d3
Reviewed-on: https://chromium-review.googlesource.com/1187573
Reviewed-by: Michael Moss <mmoss@chromium.org>
Commit-Queue: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index 6edbe35..ba3a643 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -1327,7 +1327,7 @@
     if squash:
       calls += [
           (('AddReviewers',
-            'chromium-review.googlesource.com', '123456',
+            'chromium-review.googlesource.com', 'my%2Frepo~123456',
             sorted(reviewers),
             ['joe@example.com', 'chromium-reviews+test-more-cc@chromium.org'] +
             cc, notify), ''),
@@ -1351,7 +1351,7 @@
           }),
         (('SetReview',
           'chromium-review.googlesource.com',
-          '123456',
+          'my%2Frepo~123456',
           'Self-approving for TBR',
           {'Code-Review': 2}, None), ''),
       ]
@@ -3450,6 +3450,17 @@
     self.assertEqual(cl.GetRemoteUrl(), url)
     self.assertEqual(cl.GetRemoteUrl(), url)  # Must be cached.
 
+  def test_gerrit_project_detection(self):
+    self.calls = [
+      ((['git', 'symbolic-ref', 'HEAD'],), 'master'),
+      ((['git', 'config', 'branch.master.merge'],), 'master'),
+      ((['git', 'config', 'branch.master.remote'],), 'origin'),
+      ((['git', 'config', 'remote.origin.url'],),
+       'https://chromium.googlesource.com/a/my/repo.git/'),
+    ]
+    cl = git_cl.Changelist(codereview='gerrit', issue=1)
+    self.assertEqual(cl._GetGerritProject(), 'my/repo')
+
 
 if __name__ == '__main__':
   logging.basicConfig(