From: Lucas De Marchi Date: Thu, 8 Feb 2018 00:23:30 +0000 (-0800) Subject: Support copying git submodule files X-Git-Tag: v4~1^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F232%2Fhead;p=thirdparty%2Fmkosi.git Support copying git submodule files Besides getting the files from the git directory, iterate through each submodules to copy them over to the build image as well. We had some (better) alternative, but each of them failing to provide what we need: - Recent versions for git-ls-files learned a --recurse-submodules but they are not support together with --others - git-submodule foreach --recursive would allow us to git-ls-files inside each submodule, however there's no easy way to control from which submodule the command is printing the files in order to prepend the submodule path So for now we live with getting the list of submodules from `git submodule status --recursive` and calling git-ls-files on each of them. --- diff --git a/mkosi b/mkosi index 97413547f..22a994807 100755 --- a/mkosi +++ b/mkosi @@ -1714,6 +1714,25 @@ def copy_git_files(src, dest, *, git_files): check=True) files = {x.decode("utf-8") for x in c.stdout.rstrip(b'\0').split(b'\0')} + # Get submodule files + c = run(['git', '-C', src, 'submodule', 'status', '--recursive'], + stdout=PIPE, + universal_newlines=True, + check=True) + submodules = {x.split()[1] for x in c.stdout.splitlines()} + + # workaround for git-ls-files returning the path of submodules that we will + # still parse + files -= submodules + + for sm in submodules: + c = run(['git', '-C', os.path.join(src, sm), 'ls-files', '-z'] + what_files, + stdout=PIPE, + universal_newlines=False, + check=True) + files |= {os.path.join(sm, x.decode("utf-8"))for x in c.stdout.rstrip(b'\0').split(b'\0')} + files -= submodules + del c for path in files: