def testGetFooterChangeId(self):
   msg = '\n'.join(['whatever',
                    '',
                    'Change-Id: ignored',
                    '',  # Above is ignored because of this empty line.
                    'Change-Id: Ideadbeaf'])
   self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg))
   self.assertEqual([], git_footers.get_footer_change_id(
       'desc\nBUG=not-a-valid-footer\nChange-Id: Ixxx'))
   self.assertEqual(['Ixxx'], git_footers.get_footer_change_id(
       'desc\nBUG=not-a-valid-footer\n\nChange-Id: Ixxx'))
Exemplo n.º 2
0
 def testGetFooterChangeId(self):
   msg = '\n'.join(['whatever',
                    '',
                    'Change-Id: ignored',
                    '',  # Above is ignored because of this empty line.
                    'Change-Id: Ideadbeaf'])
   self.assertEqual(['Ideadbeaf'], git_footers.get_footer_change_id(msg))
   self.assertEqual([], git_footers.get_footer_change_id(
       'desc\nBUG=not-a-valid-footer\nChange-Id: Ixxx'))
   self.assertEqual(['Ixxx'], git_footers.get_footer_change_id(
       'desc\nBUG=not-a-valid-footer\n\nChange-Id: Ixxx'))
Exemplo n.º 3
0
    def _gerrit_upload_calls(cls,
                             description,
                             reviewers,
                             squash,
                             expected_upstream_ref='origin/refs/heads/master',
                             post_amend_description=None,
                             issue=None):
        if post_amend_description is None:
            post_amend_description = description

        calls = [
            ((['git', 'config', '--bool',
               'gerrit.squash-uploads'], ), 'false'),
        ]
        # If issue is given, then description is fetched from Gerrit instead.
        if issue is None:
            if squash:
                calls += [(([
                    'git', 'show', '--format=%B', '-s',
                    'refs/heads/git_cl_uploads/master'
                ], ), '')]
            calls += [(([
                'git', 'log', '--pretty=format:%s\n\n%b',
                'fake_ancestor_sha..HEAD'
            ], ), description)]
        if not git_footers.get_footer_change_id(description) and not squash:
            calls += [
                # DownloadGerritHook(False)
                ((False, ), ''),
                # Amending of commit message to get the Change-Id.
                (([
                    'git', 'log', '--pretty=format:%s\n\n%b',
                    'fake_ancestor_sha..HEAD'
                ], ), description),
                ((['git', 'commit', '--amend', '-m', description], ), ''),
                (([
                    'git', 'log', '--pretty=format:%s\n\n%b',
                    'fake_ancestor_sha..HEAD'
                ], ), post_amend_description)
            ]
        if squash:
            if not issue:
                # Prompting to edit description on first upload.
                calls += [
                    ((['git', 'config', 'core.editor'], ), ''),
                    ((['RunEditor'], ), description),
                ]
            ref_to_push = 'abcdef0123456789'
            calls += [
                ((['git', 'config',
                   'branch.master.merge'], ), 'refs/heads/master'),
                ((['git', 'config', 'branch.master.remote'], ), 'origin'),
                ((['get_or_create_merge_base', 'master',
                   'master'], ), 'origin/master'),
                ((['git', 'rev-parse', 'HEAD:'], ), '0123456789abcdef'),
                (([
                    'git', 'commit-tree', '0123456789abcdef', '-p',
                    'origin/master', '-m', description
                ], ), ref_to_push),
            ]
        else:
            ref_to_push = 'HEAD'

        calls += [
            ((['git', 'rev-list',
               expected_upstream_ref + '..' + ref_to_push], ), ''),
            ((['git', 'config', 'rietveld.cc'], ), '')
        ]
        receive_pack = '--receive-pack=git receive-pack '
        receive_pack += '[email protected]'  # from watch list
        if reviewers:
            receive_pack += ' '
            receive_pack += ' '.join('--reviewer=' + email
                                     for email in sorted(reviewers))
        receive_pack += ''
        calls += [
            (([
                'git', 'push', receive_pack, 'origin',
                ref_to_push + ':refs/for/refs/heads/master'
            ], ),
             ('remote:\n'
              'remote: Processing changes: (\)\n'
              'remote: Processing changes: (|)\n'
              'remote: Processing changes: (/)\n'
              'remote: Processing changes: (-)\n'
              'remote: Processing changes: new: 1 (/)\n'
              'remote: Processing changes: new: 1, done\n'
              'remote:\n'
              'remote: New Changes:\n'
              'remote:   https://chromium-review.googlesource.com/123456 XXX.\n'
              'remote:\n'
              'To https://chromium.googlesource.com/yyy/zzz\n'
              ' * [new branch]      hhhh -> refs/for/refs/heads/master\n')),
        ]
        if squash:
            calls += [
                ((['git', 'config', 'branch.master.gerritissue',
                   '123456'], ), ''),
                ((['git', 'config', 'branch.master.gerritserver'], ), ''),
                ((['git', 'config', 'remote.origin.url'], ),
                 'https://chromium.googlesource.com/my/repo.git'),
                (([
                    'git', 'config', 'branch.master.gerritserver',
                    'https://chromium-review.googlesource.com'
                ], ), ''),
                (([
                    'git', 'config', 'branch.master.gerritsquashhash',
                    'abcdef0123456789'
                ], ), ''),
            ]
        calls += cls._git_post_upload_calls()
        return calls
