Last active
February 6, 2023 15:12
-
-
Save brasic/a6c24a20eb88dc695b2649db8e8854ec to your computer and use it in GitHub Desktop.
Digest dir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Return a recursive digest of all files in the current directory, including modified ones. | |
set -eo pipefail | |
# ensure we're in a git repo and running from its root. | |
cd "$(git rev-parse --show-toplevel)" | |
# If the repo is completely clean, we can just print the current tree OID. | |
if [ -z "$(git status --porcelain)" ]; then | |
git rev-parse HEAD: | |
exit 0 | |
fi | |
# Otherwise, we will hash all files into a temporary index. | |
TMPINDEX=$(mktemp) | |
trap 'rm -f "$TMPINDEX"' EXIT | |
rm -f "$TMPINDEX" | |
export GIT_INDEX_FILE=$TMPINDEX | |
git add . && git ls-files -s | shasum | cut -d' ' -f1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment