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 ...@@ -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() name = RunCommand(['git', 'rev-parse', 'HEAD']).strip()
# Need to pass a relative path for msysgit. # Need to pass a relative path for msysgit.
try: try:
files = scm.GIT.CaptureStatus([root], upstream_branch) files = scm.GIT.CaptureStatus([root], '.', upstream_branch)
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
DieWithError( DieWithError(
('\nFailed to diff against upstream branch %s!\n\n' ('\nFailed to diff against upstream branch %s!\n\n'
......
...@@ -19,7 +19,8 @@ import git_cl ...@@ -19,7 +19,8 @@ import git_cl
def GetRietveldIssueNumber(): def GetRietveldIssueNumber():
try: try:
return GIT.Capture( return GIT.Capture(
['config', 'branch.%s.rietveldissue' % GIT.GetBranch(None)]).strip() ['config', 'branch.%s.rietveldissue' % GIT.GetBranch('.')],
'.').strip()
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
return None return None
...@@ -27,14 +28,15 @@ def GetRietveldIssueNumber(): ...@@ -27,14 +28,15 @@ def GetRietveldIssueNumber():
def GetRietveldPatchsetNumber(): def GetRietveldPatchsetNumber():
try: try:
return GIT.Capture( return GIT.Capture(
['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch(None)]).strip() ['config', 'branch.%s.rietveldpatchset' % GIT.GetBranch('.')],
'.').strip()
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
return None return None
def GetRietveldServerUrl(): def GetRietveldServerUrl():
try: try:
return GIT.Capture(['config', 'rietveld.server']).strip() return GIT.Capture(['config', 'rietveld.server'], '.').strip()
except subprocess2.CalledProcessError: except subprocess2.CalledProcessError:
return None return None
......
...@@ -97,19 +97,19 @@ class GIT(object): ...@@ -97,19 +97,19 @@ class GIT(object):
current_version = None current_version = None
@staticmethod @staticmethod
def Capture(args, **kwargs): def Capture(args, cwd, **kwargs):
return subprocess2.check_output( return subprocess2.check_output(
['git'] + args, stderr=subprocess2.PIPE, **kwargs) ['git'] + args, cwd=cwd, stderr=subprocess2.PIPE, **kwargs)
@staticmethod @staticmethod
def CaptureStatus(files, upstream_branch=None): def CaptureStatus(files, cwd, upstream_branch):
"""Returns git status. """Returns git status.
@files can be a string (one file) or a list of files. @files can be a string (one file) or a list of files.
Returns an array of (status, file) tuples.""" Returns an array of (status, file) tuples."""
if upstream_branch is None: if upstream_branch is None:
upstream_branch = GIT.GetUpstreamBranch(os.getcwd()) upstream_branch = GIT.GetUpstreamBranch(cwd)
if upstream_branch is None: if upstream_branch is None:
raise gclient_utils.Error('Cannot determine upstream branch') raise gclient_utils.Error('Cannot determine upstream branch')
command = ['diff', '--name-status', '-r', '%s...' % upstream_branch] command = ['diff', '--name-status', '-r', '%s...' % upstream_branch]
...@@ -119,7 +119,7 @@ class GIT(object): ...@@ -119,7 +119,7 @@ class GIT(object):
command.append(files) command.append(files)
else: else:
command.extend(files) command.extend(files)
status = GIT.Capture(command).rstrip() status = GIT.Capture(command, cwd).rstrip()
results = [] results = []
if status: if status:
for statusline in status.splitlines(): for statusline in status.splitlines():
...@@ -226,7 +226,7 @@ class GIT(object): ...@@ -226,7 +226,7 @@ class GIT(object):
# pipe at a time. # pipe at a time.
# The -100 is an arbitrary limit so we don't search forever. # The -100 is an arbitrary limit so we don't search forever.
cmd = ['git', 'log', '-100', '--pretty=medium'] cmd = ['git', 'log', '-100', '--pretty=medium']
proc = subprocess2.Popen(cmd, stdout=subprocess2.PIPE) proc = subprocess2.Popen(cmd, cwd, stdout=subprocess2.PIPE)
url = None url = None
for line in proc.stdout: for line in proc.stdout:
match = git_svn_re.match(line) match = git_svn_re.match(line)
...@@ -237,8 +237,9 @@ class GIT(object): ...@@ -237,8 +237,9 @@ class GIT(object):
if url: if url:
svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$') svn_remote_re = re.compile(r'^svn-remote\.([^.]+)\.url (.*)$')
remotes = GIT.Capture(['config', '--get-regexp', remotes = GIT.Capture(
r'^svn-remote\..*\.url'], cwd=cwd).splitlines() ['config', '--get-regexp', r'^svn-remote\..*\.url'],
cwd=cwd).splitlines()
for remote in remotes: for remote in remotes:
match = svn_remote_re.match(remote) match = svn_remote_re.match(remote)
if match: if match:
...@@ -383,7 +384,7 @@ class GIT(object): ...@@ -383,7 +384,7 @@ class GIT(object):
def AssertVersion(cls, min_version): def AssertVersion(cls, min_version):
"""Asserts git's version is at least min_version.""" """Asserts git's version is at least min_version."""
if cls.current_version is None: 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('.')) current_version_list = map(only_int, cls.current_version.split('.'))
for min_ver in map(int, min_version.split('.')): for min_ver in map(int, min_version.split('.')):
ver = current_version_list.pop(0) ver = current_version_list.pop(0)
......
...@@ -275,13 +275,17 @@ class GIT(SCM): ...@@ -275,13 +275,17 @@ class GIT(SCM):
logging.info("GIT(%s)" % self.checkout_root) logging.info("GIT(%s)" % self.checkout_root)
def CaptureStatus(self): def CaptureStatus(self):
return scm.GIT.CaptureStatus(self.checkout_root.replace(os.sep, '/'), return scm.GIT.CaptureStatus(
self.diff_against) [],
self.checkout_root.replace(os.sep, '/'),
self.diff_against)
def GenerateDiff(self): def GenerateDiff(self):
return scm.GIT.GenerateDiff(self.checkout_root, files=self.files, return scm.GIT.GenerateDiff(
full_move=True, self.checkout_root,
branch=self.diff_against) files=self.files,
full_move=True,
branch=self.diff_against)
def _ParseSendChangeOptions(options): 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