Skip to content

Commit 4ceb761

Browse files
committed
Find submodules in subfolders
1 parent a0f3264 commit 4ceb761

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

git-archive-all

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ process_subtree()
265265
fi
266266
fi
267267
fi
268-
done < <( git ${subprefix:+-C "$subprefix"} ls-tree -z "$subtree_ish" 2>/dev/null)
268+
done < <( git ${subprefix:+-C "$subprefix"} ls-tree -r -z "$subtree_ish" 2>/dev/null)
269269
if [[ "${#modulepaths[@]}" -gt 0 ]]
270270
then
271271
# We have submodules. Now we need to create the archive for the

test.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ add_submodule()
7575
local submodule="$2"
7676
local path="${3:-$submodule}"
7777
echo "+++ adding submodule $submodule to repo $repo"
78+
mkdir -p "$repo/$(dirname "$path")"
7879
git -C "$repo" submodule add ../"$submodule" "$path"
7980
git -C "$repo" add .
8081
git -C "$repo" commit -m "add submodule"
@@ -236,6 +237,18 @@ check_tar_content()
236237
check_tar_content test.tar "${tar_files[@]}"
237238
}
238239

240+
@test "repo with submodule, submodule in subfolder" {
241+
create_repo alpha
242+
create_repo beta
243+
add_submodule alpha beta subdir/beta
244+
cd alpha
245+
run_git_archive_all -o test.tar $(git rev-parse HEAD)
246+
local tar_files=(.gitmodules)
247+
repo_files tar_files+ alpha
248+
repo_files tar_files+ beta subdir/beta/
249+
check_tar_content test.tar "${tar_files[@]}"
250+
}
251+
239252
@test "repo with submodule, gzipped tar archive" {
240253
create_repo alpha
241254
create_repo beta
@@ -367,6 +380,22 @@ check_tar_content()
367380
check_tar_content test.tar "${tar_files[@]}"
368381
}
369382

383+
@test "repo with recursive submodules, submodules in subfolders" {
384+
create_repo alpha
385+
create_repo beta
386+
create_repo gamma
387+
add_submodule beta gamma other_subdir/gamma
388+
add_submodule alpha beta subdir/beta
389+
cd alpha
390+
git submodule update --init --recursive
391+
run_git_archive_all -o test.tar --fail-missing $(git rev-parse HEAD)
392+
local tar_files=(.gitmodules subdir/beta/.gitmodules)
393+
repo_files tar_files+ alpha
394+
repo_files tar_files+ beta subdir/beta/
395+
repo_files tar_files+ gamma subdir/beta/other_subdir/gamma/
396+
check_tar_content test.tar "${tar_files[@]}"
397+
}
398+
370399
@test "repo with recursive submodules, non-recursive archive" {
371400
create_repo alpha
372401
create_repo beta

0 commit comments

Comments
 (0)