github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/scripts/ls-files.sh (about)

     1  #!/usr/bin/env bash
     2  
     3  # Recursively list all files in this Git checkout, including files in
     4  # submodules.
     5  
     6  set -euo pipefail
     7  
     8  submodules=($(git submodule foreach --quiet 'echo $path'))
     9  
    10  # IMPORTANT: This script must never output a bare directory. That is, given a
    11  # directory tree with files a/1 and a/2, this script must output "a/1 \n a/2"
    12  # and not "a/ \n a/1 \n a/2". Bare directories will cause e.g. tar to include
    13  # the entire directory tree, then re-include the files when the files in the
    14  # directory are listed on the following lines. These duplicate files will break
    15  # tar extraction horribly.
    16  #
    17  # git ls-files gets this right with the notable exception of submodules, which
    18  # are always output as a bare directory. We filter them out manually with the
    19  # parameter expansion below, which prefixes every path in the submodules array
    20  # with `:(exclude)`, resulting in a final command like:
    21  #
    22  #     git ls-files . :(exclude)vendor :(exclude)c-deps/jemalloc...
    23  #
    24  git ls-files . "${submodules[@]/#/:(exclude)}"
    25  
    26  # Then, we list all the files *within* each submodule, without listing the bare
    27  # submodule directory.
    28  for submodule in "${submodules[@]}"; do
    29    git -C "$submodule" ls-files | sed -e "s,^,$submodule/,"
    30  done