forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathls-files.sh
executable file
·36 lines (29 loc) · 1.34 KB
/
ls-files.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env bash
# Copyright 2017 The Cockroach Authors.
#
# Use of this software is governed by the CockroachDB Software License
# included in the /LICENSE file.
# Recursively list all files in this Git checkout, including files in
# submodules.
set -euo pipefail
submodules=($(git submodule foreach --quiet 'echo $path'))
# IMPORTANT: This script must never output a bare directory. That is, given a
# directory tree with files a/1 and a/2, this script must output "a/1 \n a/2"
# and not "a/ \n a/1 \n a/2". Bare directories will cause e.g. tar to include
# the entire directory tree, then re-include the files when the files in the
# directory are listed on the following lines. These duplicate files will break
# tar extraction horribly.
#
# git ls-files gets this right with the notable exception of submodules, which
# are always output as a bare directory. We filter them out manually with the
# parameter expansion below, which prefixes every path in the submodules array
# with `:(exclude)`, resulting in a final command like:
#
# git ls-files . :(exclude)vendor :(exclude)c-deps/jemalloc...
#
git ls-files . "${submodules[@]/#/:(exclude)}"
# Then, we list all the files *within* each submodule, without listing the bare
# submodule directory.
for submodule in "${submodules[@]}"; do
git -C "$submodule" ls-files | sed -e "s,^,$submodule/,"
done