def assertBundleVerifies(self, bundle_path): self.assertIsFile(bundle_path, 1) bundle_copy_path = os.path.join(tempfile.gettempdir(), 'git_bundle_for_verification.bundle') shutil.copyfile(bundle_path, bundle_copy_path) print("bundle copied to", bundle_copy_path) with TemporaryDirectory() as tmpdir: git_runner = bundle_repos.GitRunner('git') proc = git_runner.run( ['git', 'init'], cwd=tmpdir ) # must run `git bundle verify` inside a repo directory self.assertEqual(proc.returncode, 0, "git init return code nonzero") proc = git_runner.run(['git', 'bundle', 'verify', bundle_path], cwd=tmpdir) if proc.returncode != 0: print("bundle verification failed on {}".format(bundle_path), file=sys.stderr) stdout_decoded = proc.stdout.decode('utf-8') stderr_decoded = proc.stderr.decode('utf-8') print("stdout:") print(stdout_decoded) print("stderr:") print(stderr_decoded) sys.stdout.flush() self.assertEqual(proc.returncode, 0, "git bundle return code nonzero")
def do_test_read_git_latest_commit(self, bundle_path, expected_hash): with tests.TemporaryDirectory() as tempdir: git = bundle_repos.GitRunner('git') clone_dir = os.path.join(tempdir, 'cloned-bundle-directory') git.clone_mirrored_clean(bundle_path, clone_dir) commit_hash = bundle_repos.read_git_latest_commit(clone_dir) self.assertEqual(commit_hash, expected_hash)
def test_cwd(self): with tests.TemporaryDirectory() as tempdir: runner = bundle_repos.GitRunner('pwd') proc = runner.run(['pwd'], cwd=tempdir) self.assertEqual(proc.returncode, 0) actual = proc.stdout.decode('utf8').strip() self.assertEqual(actual, tempdir)
def test_clone_mirrored_clean(self): bundle_path = tests.get_data_dir('sample-repo-branched.bundle') with tests.TemporaryDirectory() as clone_dir: runner = bundle_repos.GitRunner('git') runner.clone_mirrored_clean(bundle_path, clone_dir) branch_list_lines = runner.run_clean( ['git', 'branch', '-l'], cwd=clone_dir).stdout.decode('utf-8').split("\n") branch_list_lines = list(filter(lambda x: x, branch_list_lines)) branch_list = [b.strip().split()[-1] for b in branch_list_lines] self.assertSetEqual(set(branch_list), {'master', 'other-branch'})
def setUp(self): self.git_script = create_script_file(GIT_REPLACER_SCRIPT_CONTENT) self.git_runner = bundle_repos.GitRunner(self.git_script)