def setUp(self): self.tempdir = TemporaryDirectory() self.temp_path = Path(self.tempdir.name) exec_git('-C', str(self.temp_path), 'init') self.git_dir_path = self.temp_path / '.git' self.assertTrue(self.git_dir_path.exists())
def test_with_env_pwd(self): with TemporaryDirectory() as f: temp_path = Path(f) exec_git('-C', str(temp_path), 'init') os.environ['PWD'] = str(temp_path) git_dir_path = temp_path / '.git' git_hook_dir_path = get_git_hook_directory_path() self.assertEqual(git_hook_dir_path, git_dir_path / 'hooks')
def test_with_env_pwd(self): with TemporaryDirectory() as f: temp_path = Path(f) exec_git('-C', str(temp_path), 'init') os.chdir(str(temp_path)) git_dir_path = (temp_path / '.git').resolve() git_hook_dir_path = get_git_hook_directory_path() self.assertEqual(git_hook_dir_path, git_dir_path / 'hooks')
def _apply_diff(patch: bytes) -> None: with NamedTemporaryFile(mode='wb', buffering=0) as f: f.write(patch) exec_git( 'apply', '-v', '--whitespace=nowarn', '--reject', '--recount', '--unidiff-zero', f.name, )
def _get_git_toplevel_path(): try: git_dir = exec_git('rev-parse', '--show-toplevel').rstrip() except subprocess.CalledProcessError as e: print('could not determine toplevel directory. {e.output.decode()}') raise e from None return Path(git_dir).resolve()
def get_diff(files: List[StatusEntry] = None) -> str: args = ['--no-pager', 'diff'] if files is not None: args.append('--') args.extend([str(f.absolute_path()) for f in files]) return exec_git(*args)
def get_diff(files=None): args = [ '--no-pager', 'diff', ] if files is not None: args.append('--') args.extend([str(f.absolute_path()) for f in files]) return exec_git(*args)
def get_status(files: List[Union[Path, str]] = None) -> List[StatusEntry]: args = [ 'status', '--porcelain=v1', '-z', '--ignore-submodules', '--untracked-files=no', ] if files is not None: args.append('--') args.extend([str(f) for f in files]) output = exec_git(*args) root_path = _get_git_toplevel_path() return [StatusEntry(f, root_path) for f in _parse_status(output)]
def _set_ref(name: str, hashid: str) -> None: exec_git('update-ref', name, hashid)
def _checkout_from_index(status_list: List[StatusEntry]) -> None: filenames = [str(s.path) for s in status_list] exec_git('checkout-index', '-f', '--', *filenames)
def _read_tree(ref_or_hashid: str) -> None: exec_git('read-tree', ref_or_hashid)
def _write_tree() -> str: return exec_git('write-tree').strip()
def stage_files_from_status_list(status_list: List[StatusEntry]) -> None: filenames = [str(s.path) for s in status_list] exec_git('add', *filenames)
def stage_files_from_status_list(status_list): filenames = [str(s.path) for s in status_list] exec_git('add', *filenames)
def _read_tree(ref_or_hashid): exec_git('read-tree', ref_or_hashid)
def _checkout_from_index(status_list): filenames = [str(s.path) for s in status_list] exec_git('checkout-index', '-f', '--', *filenames)
def _set_ref(name, hashid): exec_git('update-ref', name, hashid)