def dump_tree(repo, export_dir, treeish, with_submodules, recursive=True): """Dump a git tree-ish to output_dir""" if not os.path.exists(export_dir): os.makedirs(export_dir) if recursive: paths = '' else: paths = [ nam for _mod, typ, _sha, nam in repo.list_tree(treeish) if typ == 'blob' ] try: data = repo.archive('tar', '', None, treeish, paths) untar_data(export_dir, data) if recursive and with_submodules and repo.has_submodules(): repo.update_submodules() for (subdir, commit) in repo.get_submodules(treeish): gbp.log.info("Processing submodule %s (%s)" % (subdir, commit[0:8])) subrepo = GitRepository(os.path.join(repo.path, subdir)) prefix = [subdir, subdir[2:]][subdir.startswith("./")] + '/' data = subrepo.archive('tar', prefix, None, treeish) untar_data(export_dir, data) except GitRepositoryError as err: gbp.log.err("Git error when dumping tree: %s" % err) return False return True
def test_specify_upstream(self, srcrpm): """Test --upstream command line option.""" eq_(GBS(argv=["gbs", "import", "--upstream-branch=upstream", srcrpm]), None) repo = GitRepository("./ail") eq_(repo.get_local_branches(), ['master', 'pristine-tar', 'upstream']) eq_(repo.get_tags(), ['upstream/0.2.29', 'vendor/0.2.29-2.3'])
def test_set_author_name_email(self, srcrpm): """Test --author-name and --author-email command line options.""" eq_(GBS(argv=["gbs", "import", "--author-name=test", "[email protected]", srcrpm]), None) repo = GitRepository("./app-core") eq_(repo.get_local_branches(), ['master', 'pristine-tar', 'upstream']) eq_(repo.get_tags(), ['upstream/1.2', 'vendor/1.2-19.3'])
def test_import_spec(self, srcdir): """Test importing from spec.""" eq_(GBS(argv=["gbs", "import", os.path.join(srcdir, 'bluez.spec')]), None) repo = GitRepository("./bluez") eq_(repo.get_local_branches(), ['master', 'pristine-tar', 'upstream']) # No packging tag as patch-import fails eq_(repo.get_tags(), ['upstream/4.87']) eq_(len(repo.get_commits(until='master')), 2)
def git_archive_submodules(repo, treeish, output, tmpdir_base, prefix, comp_type, comp_level, comp_opts, format='tar'): """ Create a source tree archive with submodules. Since git-archive always writes an end of tarfile trailer we concatenate the generated archives using tar and compress the result. Exception handling is left to the caller. """ prefix = sanitize_prefix(prefix) tempdir = tempfile.mkdtemp(dir=tmpdir_base, prefix='git-archive_') main_archive = os.path.join(tempdir, "main.%s" % format) submodule_archive = os.path.join(tempdir, "submodule.%s" % format) try: # generate main (tmp) archive repo.archive(format=format, prefix=prefix, output=main_archive, treeish=treeish) # generate each submodule's arhive and append it to the main archive for (subdir, commit) in repo.get_submodules(treeish): tarpath = [subdir, subdir[2:]][subdir.startswith("./")] subrepo = GitRepository(os.path.join(repo.path, subdir)) gbp.log.debug("Processing submodule %s (%s)" % (subdir, commit[0:8])) subrepo.archive(format=format, prefix='%s%s/' % (prefix, tarpath), output=submodule_archive, treeish=commit) if format == 'tar': CatenateTarArchive(main_archive)(submodule_archive) elif format == 'zip': CatenateZipArchive(main_archive)(submodule_archive) # compress the output if comp_type: compress(comp_type, ['--stdout', '-%s' % comp_level] + comp_opts + [main_archive], output) else: shutil.move(main_archive, output) finally: shutil.rmtree(tempdir)
def test_import_in_submodule(self, repo): """ Test that importing works if repo is a git submodule (#674015) """ parent_repo = GitRepository.create('../parent') parent_repo.add_submodule(repo.path) parent_repo.update_submodules(init=True, recursive=True) submodule = GitRepository( os.path.join(parent_repo.path, 'hello-debhelper')) ok_(submodule.path.endswith, 'parent/hello-debhelper') os.chdir(submodule.path) orig = self._orig('2.8') submodule.create_branch('upstream', 'origin/upstream') ok_(import_orig(['arg0', '--no-interactive', orig]) == 0)
def setup(self): """Test case setup""" # Change to a temporary directory self.tmpdir = os.path.abspath( tempfile.mkdtemp(prefix='test_', dir=self.workdir)) os.chdir(self.tmpdir) # Use cache in our tmpdir suffix = os.path.basename(self.tmpdir).replace('test', '') self.cachedir = os.path.join(self.workdir, 'cache' + suffix) os.environ['OBS_GIT_BUILDPACKAGE_REPO_CACHE_DIR'] = self.cachedir # Create temporary "orig" repository repo_dir = os.path.join(self.workdir, 'orig' + suffix) shutil.copytree(self._template_repo.path, repo_dir) self.orig_repo = GitRepository(repo_dir)
def test_import_srcrpm(self, srcrpm): """Test importing from source rpm.""" eq_(GBS(argv=["gbs", "import", srcrpm]), None) repo = GitRepository("./ail") eq_(repo.get_local_branches(), ['master', 'pristine-tar', 'upstream']) eq_(repo.get_tags(), ['upstream/0.2.29', 'vendor/0.2.29-2.3'])
def get_info_from_repo(dir_path): '''Get info object of HEAD patch of git tree''' repo = GitRepository(dir_path) info = repo.get_commit_info('HEAD') return info