mirror of
https://github.com/rpm-software-management/tito.git
synced 2025-02-23 20:22:46 +00:00
Submodules may contain other submodules. Do process and add those
to the source tar. fixes #456
This commit is contained in:
parent
71c8e6f652
commit
835309b6f4
1 changed files with 38 additions and 17 deletions
|
@ -1,4 +1,5 @@
|
||||||
# Copyright (c) 2008-2011 Red Hat, Inc.
|
# Copyright (c) 2008-2011 Red Hat, Inc.
|
||||||
|
# Copyright (c) 2023 Karellen, Inc. (https://karellen.co)
|
||||||
#
|
#
|
||||||
# This software is licensed to you under the GNU General Public License,
|
# This software is licensed to you under the GNU General Public License,
|
||||||
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
# version 2 (GPLv2). There is NO WARRANTY for this software, express or
|
||||||
|
@ -26,6 +27,7 @@ from tito.common import (
|
||||||
find_spec_like_file,
|
find_spec_like_file,
|
||||||
get_commit_timestamp,
|
get_commit_timestamp,
|
||||||
)
|
)
|
||||||
|
from tito.exception import TitoException
|
||||||
from tito.tar import TarFixer
|
from tito.tar import TarFixer
|
||||||
|
|
||||||
|
|
||||||
|
@ -107,9 +109,12 @@ class SubmoduleAwareBuilder(Builder):
|
||||||
"%s > /dev/null" % git_archive_cmd,
|
"%s > /dev/null" % git_archive_cmd,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _submodule_archives(self, relative_git_dir, prefix, commit, initial_tar):
|
# pylint: disable=too-many-locals, too-many-arguments, consider-using-f-string
|
||||||
submodules_cmd = "git config --file .gitmodules --get-regexp path"
|
def _submodule_archives(self, relative_git_dir, prefix, commit, initial_tar,
|
||||||
submodules_output = run_command(submodules_cmd)
|
submodule_tree="."):
|
||||||
|
with chdir(submodule_tree):
|
||||||
|
submodules_cmd = "git config --file .gitmodules --get-regexp path"
|
||||||
|
submodules_output = run_command(submodules_cmd)
|
||||||
|
|
||||||
# split submodules output on newline
|
# split submodules output on newline
|
||||||
# then on tab, and the directory is the last entry
|
# then on tab, and the directory is the last entry
|
||||||
|
@ -120,23 +125,39 @@ class SubmoduleAwareBuilder(Builder):
|
||||||
# We ignore the hash in the sub modules list as we'll have to get the correct one
|
# We ignore the hash in the sub modules list as we'll have to get the correct one
|
||||||
# from the commit id in commit
|
# from the commit id in commit
|
||||||
for submodule in submodules_list:
|
for submodule in submodules_list:
|
||||||
# to find the submodule shars:
|
with chdir(submodule_tree):
|
||||||
# git rev-parse <commit>:./<submodule>
|
submodule_git_dir = os.path.join(submodule, ".git")
|
||||||
rev_parse_cmd = "git rev-parse %s:./%s" % (commit, submodule)
|
if not os.path.exists(submodule_git_dir):
|
||||||
submodule_commit = run_command(rev_parse_cmd)
|
raise TitoException("%r path does not contain '.git'. "
|
||||||
submodule_tar_file = "%s.%s" % (initial_tar, submodule.replace("/", "_"))
|
"Have you cloned the repository recursively?\n"
|
||||||
# prefix should be <prefix>/<submodule>
|
"Try `git submodule update --init --recursive`!" %
|
||||||
submodule_prefix = "%s/%s" % (prefix, submodule)
|
os.path.abspath(submodule))
|
||||||
|
# to find the submodule shars:
|
||||||
|
# git rev-parse <commit>:./<submodule>
|
||||||
|
rev_parse_cmd = "git rev-parse %s:./%s" % (commit, submodule)
|
||||||
|
submodule_commit = run_command(rev_parse_cmd)
|
||||||
|
submodule_tar_file = "%s.%s" % (initial_tar, submodule.replace("/", "_"))
|
||||||
|
# prefix should be <prefix>/<submodule>
|
||||||
|
submodule_prefix = "%s/%s" % (prefix, submodule)
|
||||||
|
|
||||||
self.run_git_archive(
|
self.run_git_archive(
|
||||||
relative_git_dir,
|
relative_git_dir,
|
||||||
submodule_prefix,
|
submodule_prefix,
|
||||||
submodule_commit,
|
submodule_commit,
|
||||||
submodule_tar_file,
|
submodule_tar_file,
|
||||||
submodule,
|
submodule,
|
||||||
)
|
)
|
||||||
yield (submodule_tar_file)
|
yield (submodule_tar_file)
|
||||||
|
|
||||||
|
submodule_dir = os.path.join(submodule_tree, submodule)
|
||||||
|
gitmodules_path = os.path.join(submodule_dir, ".gitmodules")
|
||||||
|
if os.path.exists(gitmodules_path):
|
||||||
|
for archive in self._submodule_archives(
|
||||||
|
relative_git_dir, submodule_prefix, submodule_commit,
|
||||||
|
submodule_tar_file, submodule_dir
|
||||||
|
):
|
||||||
|
yield archive
|
||||||
|
|
||||||
def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz):
|
def create_tgz(self, git_root, prefix, commit, relative_dir, dest_tgz):
|
||||||
"""
|
"""
|
||||||
Create a .tar.gz from a projects source in git.
|
Create a .tar.gz from a projects source in git.
|
||||||
|
|
Loading…
Add table
Reference in a new issue