Esempio n. 1
0
def _check_repo_ignoring_attributes(args, repo_config):
    """Return False if the supplied repo isn't ignoring attributes config.

    Will print details of errors found. Will continue when errors are found,
    unless they interfere with the operation of fsck.

    :args: argeparse arguments to arcyd fsck
    :repo_config: argparse namespace of the repo's config
    :returns: True or False

    """
    all_ok = True
    is_ignoring = phlgitx_ignoreattributes.is_repo_definitely_ignoring
    if not is_ignoring(repo_config.repo_path):
        print("'{}' is not ignoring some attributes".format(
            repo_config.repo_path))
        if args.fix:
            print("setting {} to ignore some attributes ..".format(
                repo_config.repo_path))

            phlgitx_ignoreattributes.ensure_repo_ignoring(
                repo_config.repo_path)
        else:
            all_ok = False

    return all_ok
    def test_B_WorkaroundSpuriousIdentDiff(self):
        ident_filename = 'ident_file'
        linked_workers = phlgitu_fixture.CentralisedWithTwoWorkers()
        with contextlib.closing(linked_workers):

            w0 = linked_workers.w0
            w1 = linked_workers.w1

            ident_path = os.path.join(w0.repo.working_dir, ident_filename)

            # commit a pre-expanded file
            w0.commit_new_file(
                message='add ident, erroneously expanded already',
                relative_path=ident_filename,
                contents='$Id: already expanded, whoops! $')

            # enable ident expansion
            w0.commit_new_file(
                message='add .gitattributes, enable ident',
                relative_path='.gitattributes',
                contents='* ident\n')

            # checkout onto a new branch to fix the ident
            w0.repo("checkout", "-b", "fix_ident")
            phlsys_fs.write_text_file(ident_path, "$Id$")

            w0.repo('commit', '-am', 'fix {}'.format(ident_filename))

            # push both branches back to share with 'w1'
            w0.repo('push', 'origin', 'master:master', 'fix_ident')

            w1.repo('fetch', 'origin')
            w1.repo('checkout', 'origin/master')

            def checkout_fix_ident():
                w1.repo('checkout', 'origin/fix_ident')

            # An error will be raised here, as the ident file will appear to
            # have been modified.
            self.assertRaises(
                phlsys_subprocess.CalledProcessError,
                checkout_fix_ident)

            # work around the problem, by ignoring the ident setting
            phlgitx_ignoreattributes.ensure_repo_ignoring(w1.repo.working_dir)

            # try to checkout back to the branch with the fix
            checkout_fix_ident()
    def test_C_WorkaroundSpuriousEolDiff(self):
        badeol_filename = 'badeol_file'
        linked_workers = phlgitu_fixture.CentralisedWithTwoWorkers()
        with contextlib.closing(linked_workers):

            w0 = linked_workers.w0
            w1 = linked_workers.w1

            badeol_path = os.path.join(w0.repo.working_dir, badeol_filename)

            # commit a bad eol file
            w0.commit_new_file(
                message='add file, bad line endings',
                relative_path=badeol_filename,
                contents='windows line ending, whoops!\r\n')

            # enable eol conversion
            w0.commit_new_file(
                message='add .gitattributes, set eol to unix',
                relative_path='.gitattributes',
                contents='* eol=lf\n')

            # checkout onto a new branch to fix the line ending
            w0.repo("checkout", "-b", "fix_badeol")
            phlsys_fs.write_text_file(badeol_path, "good ending\n")

            w0.repo('commit', '-am', 'fix {}'.format(badeol_filename))

            # push both branches back to share with 'w1'
            w0.repo('push', 'origin', 'master:master', 'fix_badeol')

            w1.repo('fetch', 'origin')
            w1.repo('checkout', 'origin/master')

            def checkout_fix_badeol():
                w1.repo('checkout', 'origin/fix_badeol')

            # An error will be raised here, as the badeol file will appear to
            # have been modified.
            self.assertRaises(
                phlsys_subprocess.CalledProcessError,
                checkout_fix_badeol)

            # work around the problem, by ignoring the badeol setting
            phlgitx_ignoreattributes.ensure_repo_ignoring(w1.repo.working_dir)

            # try to checkout back to the branch with the fix
            checkout_fix_badeol()
    def test_A_Breathing(self):
        with phlgitu_fixture.lone_worker_context() as worker:

            self.assertFalse(
                phlgitx_ignoreattributes.is_repo_definitely_ignoring(
                    worker.repo.working_dir))

            phlgitx_ignoreattributes.ensure_repo_ignoring(
                worker.repo.working_dir)

            self.assertTrue(
                phlgitx_ignoreattributes.is_repo_definitely_ignoring(
                    worker.repo.working_dir))

            phlgitx_ignoreattributes.ensure_repo_ignoring(
                worker.repo.working_dir)
