def test_list_sites_using_remote_repo_and_reuse_clone_path_option( self, temp_path): """Validates clone_path (-p) option is working properly with site list action when using remote repo. Verify that the same repo can't be cloned in the same clone_path if it already exists """ # Scenario: # # 1) List sites (should clone repo automatically to `clone_path` # location if `clone_path` is set) repo_url = 'https://github.com/openstack/%s@%s' % (self.repo_name, self.repo_rev) # Note that the -p option is used to specify the clone_folder site_list = self.runner.invoke( cli.site, ['-p', temp_path, '-r', repo_url, 'list']) assert git.is_repository(os.path.join(temp_path, self.repo_name)) # Run site list for a second time to validate that the repo can't be # cloned twice in the same clone_path site_list = self.runner.invoke( cli.site, ['-p', temp_path, '-r', repo_url, 'list']) assert site_list.exit_code == 1 msg = "The repository already exists in the given path. Either " \ "provide a new clone path or pass in the path of the local " \ "repository as the site repository (-r)." assert msg in site_list.output
def do_test(url, ref, subpath=None): nonlocal cloned_directories if url not in cloned_directories: git_dir = git.git_handler(url, ref=ref) _validate_git_clone(git_dir) cloned_directories.setdefault(url, git_dir) else: git_dir = cloned_directories[url] assert os.path.exists(git_dir) assert git.is_repository(git_dir) if subpath: assert git.is_repository(os.path.join(git_dir, subpath), search_parent_directories=True)
def test_list_sites_using_remote_repo_and_reuse_clone_path_option( self, tmpdir): """Validates clone_path (-p) option is working properly with site list action when using remote repo. Verify that the same repo can't be cloned in the same clone_path if it already exists """ # Scenario: # # 1) List sites (should clone repo automatically to `clone_path` # location if `clone_path` is set) repo_url = 'https://opendev.org/airship/%s@%s' % (self.repo_name, self.repo_rev) # Note that the -p option is used to specify the clone_folder site_list = self.runner.invoke( commands.site, ['--no-decrypt', '-p', tmpdir, '-r', repo_url, 'list']) assert git.is_repository(os.path.join(tmpdir, self.repo_name)) # Run site list for a second time to validate that the repo can't be # cloned twice in the same clone_path site_list = self.runner.invoke( commands.site, ['--no-decrypt', '-p', tmpdir, '-r', repo_url, 'list']) assert site_list.exit_code == 1 assert 'File exists' in site_list.output
def test_list_sites_using_remote_repo_and_clone_path_option( self, temp_path): """Validates clone_path (-p) option is working properly with site list action when using remote repo. Verify that the repo was cloned in the clone_path """ # Scenario: # # 1) List sites (should clone repo automatically to `clone_path` # location if `clone_path` is set) repo_url = 'https://github.com/openstack/%s@%s' % (self.repo_name, self.repo_rev) # Note that the -p option is used to specify the clone_folder site_list = self.runner.invoke( cli.site, ['-p', temp_path, '-r', repo_url, 'list']) assert site_list.exit_code == 0 # Verify that the repo was cloned into the clone_path assert os.path.exists(os.path.join(temp_path, self.repo_name)) assert git.is_repository(os.path.join(temp_path, self.repo_name))
def _validate_git_clone(repo_dir, fetched_ref=None, checked_out_ref=None): """Validate that git clone/checkout work. :param repo_dir: Path to local Git repo. :param fetched_ref: Reference that is stored in FETCH_HEAD following a remote fetch. :param checked_out_ref: Reference that is stored in HEAD following a local ref checkout. """ assert os.path.isdir(repo_dir) # Assert that the directory is a Git repo. assert git.is_repository(repo_dir) if fetched_ref: # Assert the FETCH_HEAD is at the fetched_ref ref. with open(os.path.join(repo_dir, '.git', 'FETCH_HEAD'), 'r') \ as git_file: assert fetched_ref in git_file.read() if checked_out_ref: # Assert the HEAD is at the checked_out_ref. with open(os.path.join(repo_dir, '.git', 'HEAD'), 'r') \ as git_file: assert checked_out_ref in git_file.read()
def test_is_repository_negative(tmpdir): assert not git.is_repository(tmpdir)
def test_is_repository_negative(temp_path): assert not git.is_repository(temp_path)