Exemplo n.º 4
0
  def _gerrit_upload_calls(cls, description, reviewers, squash,
                           expected_upstream_ref='origin/refs/heads/master',
                           post_amend_description=None, issue=None):
    if post_amend_description is None:
      post_amend_description = description

    calls = [
        ((['git', 'config', '--bool', 'gerrit.squash-uploads'],), 'false'),
    ]
    # If issue is given, then description is fetched from Gerrit instead.
    if issue is None:
      if squash:
        calls += [
          ((['git', 'show', '--format=%B', '-s',
             'refs/heads/git_cl_uploads/master'],), '')]
      calls += [
          ((['git', 'log', '--pretty=format:%s\n\n%b',
                   'fake_ancestor_sha..HEAD'],),
                  description)]
    if not git_footers.get_footer_change_id(description) and not squash:
      calls += [
          # DownloadGerritHook(False)
          ((False, ),
            ''),
          # Amending of commit message to get the Change-Id.
          ((['git', 'log', '--pretty=format:%s\n\n%b',
             'fake_ancestor_sha..HEAD'],),
           description),
          ((['git', 'commit', '--amend', '-m', description],),
           ''),
          ((['git', 'log', '--pretty=format:%s\n\n%b',
             'fake_ancestor_sha..HEAD'],),
           post_amend_description)
          ]
    if squash:
      if not issue:
        # Prompting to edit description on first upload.
        calls += [
            ((['git', 'config', 'core.editor'],), ''),
            ((['RunEditor'],), description),
        ]
      ref_to_push = 'abcdef0123456789'
      calls += [
          ((['git', 'config', 'branch.master.merge'],),
           'refs/heads/master'),
          ((['git', 'config', 'branch.master.remote'],),
           'origin'),
          ((['get_or_create_merge_base', 'master', 'master'],),
           'origin/master'),
          ((['git', 'rev-parse', 'HEAD:'],),
           '0123456789abcdef'),
          ((['git', 'commit-tree', '0123456789abcdef', '-p',
             'origin/master', '-m', description],),
           ref_to_push),
          ]
    else:
      ref_to_push = 'HEAD'

    calls += [
        ((['git', 'rev-list',
            expected_upstream_ref + '..' + ref_to_push],), ''),
        ((['git', 'config', 'rietveld.cc'],), '')
        ]
    receive_pack = '--receive-pack=git receive-pack '
    receive_pack += '[email protected]'  # from watch list
    if reviewers:
      receive_pack += ' '
      receive_pack += ' '.join(
          '--reviewer=' + email for email in sorted(reviewers))
    receive_pack += ''
    calls += [
        ((['git',
           'push', receive_pack, 'origin',
           ref_to_push + ':refs/for/refs/heads/master'],),
         ('remote:\n'
         'remote: Processing changes: (\)\n'
         'remote: Processing changes: (|)\n'
         'remote: Processing changes: (/)\n'
         'remote: Processing changes: (-)\n'
         'remote: Processing changes: new: 1 (/)\n'
         'remote: Processing changes: new: 1, done\n'
         'remote:\n'
         'remote: New Changes:\n'
         'remote:   https://chromium-review.googlesource.com/123456 XXX.\n'
         'remote:\n'
         'To https://chromium.googlesource.com/yyy/zzz\n'
         ' * [new branch]      hhhh -> refs/for/refs/heads/master\n')),
        ]
    if squash:
      calls += [
          ((['git', 'config', 'branch.master.gerritissue', '123456'],), ''),
          ((['git', 'config', 'branch.master.gerritserver'],), ''),
          ((['git', 'config', 'remote.origin.url'],),
            'https://chromium.googlesource.com/my/repo.git'),
          ((['git', 'config', 'branch.master.gerritserver',
          'https://chromium-review.googlesource.com'],), ''),
          ((['git', 'config', 'branch.master.gerritsquashhash',
             'abcdef0123456789'],), ''),
          ]
    calls += cls._git_post_upload_calls()
    return calls