Commit 80a9ef1e authored by maruel@chromium.org's avatar maruel@chromium.org

Enforce cwd for GIT functions

GIT.CaptureStatus was assuming os.getcwd() was using all the time, which isn't
true when using trychange.py --sub_rep XXX.

R=dpranke@chromium.org
TEST=
BUG=


Review URL: http://codereview.chromium.org/8930002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@114264 0039d316-1c4b-4281-b951-d872f2087c98
parent d579fcf9
......@@ -500,7 +500,7 @@ or verify this branch is set up to track another (via the --track argument to
name = RunCommand(['git', 'rev-parse', 'HEAD']).strip()
# Need to pass a relative path for msysgit.
try:
files = scm.GIT.CaptureStatus([root], upstream_branch)
files = scm.GIT.CaptureStatus([root], '.', upstream_branch)
except subprocess2.CalledProcessError:
DieWithError(
('\nFailed to diff against upstream branch %s!\n\n'
......
......@@ -19,7 +19,8 @@ import git_cl
def GetRietveldIssueNumber():
try:
return GIT.Capture(
['config', 'branch.%s.rietveldissue' % GIT.GetBranch(None)]).strip()
['config', 'branch.%s.rietveldissue' % GIT.GetBranch('.')],
'.').strip()
except subprocess2.CalledProcessError:
return None
......@@ -27,14 +28,15 @@ def GetRietveldIssueNumber():
def GetRietveldPatchsetNumber():
try:
return GIT.Capture(
['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch(None)]).strip()
['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch('.')],
'.').strip()
except subprocess2.CalledProcessError:
return None
def GetRietveldServerUrl():
try:
return GIT.Capture(['config', 'rietveld.server']).strip()
return GIT.Capture(['config', 'rietveld.server'], '.').strip()
except subprocess2.CalledProcessError:
return None
......
......@@ -97,19 +97,19 @@ class GIT(object):
current_version = None
@staticmethod
def Capture(args, **kwargs):
def Capture(args, cwd, **kwargs):
return subprocess2.check_output(
['git'] + args, stderr=subprocess2.PIPE, **kwargs)
['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, **kwargs)
@staticmethod
def CaptureStatus(files, upstream_branch=None):
def CaptureStatus(files, cwd, upstream_branch):
"""Returns git status.
@files can be a string (one file) or a list of files.
Returns an array of (status, file) tuples."""
if upstream_branch is None:
upstream_branch = GIT.GetUpstreamBranch(os.getcwd())
upstream_branch = GIT.GetUpstreamBranch(cwd)
if upstream_branch is None:
raise gclient_utils.Error('Cannot determine upstream branch')
command = ['diff', '--name-status', '-r', '%s...' % upstream_branch]
......@@ -119,7 +119,7 @@ class GIT(object):
command.append(files)
else:
command.extend(files)
status = GIT.Capture(command).rstrip()
status = GIT.Capture(command, cwd).rstrip()
results = []
if status:
for statusline in status.splitlines():
......@@ -226,7 +226,7 @@ class GIT(object):
# pipe at a time.
# The -100 is an arbitrary limit so we don't search forever.
cmd = ['git', 'log', '-100', '--pretty=medium']
proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE)
proc = subprocess2.Popen(cmd, cwd, stdout=subprocess2.PIPE)
url = None
for line in proc.stdout:
match = git_svn_re.match(line)
......@@ -237,8 +237,9 @@ class GIT(object):
if url:
svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
remotes = GIT.Capture(['config', '--get-regexp',
r'^svn-remote\..*\.url'], cwd=cwd).splitlines()
remotes = GIT.Capture(
['config', '--get-regexp', r'^svn-remote\..*\.url'],
cwd=cwd).splitlines()
for remote in remotes:
match = svn_remote_re.match(remote)
if match:
......@@ -383,7 +384,7 @@ class GIT(object):
def AssertVersion(cls, min_version):
"""Asserts git's version is at least min_version."""
if cls.current_version is None:
cls.current_version = cls.Capture(['--version']).split()[-1]
cls.current_version = cls.Capture(['--version'], '.').split()[-1]
current_version_list = map(only_int, cls.current_version.split('.'))
for min_ver in map(int, min_version.split('.')):
ver = current_version_list.pop(0)
......
......@@ -275,13 +275,17 @@ class GIT(SCM):
logging.info("GIT(%s)" % self.checkout_root)
def CaptureStatus(self):
return scm.GIT.CaptureStatus(self.checkout_root.replace(os.sep, '/'),
self.diff_against)
return scm.GIT.CaptureStatus(
[],
self.checkout_root.replace(os.sep, '/'),
self.diff_against)
def GenerateDiff(self):
return scm.GIT.GenerateDiff(self.checkout_root, files=self.files,
full_move=True,
branch=self.diff_against)
return scm.GIT.GenerateDiff(
self.checkout_root,
files=self.files,
full_move=True,
branch=self.diff_against)
def _ParseSendChangeOptions(options):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment