pmbootstrap ci: fix error with deleted files
Check if each file listed by the two git ls-files commands still exists, and only add the existing ones to the tarball. Otherwise it would crash when a file has been deleted without having the change commited yet. Link: https://lists.sr.ht/~postmarketos/pmbootstrap-devel/%3C20221031111614.1377-1-ollieparanoid@postmarketos.org%3E
This commit is contained in:
parent
397225667f
commit
f8d186e776
|
@ -111,10 +111,15 @@ def copy_git_repo_to_chroot(args, topdir):
|
|||
pmb.helpers.git.get_topdir() """
|
||||
pmb.chroot.init(args)
|
||||
tarball_path = f"{args.work}/chroot_native/tmp/git.tar.gz"
|
||||
files = pmb.helpers.git.get_files(args, topdir)
|
||||
|
||||
cmd = "(git ls-files && git ls-files --exclude-standard --other)"
|
||||
cmd += f" | tar -cf {shlex.quote(tarball_path)} -T -"
|
||||
pmb.helpers.run.user(args, ["sh", "-c", cmd], topdir)
|
||||
with open(f"{tarball_path}.files", "w") as handle:
|
||||
for file in files:
|
||||
handle.write(file)
|
||||
handle.write("\n")
|
||||
|
||||
pmb.helpers.run.user(args, ["tar", "-cf", tarball_path, "-T",
|
||||
f"{tarball_path}.files"], topdir)
|
||||
|
||||
ci_dir = "/home/pmos/ci"
|
||||
pmb.chroot.user(args, ["rm", "-rf", ci_dir])
|
||||
|
|
|
@ -253,3 +253,22 @@ def get_topdir(args, path):
|
|||
empty string if it's not a git repository. """
|
||||
return pmb.helpers.run.user(args, ["git", "rev-parse", "--show-toplevel"],
|
||||
path, output_return=True, check=False).rstrip()
|
||||
|
||||
|
||||
def get_files(args, path):
|
||||
""" Get all files inside a git repository, that are either already in the
|
||||
git tree or are not in gitignore. Do not list deleted files. To be used
|
||||
for creating a tarball of the git repository.
|
||||
:param path: top dir of the git repository
|
||||
:returns: all files in a git repository as list, relative to path """
|
||||
ret = []
|
||||
files = pmb.helpers.run.user(args, ["git", "ls-files"], path,
|
||||
output_return=True).split("\n")
|
||||
files += pmb.helpers.run.user(args, ["git", "ls-files",
|
||||
"--exclude-standard", "--other"], path,
|
||||
output_return=True).split("\n")
|
||||
for file in files:
|
||||
if os.path.exists(f"{path}/{file}"):
|
||||
ret += [file]
|
||||
|
||||
return ret
|
||||
|
|
Loading…
Reference in New Issue