From 81fadd2d4cf40f0a9230833f645d5f51230f1a85 Mon Sep 17 00:00:00 2001 From: David Briscoe Date: Thu, 6 Jan 2022 09:00:22 -0800 Subject: [PATCH] Provide ::git-ls-files:: to resolve git submodules Fix #22: Cloned subdirectory fails ls-tree doesn't support --recurse-submodules, but --ls-files does. So provide it as an option. --- makelove/makelove.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/makelove/makelove.py b/makelove/makelove.py index 7e54981..426a670 100644 --- a/makelove/makelove.py +++ b/makelove/makelove.py @@ -119,6 +119,25 @@ def git_ls_tree(path=".", visited=None): return out +def git_ls_files(path="."): + """List files tracked by git using ls-files using paths relative to the + input path. Includes files in submodules. Doesn't resolve symlinks (?). + + git_ls_files(str) -> [str] + """ + p = os.path + + path = "." + ls_tree = ( + subprocess.check_output( + ["git", "ls-files", "--recurse-submodules", "--abbrev=0", "HEAD", path], cwd=path + ) + .decode("utf-8") + .splitlines() + ) + return [p.join(path, item) for item in ls_tree] + + def assemble_game_directory(args, config, game_directory): if os.path.isdir(game_directory): shutil.rmtree(game_directory) @@ -132,6 +151,13 @@ def assemble_game_directory(args, config, game_directory): file_list.include_raw(item) except FileNotFoundError: sys.exit("Could not find git-tracked file '{}'".format(item)) + elif rule == "+::git-ls-files::" or rule == "::git-ls-files::": + ls_tree = git_ls_files(".") + for item in ls_tree: + try: + file_list.include_raw(item) + except FileNotFoundError: + sys.exit("Could not find git-tracked file '{}'".format(item)) elif rule[0] == "-": file_list.exclude(rule[1:]) elif rule[0] == "+":