From bae5a8f38c7f0bce05d3253a2116893b0ba952d5 Mon Sep 17 00:00:00 2001 From: Ian Douglas Scott Date: Fri, 20 Nov 2020 10:40:55 -0800 Subject: [PATCH] Include submodules in git_archive_id() `git archive` doesn't have an option to include submodules, because obviously submodules can never be easy to work with. These arcane commands are the simplest solution I can think of, and seems to work well. --- scripts/git.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/git.py b/scripts/git.py index 5c356307..822a35b8 100644 --- a/scripts/git.py +++ b/scripts/git.py @@ -1,4 +1,5 @@ from subprocess import check_call, check_output +import tempfile def git_ids_and_branches(cwd): """ @@ -53,4 +54,10 @@ def git_datetime_id(cwd, _id): def git_archive_id(cwd, _id, archive): - return check_output(["git", "archive", "--format", "tar", "-o", archive, _id], cwd=cwd) + o = b'' + with tempfile.TemporaryDirectory(dir=cwd) as d: + o += check_output(["git", "worktree", "add", d, _id], cwd=cwd) + o += check_output(["git", "submodule", "update", "--recursive"], cwd=d) + o += check_output(["tar", "--exclude", ".git", "-caf", archive, "."], cwd=d) + o += check_output(["git", "worktree", "remove", d], cwd=cwd) + return o