From 9dd3bc1e0fe5c6cef0396620c1dc304294629fb1 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 7 Feb 2018 16:23:30 -0800 Subject: [PATCH] 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. --- mkosi | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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: -- 2.47.2