def test_integrate_hook_with_io(repo: Repo): hook = Hook("test-hook", repo_path(repo)) io = FileIO() assert not io.exists(hook.path) hook.install(io) assert io.exists(hook.path)
def test_register_git_hooks(repo: Repo): path = hooks_path(repo_path(repo)) for hook in HOOKS: install_hook(hook, repo_path(repo)) with os.scandir(path) as entries: assert hooks_ok(entries) stage_tmp_file(repo) # Not using capture_output due to 3.6 support result = subprocess.run( ["git", "commit", "-m", "test"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=repo_path(repo), ) assert result.returncode == 0
def test_init_configures_env_from_scratch(repo: GitRepository): """ Test init command creates the default config file. Context -> a -> Assertion -> TestResult () """ path = repo_path(repo) runner = CliRunner() result = runner.invoke(cli, ["--path", path, "init"]) assert result.exit_code == 0, result.exception with open(config_path(path)) as f: config = yaml.safe_load(f) assert config == DEFAULT_CONF with os.scandir(hooks_path(path)) as entries: assert hooks_ok(entries)
def list_files_since_last_push(repo: git.Repo) -> List[str]: if repo.active_branch.tracking_branch(): diff = repo.git.diff("@{push}..HEAD", name_status=True) else: diff = repo.git.diff("master..HEAD", name_status=True) return git_files_to_path(repo_path(repo), parse_diff(diff))
def list_staged_files(repo: git.Repo) -> List[str]: """List staged files in git.""" diff = repo.git.diff(name_status=True, staged=True) return git_files_to_path(repo_path(repo), parse_diff(diff))