def test_make_archive(tempdir_factory): output_dir = tempdir_factory.get() git_path = git_dir(tempdir_factory) # Add a files to the git directory with cwd(git_path): open('foo', 'a').close() cmd_output('git', 'add', '.') cmd_output('git', 'commit', '-m', 'foo') # We'll use this sha head_sha = get_head_sha('.') # And check that this file doesn't exist open('bar', 'a').close() cmd_output('git', 'add', '.') cmd_output('git', 'commit', '-m', 'bar') # Do the thing archive_path = make_archives.make_archive( 'foo', git_path, head_sha, output_dir, ) assert archive_path == os.path.join(output_dir, 'foo.tar.gz') assert os.path.exists(archive_path) extract_dir = tempdir_factory.get() # Extract the tar with tarfile.open(archive_path) as tf: tf.extractall(extract_dir) # Verify the contents of the tar assert os.path.exists(os.path.join(extract_dir, 'foo')) assert os.path.exists(os.path.join(extract_dir, 'foo', 'foo')) assert not os.path.exists(os.path.join(extract_dir, 'foo', '.git')) assert not os.path.exists(os.path.join(extract_dir, 'foo', 'bar'))
def test_make_archive(in_git_dir, tmpdir): output_dir = tmpdir.join('output').ensure_dir() # Add a files to the git directory in_git_dir.join('foo').ensure() cmd_output('git', 'add', '.') git_commit() # We'll use this rev head_rev = git.head_rev('.') # And check that this file doesn't exist in_git_dir.join('bar').ensure() cmd_output('git', 'add', '.') git_commit() # Do the thing archive_path = make_archives.make_archive( 'foo', in_git_dir.strpath, head_rev, output_dir.strpath, ) expected = output_dir.join('foo.tar.gz') assert archive_path == expected.strpath assert expected.exists() extract_dir = tmpdir.join('extract').ensure_dir() with tarfile.open(archive_path) as tf: tf.extractall(extract_dir.strpath) # Verify the contents of the tar assert extract_dir.join('foo').isdir() assert extract_dir.join('foo/foo').exists() assert not extract_dir.join('foo/.git').exists() assert not extract_dir.join('foo/bar').exists()
def test_make_archive(tmpdir_factory): output_dir = tmpdir_factory.get() git_path = git_dir(tmpdir_factory) # Add a files to the git directory with local.cwd(git_path): local['touch']('foo') local['git']('add', '.') local['git']('commit', '-m', 'foo') # We'll use this sha head_sha = get_head_sha('.') # And check that this file doesn't exist local['touch']('bar') local['git']('add', '.') local['git']('commit', '-m', 'bar') # Do the thing archive_path = make_archives.make_archive( 'foo', git_path, head_sha, output_dir, ) assert archive_path == os.path.join(output_dir, 'foo.tar.gz') assert os.path.exists(archive_path) extract_dir = tmpdir_factory.get() # Extract the tar with tarfile_open(archive_path) as tf: tf.extractall(extract_dir) # Verify the contents of the tar assert os.path.exists(os.path.join(extract_dir, 'foo')) assert os.path.exists(os.path.join(extract_dir, 'foo', 'foo')) assert not os.path.exists(os.path.join(extract_dir, 'foo', '.git')) assert not os.path.exists(os.path.join(extract_dir, 'foo', 'bar'))