From 7b58dfe17382a66c17442aa87902131d84786a73 Mon Sep 17 00:00:00 2001 From: acrewdson Date: Tue, 5 Dec 2017 11:03:59 -0500 Subject: [PATCH] Add side-by-side diff output option --- bin/git-diff-ansible-vault | 12 ++++++++++- test/git-diff-ansible-vault.bats | 36 ++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bin/git-diff-ansible-vault b/bin/git-diff-ansible-vault index 378154d..1fa9253 100755 --- a/bin/git-diff-ansible-vault +++ b/bin/git-diff-ansible-vault @@ -16,6 +16,7 @@ VAULT_PASSWORD_FILE='./.vault-pass' VAULT_ONLY=0 COLOR= VERBOSE=0 +SIDE_BY_SIDE=0 GIT_CMD='git --no-pager' PAGER_CMD= @@ -59,6 +60,7 @@ help() { --vault-only restrict diff to vault files only --color, --colour turn on coloured output --no-color, --no-colour turn off coloured diff + --side-by-side side-by-side diff output instead of unified --verbose display verbose output -v, --version output program version -h, --help output help information @@ -286,8 +288,15 @@ git_diff_ansible_vault() { # print the diff heading from git diff so we get the real paths echo "$($GIT_CMD -c color.ui=$COLOR diff $GIT_DIFF_ARGS $REVISION $FILE_PATH)" | head -n 4 + # set the diff type (unified is default) + if [[ $SIDE_BY_SIDE -eq 1 ]]; then + local difftype="-y" + else + local difftype="-u" + fi + # print the diff body from the opened vault diff - diff -u \ + diff $difftype \ <( decrypted_vault_contents "$old" ) \ <( decrypted_vault_contents "$new" ) \ | tail -n +3 | colordiff_wrap @@ -314,6 +323,7 @@ while test $# -ne 0; do --color|--colour) ensure_colordiff; COLOR='always' ;; --no-color|--no-colour) COLOR='never' ;; --verbose) VERBOSE=1 ;; + --side-by-side) SIDE_BY_SIDE=1 ;; -v|--version) version; exit ;; -h|--help) help; exit ;; *) diff --git a/test/git-diff-ansible-vault.bats b/test/git-diff-ansible-vault.bats index 81391c3..a7aa276 100644 --- a/test/git-diff-ansible-vault.bats +++ b/test/git-diff-ansible-vault.bats @@ -59,6 +59,42 @@ EOF )" } +@test "with --side-by-side shows expected output format" { + run git diff-ansible-vault -r b479719..c54076a --side-by-side + assert_success + assert_output "$(cat < - ruby +- tabitha: - tabitha: + name: Tabitha Bitumen name: Tabitha Bitumen + job: Developer job: Developer + skills: skills: + - lisp - lisp + - fortran - fortran + - erlang - erlang +EOF +)" +} + @test "with --path shows work-in-progress changes for that path only" { run git diff-ansible-vault -p vault.yml assert_success