Last active
April 17, 2026 08:39
-
-
Save beli-sk/e9811488945d0d899014714e4f72298d to your computer and use it in GitHub Desktop.
git diff for SOPS encrypted file
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
| #!/bin/bash | |
| set -eo pipefail | |
| ref="$1" | |
| fname="$2" | |
| if [[ -z "$fname" || "$ref" == "-h" || "$ref" == "--help" ]] ; then | |
| echo "git diff for SOPS encrypted file" | |
| echo "use: git-sops-diff <commit> <path>" | |
| echo "compares working tree file to version in specified commit" | |
| exit 1 | |
| fi | |
| ftype="${fname##*.}" | |
| [[ "$fname" != */* ]] && fname="./${fname}" | |
| tmpf1=`mktemp --tmpdir worktree.XXXXXX` | |
| tmpf2=`mktemp --tmpdir commit.XXXXXX` | |
| cleanup() { rm "$tmpf1" "$tmpf2" ; } | |
| trap cleanup EXIT | |
| sops -d "$fname" > "$tmpf1" | |
| git show "${ref}:${fname}" | sops -d --input-type "$ftype" --output-type "$ftype" /dev/stdin > "$tmpf2" | |
| diff -u "$tmpf2" "$tmpf1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment