Пример #1
0
    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())
Пример #2
0
    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')
Пример #3
0
    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')
Пример #4
0
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,
        )
Пример #5
0
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()
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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)]
Пример #9
0
def _set_ref(name: str, hashid: str) -> None:
    exec_git('update-ref', name, hashid)
Пример #10
0
def _checkout_from_index(status_list: List[StatusEntry]) -> None:
    filenames = [str(s.path) for s in status_list]
    exec_git('checkout-index', '-f', '--', *filenames)
Пример #11
0
def _read_tree(ref_or_hashid: str) -> None:
    exec_git('read-tree', ref_or_hashid)
Пример #12
0
def _write_tree() -> str:
    return exec_git('write-tree').strip()
Пример #13
0
def stage_files_from_status_list(status_list: List[StatusEntry]) -> None:
    filenames = [str(s.path) for s in status_list]
    exec_git('add', *filenames)
Пример #14
0
def stage_files_from_status_list(status_list):
    filenames = [str(s.path) for s in status_list]
    exec_git('add', *filenames)
Пример #15
0
def _read_tree(ref_or_hashid):
    exec_git('read-tree', ref_or_hashid)
Пример #16
0
def _checkout_from_index(status_list):
    filenames = [str(s.path) for s in status_list]
    exec_git('checkout-index', '-f', '--', *filenames)
Пример #17
0
def _set_ref(name, hashid):
    exec_git('update-ref', name, hashid)