1010VERSION=0.1.0
1111REVISION=
1212PATH_SCOPE=
13+ GIT_DIFF_ARGS=
1314VAULT_PASSWORD_FILE=' ./.vault-pass'
1415VAULT_ONLY=0
1516COLOR=
@@ -50,6 +51,7 @@ help() {
5051 Options:
5152 -r, --revision <revision> show diff for git revision, e.g. master..some-branch
5253 -p, --path <path> restrict diff to path, e.g. support/config.yml
54+ --cached, --staged show diff for staged changes
5355 --vault-password-file <path> vault password file path, defaults to .vault-pass
5456 --vault-only restrict diff to vault files only
5557 --color, --colour turn on coloured output
@@ -233,23 +235,24 @@ set_default_color() {
233235git_diff_ansible_vault () {
234236 log " REVISION: $REVISION "
235237 log " PATH_SCOPE: $PATH_SCOPE "
238+ log " GIT_DIFF_ARGS: $GIT_DIFF_ARGS "
236239 log " VAULT_PASSWORD_FILE: $VAULT_PASSWORD_FILE "
237240 log " VAULT_ONLY: $VAULT_ONLY "
238241 log " COLOR: $COLOR "
239242
240- for FILE_PATH in $( $GIT_CMD diff --name-only $REVISION $PATH_SCOPE ) ; do
243+ for FILE_PATH in $( $GIT_CMD diff $GIT_DIFF_ARGS --name-only $REVISION $PATH_SCOPE ) ; do
241244 if is_vault $FILE_PATH ; then
242245 log " $FILE_PATH is vault"
243246 # extract the old revision encrypted file contents
244- local old=$( $GIT_CMD diff $REVISION $FILE_PATH \
247+ local old=$( $GIT_CMD diff $GIT_DIFF_ARGS $ REVISION $FILE_PATH \
245248 | grep -E ' ^-[^-]|\$ANSIBLE_VAULT' | sed -E ' s/^([^- ]*)[- ]/\1/' )
246249
247250 # extract the new revision encrypted file contents
248- local new=$( $GIT_CMD diff $REVISION $FILE_PATH \
251+ local new=$( $GIT_CMD diff $GIT_DIFF_ARGS $ REVISION $FILE_PATH \
249252 | grep -E ' ^\+[^\+]|\$ANSIBLE_VAULT' | sed -E ' s/^([^+ ]*)[+ ]/\1/' )
250253
251254 # print the diff heading from git diff so we get the real paths
252- $GIT_CMD -c color.ui=$COLOR diff $REVISION $FILE_PATH | head -n 4
255+ $GIT_CMD -c color.ui=$COLOR diff $GIT_DIFF_ARGS $ REVISION $FILE_PATH | head -n 4
253256
254257 # print the diff body from the opened vault diff
255258 diff -u \
@@ -258,7 +261,7 @@ git_diff_ansible_vault() {
258261 | tail -n +3 | colordiff_wrap
259262 elif [ $VAULT_ONLY -eq 0 ]; then
260263 log " $FILE_PATH is not vault"
261- $GIT_CMD -c color.ui=$COLOR diff $REVISION $FILE_PATH
264+ $GIT_CMD -c color.ui=$COLOR diff $GIT_DIFF_ARGS $ REVISION $FILE_PATH
262265 fi
263266 done
264267}
@@ -272,6 +275,7 @@ while test $# -ne 0; do
272275 case $ARG in
273276 -r|--revision) REVISION=$1 ; shift ;;
274277 -p|--path) PATH_SCOPE=$1 ; shift ;;
278+ --cached|--staged) GIT_DIFF_ARGS=" $GIT_DIFF_ARGS --cached" ;;
275279 --vault-password-file) set_vault_password_file_path $1 ; shift ;;
276280 --vault-only) VAULT_ONLY=1 ;;
277281 --color|--colour) ensure_colordiff; COLOR=' always' ;;
0 commit comments