[git-cl] Handle non-HTTPS repositories gracefully in EnsureAuthenticated

There are some Google-internal repos that use a custom scheme. Having
any remotes pointing to these URLs breaks git cl archive.

Change-Id: Ibd686c5cd11e090f0821ff2b412540138252dfce
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1614946
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Andrii Shyshkalov <tandrii@chromium.org>
diff --git a/tests/git_cl_test.py b/tests/git_cl_test.py
index a665aa9..a19181c 100755
--- a/tests/git_cl_test.py
+++ b/tests/git_cl_test.py
@@ -806,16 +806,16 @@
       return [((cmd, ), 'true')]
 
     calls = [((cmd, ), CERR1)]
-    if issue:
-      calls.extend([
-          ((['git', 'config', 'branch.master.gerritserver'],), CERR1),
-      ])
     calls.extend([
         ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
         ((['git', 'config', 'branch.master.remote'],), 'origin'),
         ((['git', 'config', 'remote.origin.url'],),
          'https://%s.googlesource.com/my/repo' % short_hostname),
     ])
+    if issue:
+      calls.extend([
+          ((['git', 'config', 'branch.master.gerritserver'],), CERR1),
+      ])
     return calls
 
   @classmethod
@@ -2007,6 +2007,22 @@
         'chromium.googlesource.com')
     self.assertTrue('Bearer' in header)
 
+  def test_gerrit_ensure_authenticated_non_https(self):
+    self.calls = [
+        ((['git', 'config', '--bool',
+           'gerrit.skip-ensure-authenticated'],), CERR1),
+        ((['git', 'config', 'branch.master.merge'],), 'refs/heads/master'),
+        ((['git', 'config', 'branch.master.remote'],), 'origin'),
+        ((['git', 'config', 'remote.origin.url'],), 'custom-scheme://repo'),
+    ]
+    self.mock(git_cl.gerrit_util, 'CookiesAuthenticator',
+              CookiesAuthenticatorMockFactory(hosts_with_creds={}))
+    cl = git_cl.Changelist(codereview='gerrit')
+    cl.branch = 'master'
+    cl.branchref = 'refs/heads/master'
+    cl.lookedup_issue = True
+    self.assertIsNone(cl.EnsureAuthenticated(force=False))
+
   def _cmd_set_commit_gerrit_common(self, vote, notify=None):
     self.mock(git_cl.gerrit_util, 'SetReview',
               lambda h, i, labels, notify=None: