def testRawDiff(self): """Test the parsing of the git.RawDiff function.""" diff_output = """ :100644 100644 ac234b2... 077d1f8... M\tchromeos-base/chromeos-chrome/Manifest :100644 100644 9e5d11b... 806bf9b... R099\tchromeos-base/chromeos-chrome/chromeos-chrome-40.0.2197.0_rc-r1.ebuild\tchromeos-base/chromeos-chrome/chromeos-chrome-40.0.2197.2_rc-r1.ebuild :100644 100644 70d6e94... 821c642... M\tchromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild :100644 100644 be445f9... be445f9... R100\tchromeos-base/chromium-source/chromium-source-40.0.2197.0_rc-r1.ebuild\tchromeos-base/chromium-source/chromium-source-40.0.2197.2_rc-r1.ebuild """ result = cros_build_lib.CommandResult(output=diff_output) self.PatchObject(git, 'RunGit', return_value=result) entries = git.RawDiff('foo', 'bar') self.assertEqual( entries, [('100644', '100644', 'ac234b2', '077d1f8', 'M', None, 'chromeos-base/chromeos-chrome/Manifest', None), ('100644', '100644', '9e5d11b', '806bf9b', 'R', '099', 'chromeos-base/chromeos-chrome/' 'chromeos-chrome-40.0.2197.0_rc-r1.ebuild', 'chromeos-base/chromeos-chrome/' 'chromeos-chrome-40.0.2197.2_rc-r1.ebuild'), ('100644', '100644', '70d6e94', '821c642', 'M', None, 'chromeos-base/chromeos-chrome/chromeos-chrome-9999.ebuild', None), ('100644', '100644', 'be445f9', 'be445f9', 'R', '100', 'chromeos-base/chromium-source/' 'chromium-source-40.0.2197.0_rc-r1.ebuild', 'chromeos-base/chromium-source/' 'chromium-source-40.0.2197.2_rc-r1.ebuild')])
def __init__(self, ebuild_dir, before=None): """Construct a Chrome uprev object Args: ebuild_dir: Path to the directory with the chrome ebuild in it. before: CL to work backwards from. """ # Format includes the hash, commit body including subject, and author date. cmd = [ 'log', '-n', '1', '--author', 'chrome-bot', '--grep', cros_mark_as_stable.GIT_COMMIT_SUBJECT, '--format=format:%H%n%aD%n%B' ] if before: cmd.append(str(before) + '~') cmd.append('.') log = git.RunGit(ebuild_dir, cmd).output if not log.strip(): raise UprevNotFound('No uprev CL was found') self.sha, _, log = log.partition('\n') self.date, _, message = log.partition('\n') self.conf_files = [m.group('conf') for m in CONF_RE.finditer(message)] entries = git.RawDiff(ebuild_dir, '%s^!' % self.sha) for entry in entries: if entry.status != 'R': continue from_path = entry.src_file to_path = entry.dst_file if (os.path.splitext(from_path)[1] != '.ebuild' or os.path.splitext(to_path)[1] != '.ebuild'): continue self.from_parts = SplitPVPath(from_path) self.to_parts = SplitPVPath(to_path) if (self.from_parts.package != 'chromeos-chrome' or self.to_parts.package != 'chromeos-chrome'): continue break else: raise Exception('Failed to find chromeos-chrome uprev in CL %s' % self.sha)
def testEmptyDiff(self): """Verify an empty diff doesn't crash.""" result = cros_build_lib.CommandResult(output='\n') self.PatchObject(git, 'RunGit', return_value=result) entries = git.RawDiff('foo', 'bar') self.assertEqual([], entries)