def _check_repo_ignoring_ident(args, repo_config): """Return False if the supplied repo isn't ignoring ident 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_ignoreident.is_repo_definitely_ignoring if not is_ignoring(repo_config.repo_path): print "'{}' is not ignoring ident attributes".format( repo_config.repo_path) if args.fix: print "setting {} to ignore ident ..".format( repo_config.repo_path) phlgitx_ignoreident.ensure_repo_ignoring( repo_config.repo_path) else: all_ok = False return all_ok
def test_B_WorkaroundSpuriousDiff(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_ignoreident.ensure_repo_ignoring(w1.repo.working_dir) # try to checkout back to the branch with the fix checkout_fix_ident()
def test_A_Breathing(self): with phlgitu_fixture.lone_worker_context() as worker: self.assertFalse( phlgitx_ignoreident.is_repo_definitely_ignoring( worker.repo.working_dir)) phlgitx_ignoreident.ensure_repo_ignoring( worker.repo.working_dir) self.assertTrue( phlgitx_ignoreident.is_repo_definitely_ignoring( worker.repo.working_dir)) phlgitx_ignoreident.ensure_repo_ignoring( worker.repo.working_dir)
def process(args): fs = abdt_fs.make_default_accessor() exit_code = 0 with fs.lockfile_context(): for repo in fs.repo_config_path_list(): parser = argparse.ArgumentParser(fromfile_prefix_chars='@') abdi_repoargs.setup_parser(parser) with open(repo) as f: repo_params = parser.parse_args( line.strip() for line in f) if not os.path.isdir(repo_params.repo_path): print "'{}' is missing repo '{}'".format( repo, repo_params.repo_path) if args.fix: repo_url = abdi_repoargs.get_repo_url(repo_params) print "cloning '{}' ..".format(repo_url) abdi_repo.setup_repo(repo_url, repo_params.repo_path) else: exit_code = 1 else: is_ignoring = phlgitx_ignoreident.is_repo_definitely_ignoring if not is_ignoring(repo_params.repo_path): print "'{}' is not ignoring ident attributes".format( repo_params.repo_path) if args.fix: print "setting {} to ignore ident ..".format( repo_params.repo_path) phlgitx_ignoreident.ensure_repo_ignoring( repo_params.repo_path) else: exit_code = 1 if exit_code != 0 and not args.fix: print "use '--fix' to attempt to fix the issues" return exit_code
def setup_repo_context(repo_url, repo_path): """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 :returns: None """ # if there's any failure after cloning then we should remove the repo 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_ignoreident.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', '-') # test push to special refs repo('push', 'origin', '--dry-run', 'HEAD:refs/arcyd/test') repo('push', 'origin', '--dry-run', 'HEAD:refs/heads/dev/arcyd/test') # fetch the 'landed' and 'abandoned' refs if they exist abdt_git.checkout_master_fetch_special_refs(repo, 'origin') # success, allow the caller to do work yield except Exception: # clean up the git repo on any exception shutil.rmtree(repo_path) raise