Skip to content

Commit

Permalink
Take submodules into account for calculating repo checksums.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Aug 29, 2022
1 parent 22cf9fe commit 2e646b7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions law/contrib/git/scripts/repository_checksum.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env bash

# Computes a checksum of a git repository considering
# 1. the current revision,
# 2. the current diff, and
# 3. the content of new files.
# 1. the current revision,
# 2. the current diff, and
# 3. the content of new files
# of the repository itself and optionally all of its submodules.

# Arguments:
# 1. the path to the repository
# 1. path to the repository
# 2. (optional) recursive flag ("0" or "1"), defaults to "1"

action() {
local shell_is_zsh=$( [ -z "${ZSH_VERSION}" ] && echo "false" || echo "true" )
Expand All @@ -18,6 +20,7 @@ action() {

# handle arguments
local repo_path="$1"
local recursive="${2:-1}"
if [ -z "${repo_path}" ]; then
>&2 echo "please provide the path to the repository to bundle"
return "1"
Expand All @@ -28,11 +31,15 @@ action() {
return "2"
fi

( \
(
cd "${repo_path}" && \
git rev-parse HEAD && \
git diff && \
( git ls-files --others --exclude-standard | xargs cat ) \
git ls-files --others --exclude-standard | xargs cat; \
[ "${recursive}" = "1" ] && git submodule foreach --recursive --quiet "\
git rev-parse HEAD && \
git diff && \
git ls-files --others --exclude-standard | xargs cat";
) | shasum | cut -d " " -f 1
local ret="$?"

Expand Down

0 comments on commit 2e646b7

Please sign in to comment.