Exemple #1
0
 def testFileRead_Bytes(self):
     with gclient_utils.temporary_file() as tmp:
         gclient_utils.FileWrite(tmp,
                                 b'foo \xe2\x9c bar',
                                 mode='wb',
                                 encoding=None)
         self.assertEqual('foo \ufffd bar', gclient_utils.FileRead(tmp))
Exemple #2
0
def UploadCl(refactor_branch, refactor_branch_upstream, directory, files,
             description, comment, reviewers, changelist, cmd_upload,
             cq_dry_run, enable_auto_submit):
    """Uploads a CL with all changes to |files| in |refactor_branch|.

  Args:
    refactor_branch: Name of the branch that contains the changes to upload.
    refactor_branch_upstream: Name of the upstream of |refactor_branch|.
    directory: Path to the directory that contains the OWNERS file for which
        to upload a CL.
    files: List of AffectedFile instances to include in the uploaded CL.
    description: Description of the uploaded CL.
    comment: Comment to post on the uploaded CL.
    reviewers: A set of reviewers for the CL.
    changelist: The Changelist class.
    cmd_upload: The function associated with the git cl upload command.
    cq_dry_run: If CL uploads should also do a cq dry run.
    enable_auto_submit: If CL uploads should also enable auto submit.
  """
    # Create a branch.
    if not CreateBranchForDirectory(refactor_branch, directory,
                                    refactor_branch_upstream):
        print('Skipping ' + directory + ' for which a branch already exists.')
        return

    # Checkout all changes to files in |files|.
    deleted_files = [f.AbsoluteLocalPath() for f in files if f.Action() == 'D']
    if deleted_files:
        git.run(*['rm'] + deleted_files)
    modified_files = [
        f.AbsoluteLocalPath() for f in files if f.Action() != 'D'
    ]
    if modified_files:
        git.run(*['checkout', refactor_branch, '--'] + modified_files)

    # Commit changes. The temporary file is created with delete=False so that it
    # can be deleted manually after git has read it rather than automatically
    # when it is closed.
    with gclient_utils.temporary_file() as tmp_file:
        gclient_utils.FileWrite(
            tmp_file, FormatDescriptionOrComment(description, directory))
        git.run('commit', '-F', tmp_file)

    # Upload a CL.
    upload_args = ['-f', '-r', ','.join(reviewers)]
    if cq_dry_run:
        upload_args.append('--cq-dry-run')
    if not comment:
        upload_args.append('--send-mail')
    if enable_auto_submit:
        upload_args.append('--enable-auto-submit')
    print('Uploading CL for ' + directory + '.')
    cmd_upload(upload_args)
    if comment:
        changelist().AddComment(FormatDescriptionOrComment(comment, directory),
                                publish=True)
    def testIgnoreFile(self):
        """Tests passing the ignore list in a file."""
        expected_output = [
            self.blame_line('C', ' 1) line 1.1'),
            self.blame_line('A', '2*) line 2.1')
        ]
        outbuf = BytesIO()

        with gclient_utils.temporary_file() as ignore_file:
            gclient_utils.FileWrite(
                ignore_file, '# Line comments are allowed.\n'
                '\n'
                '{}\n'
                'xxxx\n'.format(self.repo['B']))
            retval = self.repo.run(
                self.git_hyper_blame.main,
                ['--ignore-file', ignore_file, 'tag_C', 'some/files/file'],
                outbuf)

        self.assertEqual(0, retval)
        self.assertEqual(expected_output,
                         outbuf.getvalue().rstrip().split(b'\n'))
        self.assertEqual('warning: unknown revision \'xxxx\'.\n',
                         sys.stderr.getvalue())
Exemple #4
0
 def testToJson(self):
     with gclient_utils.temporary_file() as tmp:
         self.assertEqual(git_footers.main(['--json', tmp]), 0)
         with open(tmp) as f:
             js = json.load(f)
     self.assertEqual(js, {'Foo': ['3', '1'], 'Bar': ['2']})
Exemple #5
0
 def testTemporaryFile(self):
     with gclient_utils.temporary_file() as tmp:
         gclient_utils.FileWrite(tmp, 'test')
         self.assertEqual('test', gclient_utils.FileRead(tmp))
     self.assertFalse(os.path.exists(tmp))
Exemple #6
0
 def testFileRead_Unicode(self):
     with gclient_utils.temporary_file() as tmp:
         gclient_utils.FileWrite(tmp, 'foo ✔ bar')
         self.assertEqual('foo ✔ bar', gclient_utils.FileRead(tmp))