def test_git_clone(reset_directory, remote_repository, tmp_path_factory): path = tmp_path_factory.mktemp('clone-workdir') os.chdir(path) git = git_project.Git() remote_url = 'file://' + remote_repository.path clone_path = git.clone(remote_url) assert os.path.exists(clone_path) os.chdir(clone_path) git = git_project.Git() assert git.has_repo() assert not git.is_bare_repository() path = tmp_path_factory.mktemp('bare-clone-workdir') os.chdir(path) git = git_project.Git() clone_path = git.clone(remote_url, bare=True) assert os.path.exists(clone_path) os.chdir(clone_path) git = git_project.Git() assert git.has_repo() assert git.is_bare_repository()
def test_git_worktree_subdir(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() # Create a branch for the worktree. commit, ref = git._repo.resolve_refish('HEAD') branch = git._repo.branches.create('user/test-wt', commit) worktree_checkout_path = Path.cwd() / '..' / '..' / 'user' / 'test-wt' git.add_worktree('test-wt', str(worktree_checkout_path), 'user/test-wt') worktree_path = Path(local_repository.path) / 'worktrees' / 'test-wt' assert os.path.exists(worktree_path) os.chdir(worktree_path) wtgit = git_project.Git() assert wtgit.get_current_branch() == 'user/test-wt' try: git.prune_worktree('test-wt') assert False, 'Pruned a worktree when should not have' except: pass shutil.rmtree(worktree_checkout_path) git.prune_worktree('test-wt') assert not os.path.exists('user/test-wt')
def test_git_get_current_refname(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.get_current_refname() == 'refs/heads/master'
def test_worktree_init_nomain(git, git_project_runner, tmp_path_factory): path = tmp_path_factory.mktemp('clone-workdir') os.chdir(path) clone_path = git.clone('file://' + git.get_gitdir()) os.chdir(clone_path) git = git_project.Git() workarea = git.get_working_copy_root() print(f'Workarea: {workarea}') assert os.path.exists(workarea / '.git') assert os.path.exists(workarea / 'MergedRemote.txt') git.create_branch('newmain', 'master') git.checkout('newmain') git.delete_branch('master') git_project_runner.chdir(workarea) git_project_runner.run('.*', '', 'init', '--worktree') assert os.path.exists(workarea / '.git') assert not os.path.exists(workarea / 'MergedRemote.txt') assert not os.path.exists(workarea / 'master') assert os.path.exists(workarea / 'newmain')
def test_git_is_bare_repository(reset_directory, remote_repository, local_repository): os.chdir(remote_repository.path) git = git_project.Git() assert git.has_repo() assert git.is_bare_repository() os.chdir(Path(local_repository.path) / '..') git = git_project.Git() assert git.has_repo() assert not git.is_bare_repository()
def main_impl(args=None): """The main entry point for the git-config tools.""" if not args: args = sys.argv[1:] git = git_project.Git() git.validate_config() project_name = Path(sys.argv[0]).name prefix = 'git-' if project_name.startswith(prefix): project_name = project_name[len(prefix):] plugin_manager = git_project.PluginManager() project = git_project.Project.get(git, project_name) plugin_manager.load_plugins(git, project) # Now that class hooks have been added, instantiate objects. gp = git_project.GitProject.get(git) clargs = git_project.parse_arguments(git, gp, project, plugin_manager, args) plugin_manager.initialize_plugins(git, gp, project) clargs.func(git, gp, project, clargs) git.validate_config()
def test_git_init(reset_directory, remote_repository, local_repository, tmp_path_factory): path = tmp_path_factory.mktemp('init-workdir') os.chdir(path) git = git_project.Git() assert not git.has_repo() os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git._repo.path == local_repository.path
def test_git_get_working_copy_root(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert Path(git.get_working_copy_root()) == (Path(git._repo.path) / '..').resolve()
def test_git_get_remote_push_refname(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.get_remote_push_refname('refs/heads/pushed', 'origin') == 'refs/remotes/origin/pushed'
def test_git_committish_to_refname(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.committish_to_refname('HEAD') == 'refs/heads/master'
def test_git_get_git_common_dir_worktree(reset_directory, git): git.create_branch('test', 'master') git.add_worktree('test', '../test', 'test') os.chdir('../test') git = git_project.Git() assert Path(git.get_git_common_dir()).name == '.git'
def test_git_branch_name_to_refname(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.branch_name_to_refname('master') == 'refs/heads/master' assert git.branch_name_to_refname('refs/heads/master') == 'refs/heads/master'
def test_git_refname_to_branch_name_remote(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.refname_to_branch_name('refs/remotes/origin/master') == 'origin/master' assert git.refname_to_branch_name('origin/master') == 'origin/master'
def test_git_get_committish_oid(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert (git.get_committish_oid('HEAD') == git.get_committish_oid(git.committish_to_refname('HEAD')))
def test_git_delete_remote_refname(reset_directory, local_repository, remote_repository): os.chdir(local_repository.path) local_git = git_project.Git() os.chdir(remote_repository.path) remote_git = git_project.Git() assert not local_git.committish_exists('todelete') assert not local_git.committish_exists('refs/heads/todelete') assert not remote_git.committish_exists('todelete') assert not remote_git.committish_exists('refs/heads/todelete') local_git.create_branch('todelete', 'HEAD') assert local_git.committish_exists('todelete') assert local_git.committish_exists('refs/heads/todelete') local_git._repo.remotes['origin'].push(['refs/heads/todelete']) assert remote_git.committish_exists('todelete') assert remote_git.committish_exists('refs/heads/todelete') assert local_git.committish_exists('refs/remotes/origin/todelete') local_git.delete_branch('todelete') assert not local_git.committish_exists('todelete') assert local_git.committish_exists('refs/remotes/origin/todelete') assert remote_git.committish_exists('todelete') assert remote_git.committish_exists('refs/heads/todelete') local_git.delete_remote_branch('todelete', 'origin') assert not local_git.committish_exists('refs/remotes/origin/todelete') assert not remote_git.committish_exists('todelete') assert not remote_git.committish_exists('refs/heads/todelete')
def test_git_committish_is_pushed(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.committish_is_pushed('pushed', 'origin') assert not git.committish_is_pushed('merged_local', 'origin') assert not git.committish_is_pushed('notpushed', 'origin')
def test_git_is_strict_ancestor(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.is_strict_ancestor('HEAD~', 'HEAD') assert not git.is_strict_ancestor('HEAD', 'HEAD~') assert not git.is_strict_ancestor('HEAD', 'HEAD')
def test_gitproject_get(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() gp = git_project.GitProject.get(git) projects = [name for name in gp.iternames()] assert projects == []
def test_git_committish_exists(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.committish_exists('refs/heads/master') assert git.committish_exists('master') assert not git.committish_exists('refs/heads/bogus') assert not git.committish_exists('bogus')
def test_git_get_remote_push_refname_oid(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() pushed_commit = git._repo.revparse_single('pushed') pushed_oid = pushed_commit.id assert git.get_remote_push_refname_oid('refs/heads/pushed', 'origin') == pushed_oid
def test_git_remote_branch_exists(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.remote_branch_exists('master', 'origin') assert git.remote_branch_exists('pushed', 'origin') assert git.remote_branch_exists('notpushed', 'origin') assert git.remote_branch_exists('merged_remote', 'origin') assert not git.remote_branch_exists('merged_local', 'origin') assert not git.remote_branch_exists('unmerged', 'origin')
def test_git_refname_is_merged(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() assert git.has_repo() assert git.refname_is_merged('refs/heads/merged_local', 'refs/heads/master') assert not git.refname_is_merged('refs/heads/unmerged', 'refs/heads/master') assert git.refname_is_merged('refs/heads/merged_remote', 'refs/remotes/origin/master') assert not git.refname_is_merged('refs/heads/notpushed', 'refs/remotes/origin/notpushed')
def test_git_create_branch(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() git.create_branch('testbranch', 'refs/heads/master') assert git.committish_exists('testbranch') assert git.refname_is_merged('refs/heads/testbranch', 'refs/heads/master') git.create_branch('refs/heads/weirdbranch', 'refs/heads/master') assert git.committish_exists('weirdbranch') assert git.refname_is_merged('refs/heads/weirdbranch', 'refs/heads/master')
def test_gitproject_iternames(reset_directory, local_repository): # Gets to GITDIR os.chdir(local_repository.path) git = git_project.Git() gp = git_project.GitProject.get(git) gp.add_item('name', 'new') gp.add_item('name', 'test') projects = {name for name in gp.iternames()} assert projects == {'test', 'new'}
def test_git_delete_refname(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() git.create_branch('todelete', 'HEAD') assert git.committish_exists('todelete') assert git.committish_exists('refs/heads/todelete') git.delete_branch('refs/heads/todelete') assert not git.committish_exists('todelete') assert not git.committish_exists('refs/heads/todelete')
def test_project_get_no_repository(reset_directory): git = git_project.Git() assert not git.has_repo() project = git_project.Project.get(git, 'project') assert not project.has_item('remote') assert not project.has_item('branch') assert not project.has_item('builddir') assert not project.has_item('prefix') assert not project.has_item('sharedir') assert not project.has_item('configure') assert not project.has_item('build') assert not project.has_item('install')
def test_git_iterrefnames_str(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() refnamelist = [refname for refname in git.iterrefnames('refs/heads/')] assert (refnamelist == ['refs/heads/master', 'refs/heads/merged_local', 'refs/heads/merged_remote', 'refs/heads/notpushed', 'refs/heads/pushed', 'refs/heads/pushed_indirectly', 'refs/heads/unmerged'])
def test_project_prune_branch(reset_directory, remote_repository, tmp_path_factory): remotedir = tmp_path_factory.mktemp('remote-workdir') os.chdir(remotedir) git_project.capture_command(f'git clone --mirror {remote_repository.path}') print(f'remote.path: {remote_repository.path}') remote_name = Path(remote_repository.path).name + '.git' remote_path = str(Path.cwd() / remote_name) print(f'remote_path: {remote_path}') localdir = tmp_path_factory.mktemp('local-workdir') os.chdir(localdir) git = git_project.Git() project = git_project.Project.get(git, 'project') path = git.clone(remote_path) os.chdir(path) git = git_project.Git() project = git_project.Project.get(git, 'project') assert project._git.remote_branch_exists('pushed', 'origin') project.prune_branch('pushed') assert not project._git.remote_branch_exists('pushed', 'origin')
def test_git_clone_with_path(reset_directory, remote_repository, tmp_path_factory): path = tmp_path_factory.mktemp('clone-workdir') os.chdir(path) git = git_project.Git() remote_url = 'file://' + remote_repository.path path = Path.cwd() / 'foo' / 'bar' os.makedirs(path) path = path / 'test-clone' clone_path = git.clone(remote_url, path) assert os.path.exists(clone_path) assert clone_path == str(path)
def test_git_update_symbolic_ref(reset_directory, local_repository): os.chdir(local_repository.path) git = git_project.Git() git.update_symbolic_ref('HEAD', 'unmerged') assert (git.get_committish_oid('HEAD') == git.get_committish_oid('unmerged')) assert not (git.get_committish_oid('HEAD') == git.get_committish_oid('master')) git.update_symbolic_ref('HEAD', 'master') assert not (git.get_committish_oid('HEAD') == git.get_committish_oid('unmerged')) assert (git.get_committish_oid('HEAD') == git.get_committish_oid('master'))