Esempio n. 5
0
def setup_repo_context(repo_url, repo_path, repo_push_url=None):
    """Setup a repository, if an exception is raised then remove the repo.

    :repo_url: string url of the repo to clone
    :repo_path: string path to clone the repo to
    :repo_push_url: string url to push to, or None
    :returns: None

    """
    # if there's any failure after cloning then we should remove the repo
    if repo_push_url is not None:
        phlsys_subprocess.run(
            'git', 'clone', repo_url, repo_path,
            '--config', 'remote.origin.pushurl=' + repo_push_url)
    else:
        phlsys_subprocess.run(
            'git', 'clone', repo_url, repo_path)

    try:
        repo = phlsys_git.Repo(repo_path)

        # make sure we have no problems with 'ident' strings, we won't build
        # from arcyd so it shouldn't be externally visible that we don't expand
        # them.
        phlgitx_ignoreattributes.ensure_repo_ignoring(repo_path)

        # test pushing to master
        repo('checkout', 'origin/master')
        phlgit_commit.allow_empty(repo, 'test commit for pushing')
        repo('push', 'origin', '--dry-run', 'HEAD:refs/heads/master')
        repo('checkout', '-')

        try_push_special_refs(repo)

        # fetch the 'landed' and 'abandoned' refs if they exist
        abdt_git.checkout_master_fetch_special_refs(repo, 'origin')

        ensure_reserve_branch(repo)

        # success, allow the caller to do work
        yield
    except Exception:
        # clean up the git repo on any exception
        shutil.rmtree(repo_path)
        raise
Esempio n. 6
0
def setup_repo_context(repo_url, repo_path, repo_push_url=None):
    """Setup a repository, if an exception is raised then remove the repo.

    :repo_url: string url of the repo to clone
    :repo_path: string path to clone the repo to
    :repo_push_url: string url to push to, or None
    :returns: None

    """
    # if there's any failure after cloning then we should remove the repo
    if repo_push_url is not None:
        phlsys_subprocess.run('git', 'clone', repo_url, repo_path, '--config',
                              'remote.origin.pushurl=' + repo_push_url)
    else:
        phlsys_subprocess.run('git', 'clone', repo_url, repo_path)

    try:
        repo = phlsys_git.Repo(repo_path)

        # make sure we have no problems with 'ident' strings, we won't build
        # from arcyd so it shouldn't be externally visible that we don't expand
        # them.
        phlgitx_ignoreattributes.ensure_repo_ignoring(repo_path)

        # test pushing to master
        repo('checkout', 'origin/master')
        phlgit_commit.allow_empty(repo, 'test commit for pushing')
        repo('push', 'origin', '--dry-run', 'HEAD:refs/heads/master')
        repo('checkout', '-')

        try_push_special_refs(repo)

        # fetch the 'landed' and 'abandoned' refs if they exist
        abdt_git.checkout_master_fetch_special_refs(repo, 'origin')

        ensure_reserve_branch(repo)

        # success, allow the caller to do work
        yield
    except Exception:
        # clean up the git repo on any exception
        shutil.rmtree(repo_path)
        raise
    def test_D_UpdateInfoAttributes(self):

        all_attributes = list(phlgitx_ignoreattributes._REPO_ATTRIBUTES_TUPLE)
        all_attributes.append("")

        all_lines = itertools.combinations(
            all_attributes,
            len(all_attributes) - 1)

        for lines in all_lines:

            content = "\n".join(lines)
            print(content)
            print("---")
            with phlgitu_fixture.lone_worker_context() as worker:

                working_dir = worker.repo.working_dir
                attributes_path = os.path.join(
                    working_dir, '.git/info/attributes')
                phlsys_fs.write_text_file(attributes_path, content)

                # should not throw
                phlgitx_ignoreattributes.ensure_repo_ignoring(
                    worker.repo.working_dir)