Ejemplo n.º 1
0
def _exportable_commits_since(chromium_commit_hash, host, local_wpt, wpt_github,
                              require_clean=True, verify_merged_pr=False):
    """Lists exportable commits after the given commit.

    Args:
        chromium_commit_hash: The SHA of the Chromium commit from which this
            method will look. This commit is not included in the commits searched.

    Return values and remaining arguments are the same as exportable_commits_over_last_n_commits.
    """
    chromium_repo_root = host.executive.run_command([
        'git', 'rev-parse', '--show-toplevel'
    ], cwd=absolute_chromium_dir(host)).strip()

    wpt_path = chromium_repo_root + '/' + CHROMIUM_WPT_DIR
    commit_range = '{}..HEAD'.format(chromium_commit_hash)
    skipped_revs = ['^' + rev for rev in SKIPPED_REVISIONS]
    command = ['git', 'rev-list', commit_range] + skipped_revs + ['--reverse', '--', wpt_path]
    commit_hashes = host.executive.run_command(command, cwd=absolute_chromium_dir(host)).splitlines()
    chromium_commits = [ChromiumCommit(host, sha=sha) for sha in commit_hashes]
    exportable_commits = []
    errors = []
    for commit in chromium_commits:
        state, error = get_commit_export_state(commit, local_wpt, wpt_github, verify_merged_pr)
        if require_clean:
            success = state == CommitExportState.EXPORTABLE_CLEAN
        else:
            success = state in (CommitExportState.EXPORTABLE_CLEAN, CommitExportState.EXPORTABLE_DIRTY)
        if success:
            exportable_commits.append(commit)
        elif error != '':
            errors.append('The following commit did not apply cleanly:\nSubject: %s (%s)\n%s' %
                          (commit.subject(), commit.url(), error))
    return exportable_commits, errors
Ejemplo n.º 2
0
    def test_derives_sha_from_position(self):
        host = MockHost()
        host.executive = MockExecutive(output='c881563d734a86f7d9cd57ac509653a61c45c240')
        pos = 'Cr-Commit-Position: refs/heads/master@{#789}'
        chromium_commit = ChromiumCommit(host, position=pos)

        self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
Ejemplo n.º 3
0
    def test_derives_position_from_sha(self):
        host = MockHost()
        host.executive = mock_git_commands({
            'footers': 'refs/heads/master@{#789}'
        })
        chromium_commit = ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240')

        self.assertEqual(chromium_commit.position, 'refs/heads/master@{#789}')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
Ejemplo n.º 4
0
    def test_filtered_changed_files_blacklist(self):
        host = MockHost()

        fake_files = ['file1', 'MANIFEST.json', 'file3', 'OWNERS']
        qualified_fake_files = [CHROMIUM_WPT_DIR + f for f in fake_files]

        host.executive = mock_git_commands({
            'diff-tree': '\n'.join(qualified_fake_files),
            'crrev-parse': 'c881563d734a86f7d9cd57ac509653a61c45c240',
        })

        position_footer = 'Cr-Commit-Position: refs/heads/master@{#789}'
        chromium_commit = ChromiumCommit(host, position=position_footer)

        files = chromium_commit.filtered_changed_files()

        expected_files = ['file1', 'file3']
        qualified_expected_files = [CHROMIUM_WPT_DIR + f for f in expected_files]

        self.assertEqual(files, qualified_expected_files)
Ejemplo n.º 5
0
    def test_when_commit_has_no_position(self):
        host = MockHost()

        def run_command(_):
            raise ScriptError('Unable to infer commit position from footers rutabaga')

        host.executive = MockExecutive(run_command_fn=run_command)
        chromium_commit = ChromiumCommit(host, sha='c881563d734a86f7d9cd57ac509653a61c45c240')

        self.assertEqual(chromium_commit.position, 'no-commit-position-yet')
        self.assertEqual(chromium_commit.sha, 'c881563d734a86f7d9cd57ac509653a61c45c240')
Ejemplo n.º 6
0
    def fetch_current_revision_commit(self, host):
        """Fetches the git commit for the latest revision of CL.

        This method fetches the commit corresponding to the latest revision of
        CL to local Chromium repository, but does not checkout the commit to the
        working tree. All changes in the CL are squashed into this one commit,
        regardless of how many revisions have been uploaded.

        Args:
            host: A Host object for git invocation.

        Returns:
            A ChromiumCommit object (the fetched commit).
        """
        git = host.git(absolute_chromium_dir(host))
        url = self.current_revision['fetch']['http']['url']
        ref = self.current_revision['fetch']['http']['ref']
        git.run(['fetch', url, ref])
        sha = git.run(['rev-parse', 'FETCH_HEAD']).strip()
        return ChromiumCommit(host, sha=sha)
Ejemplo n.º 7
0
 def test_url(self):
     chromium_commit = ChromiumCommit(
         MockHost(), sha='c881563d734a86f7d9cd57ac509653a61c45c240')
     self.assertEqual(
         chromium_commit.url(),
         'https://chromium.googlesource.com/chromium/src/+/c881563d73')
Ejemplo n.º 8
0
 def test_short_sha(self):
     chromium_commit = ChromiumCommit(
         MockHost(), sha='c881563d734a86f7d9cd57ac509653a61c45c240')
     self.assertEqual(chromium_commit.short_sha, 'c881563d73')
Ejemplo n.º 9
0
 def test_validates_sha(self):
     with self.assertRaises(AssertionError):
         ChromiumCommit(MockHost(), sha='rutabaga')