Use a regex instead of shlex.split() to get remote url

shlex.spit(), in addition to doing str.split(' '), also strips out '\\'
from windows paths, which causes the cache_dir check to fail and Gclient to think
that we're not in cache_dir mode even if we are.

Instead of using shlex to strip data from a stdout log, I think regex is more
suited for this job.

BUG=405973

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@291446 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py
index 3dd175c..163cc07 100755
--- a/tests/gclient_scm_test.py
+++ b/tests/gclient_scm_test.py
@@ -88,6 +88,33 @@
     gclient_scm.GitWrapper.BinaryExists = self._original_GitBinaryExists
 
 
+class BasicTests(SuperMoxTestBase):
+  def setUp(self):
+    SuperMoxTestBase.setUp(self)
+
+  def testGetFirstRemoteUrl(self):
+    REMOTE_STRINGS = [('remote.origin.url E:\\foo\\bar', 'E:\\foo\\bar'),
+                      ('remote.origin.url /b/foo/bar', '/b/foo/bar'),
+                      ('remote.origin.url https://foo/bar', 'https://foo/bar'),
+                      ('remote.origin.url E:\\Fo Bar\\bax', 'E:\\Fo Bar\\bax'),
+                      ('remote.origin.url git://what/"do', 'git://what/"do')]
+    FAKE_PATH = '/fake/path'
+    self.mox.StubOutWithMock(gclient_scm.scm.GIT, 'Capture')
+    for question, _ in REMOTE_STRINGS:
+      gclient_scm.scm.GIT.Capture(
+          ['config', '--local', '--get-regexp', r'remote.*.url'],
+          cwd=FAKE_PATH).AndReturn(question)
+
+    self.mox.ReplayAll()
+
+    for _, answer in REMOTE_STRINGS:
+      self.assertEquals(gclient_scm.SCMWrapper._get_first_remote_url(FAKE_PATH),
+                        answer)
+
+  def tearDown(self):
+    SuperMoxTestBase.tearDown(self)
+
+
 class SVNWrapperTestCase(BaseTestCase):
   class OptionsObject(object):
     def __init__(self, verbose=False, revision=None, force=False):