@contextmanager
def initialize_repo(worktree):
  gitdir = safe_mkdtemp()
  with environment_as(GIT_DIR=gitdir, GIT_WORK_TREE=worktree):
    subprocess.check_call(['git', 'init'])
    subprocess.check_call(['git', 'config', 'user.email', 'you@example.com'])
    subprocess.check_call(['git', 'config', 'user.name', 'Your Name'])
    subprocess.check_call(['git', 'add', '.'])
    subprocess.check_call(['git', 'commit', '-am', 'Add project files.'])

    yield Git(gitdir=gitdir, worktree=worktree)

    safe_rmtree(gitdir)
Initialize git repository for the given worktree.
dataset/ETHPy150Open pantsbuild/pants/tests/python/pants_test/testutils/git_util.py/initialize_repo