Fix rebase-update on windows on git-svn repos.
Through a comedy of wrapper scripts, the ^ is being swallowed, which
causes the `git config` invocation to match all lines which HAVE
"remote" in them, instead of matching lines which BEGIN with remote.
R=maruel@chromium.org, pkasting@chromium.org
BUG=
Review URL: https://codereview.chromium.org/1566343002
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298185 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_common.py b/git_common.py
index d405144..5063652 100644
--- a/git_common.py
+++ b/git_common.py
@@ -33,7 +33,8 @@
ROOT = os.path.abspath(os.path.dirname(__file__))
-GIT_EXE = ROOT+'\\git.bat' if sys.platform.startswith('win') else 'git'
+IS_WIN = sys.platform == 'win32'
+GIT_EXE = ROOT+'\\git.bat' if IS_WIN else 'git'
TEST_MODE = False
FREEZE = 'FREEZE'
@@ -284,11 +285,20 @@
return config('branch.%s.%s' % (branch, option), default=default)
+def config_regexp(pattern):
+ if IS_WIN: # pragma: no cover
+ # this madness is because we call git.bat which calls git.exe which calls
+ # bash.exe (or something to that effect). Each layer divides the number of
+ # ^'s by 2.
+ pattern = pattern.replace('^', '^' * 8)
+ return run('config', '--get-regexp', pattern).splitlines()
+
+
def branch_config_map(option):
"""Return {branch: <|option| value>} for all branches."""
try:
reg = re.compile(r'^branch\.(.*)\.%s$' % option)
- lines = run('config', '--get-regexp', reg.pattern).splitlines()
+ lines = config_regexp(reg.pattern)
return {reg.match(k).group(1): v for k, v in (l.split() for l in lines)}
except subprocess2.CalledProcessError:
return {}
@@ -553,7 +563,6 @@
except subprocess2.CalledProcessError as cpe:
return cpe.returncode
-
def run_stream(*cmd, **kwargs):
"""Runs a git command. Returns stdout as a PIPE (file-like object).
@@ -562,6 +571,7 @@
"""
kwargs.setdefault('stderr', subprocess2.VOID)
kwargs.setdefault('stdout', subprocess2.PIPE)
+ kwargs.setdefault('shell', False)
cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
proc = subprocess2.Popen(cmd, **kwargs)
return proc.stdout
@@ -578,6 +588,7 @@
"""
kwargs.setdefault('stderr', subprocess2.VOID)
kwargs.setdefault('stdout', subprocess2.PIPE)
+ kwargs.setdefault('shell', False)
cmd = (GIT_EXE, '-c', 'color.ui=never') + cmd
try:
proc = subprocess2.Popen(cmd, **kwargs)
@@ -601,6 +612,7 @@
kwargs.setdefault('stdin', subprocess2.PIPE)
kwargs.setdefault('stdout', subprocess2.PIPE)
kwargs.setdefault('stderr', subprocess2.PIPE)
+ kwargs.setdefault('shell', False)
autostrip = kwargs.pop('autostrip', True)
indata = kwargs.pop('indata', None)