Commit 7444c504 authored by maruel@chromium.org's avatar maruel@chromium.org

Improve presubmit_support.py handling of git checkout.

It would fail otherwise when called directly from a git checkout subdirectory.

Updated unit test.

BUG=none
TEST=none

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@74281 0039d316-1c4b-4281-b951-d872f2087c98
parent cdbecc49
......@@ -1053,6 +1053,7 @@ def ScanSubDirs(mask, recursive):
def ParseFiles(args, recursive):
logging.debug('Searching for %s' % args)
files = []
for arg in args:
files.extend([('M', f) for f in ScanSubDirs(arg, recursive)])
......@@ -1083,15 +1084,9 @@ def Main(argv):
parser.add_option("--default_presubmit")
parser.add_option("--may_prompt", action='store_true', default=False)
options, args = parser.parse_args(argv[1:])
if os.path.isdir(os.path.join(options.root, '.git')):
change_class = GitChange
if not options.files:
if args:
options.files = ParseFiles(args, options.recursive)
else:
# Grab modified files.
options.files = scm.GIT.CaptureStatus([options.root])
elif os.path.isdir(os.path.join(options.root, '.svn')):
if options.verbose:
logging.basicConfig(level=logging.DEBUG)
if os.path.isdir(os.path.join(options.root, '.svn')):
change_class = SvnChange
if not options.files:
if args:
......@@ -1100,10 +1095,27 @@ def Main(argv):
# Grab modified files.
options.files = scm.SVN.CaptureStatus([options.root])
else:
# Doesn't seem under source control.
change_class = Change
is_git = os.path.isdir(os.path.join(options.root, '.git'))
if not is_git:
is_git = (0 == subprocess.call(
['git', 'rev-parse', '--show-cdup'],
stdout=subprocess.PIPE, cwd=options.root))
if is_git:
# Only look at the subdirectories below cwd.
change_class = GitChange
if not options.files:
if args:
options.files = ParseFiles(args, options.recursive)
else:
# Grab modified files.
options.files = scm.GIT.CaptureStatus([options.root])
else:
logging.info('Doesn\'t seem under source control.')
change_class = Change
if options.verbose:
if len(options.files) != 1:
if not options.files:
print "Found no files."
elif len(options.files) != 1:
print "Found %d files." % len(options.files)
else:
print "Found 1 file."
......
......@@ -596,11 +596,14 @@ def CheckChangeOnCommit(input_api, output_api):
self.UnMock(presubmit.os.path, 'exists')
self.mox.StubOutWithMock(presubmit, 'DoPresubmitChecks')
self.mox.StubOutWithMock(presubmit, 'ParseFiles')
presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.git')
).AndReturn(False)
presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.svn')
).AndReturn(False)
#presubmit.ParseFiles([], None).AndReturn([])
presubmit.os.path.isdir(presubmit.os.path.join(self.fake_root_dir, '.git')
).AndReturn(False)
presubmit.subprocess.call(
['git', 'rev-parse', '--show-cdup'],
cwd=self.fake_root_dir,
stdout=presubmit.subprocess.PIPE).AndReturn(1)
presubmit.DoPresubmitChecks(mox.IgnoreArg(), False, False,
mox.IgnoreArg(),
mox.IgnoreArg(),
......
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