Skip to content

Add side-by-side diff output option #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion bin/git-diff-ansible-vault
Original file line number Diff line number Diff line change
Expand Up @@ -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=

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 ;;
*)
Expand Down
36 changes: 36 additions & 0 deletions test/git-diff-ansible-vault.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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 <<EOF
diff --git a/public.yml b/public.yml
index 970074c..1f613c2 100644
--- a/public.yml
+++ b/public.yml
@@ -5,3 +5,4 @@ fruits:
- Orange
- Strawberry
- Mango
+ - Banana
diff --git a/vault.yml b/vault.yml
index 2e972c1..5fd6cf8 100644
--- a/vault.yml
+++ b/vault.yml
- martin: - martin:
name: Martin D'vloper name: Martin D'vloper
job: Developer job: Developer
skills: skills:
- python - python
- perl - perl
- pascal - pascal
> - 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
Expand Down