Skip to content

Instantly share code, notes, and snippets.

@brasic
Last active February 6, 2023 15:12
Show Gist options
  • Save brasic/a6c24a20eb88dc695b2649db8e8854ec to your computer and use it in GitHub Desktop.
Save brasic/a6c24a20eb88dc695b2649db8e8854ec to your computer and use it in GitHub Desktop.
Digest dir
#!/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