From b8b2609ec2cf3dafe880cc94f008f46bbd1cabda Mon Sep 17 00:00:00 2001 From: Miguel Silvestre Date: Fri, 17 Feb 2017 18:40:49 +0000 Subject: [PATCH 1/3] Fix bug when passing more than one file to changes --- src/commands/git_secret_changes.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/git_secret_changes.sh b/src/commands/git_secret_changes.sh index b669cda9..11bc88a4 100644 --- a/src/commands/git_secret_changes.sh +++ b/src/commands/git_secret_changes.sh @@ -18,7 +18,7 @@ function changes { shift $((OPTIND-1)) [ "$1" = '--' ] && shift - local filenames="$1" + local filenames="$@" if [[ -z "$filenames" ]]; then # Checking if no filenames are passed, show diff for all files. filenames=$(git secret list) From 5a2049bd47ca6cc49c916cdc6e3d0a22e528d431 Mon Sep 17 00:00:00 2001 From: Miguel Silvestre Date: Tue, 21 Feb 2017 18:50:13 +0000 Subject: [PATCH 2/3] Clean code using shellspeck --- src/commands/git_secret_changes.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/git_secret_changes.sh b/src/commands/git_secret_changes.sh index 11bc88a4..b1ad3c82 100644 --- a/src/commands/git_secret_changes.sh +++ b/src/commands/git_secret_changes.sh @@ -18,15 +18,15 @@ function changes { shift $((OPTIND-1)) [ "$1" = '--' ] && shift - local filenames="$@" - if [[ -z "$filenames" ]]; then + local filenames=( "$@" ) + if [[ ${#filenames[@]} -eq 0 ]]; then # Checking if no filenames are passed, show diff for all files. - filenames=$(git secret list) + filenames=( $(git secret list) ) fi IFS=' ' - for filename in $filenames; do + for filename in "${filenames[@]}"; do local decrypted local content local diff_result From 40777fe45037f076680c9e73b9fac5ce32ce824a Mon Sep 17 00:00:00 2001 From: Miguel Silvestre Date: Tue, 21 Feb 2017 18:52:02 +0000 Subject: [PATCH 3/3] Test changes using multiple files passed as argument --- tests/test_changes.bats | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_changes.bats b/tests/test_changes.bats index b151b22e..7902baf6 100644 --- a/tests/test_changes.bats +++ b/tests/test_changes.bats @@ -66,3 +66,21 @@ function teardown { [[ "$output" == *"changes in $SECOND_FILE_TO_HIDE"* ]] [[ "$output" == *"$second_file_to_hide"* ]] } + +@test "run 'changes' with multiple selected files changed" { + local password=$(test_user_password "$TEST_DEFAULT_USER") + local new_content="new content" + local second_new_content="something different" + echo "$new_content" >> "$FILE_TO_HIDE" + echo "$second_new_content" >> "$SECOND_FILE_TO_HIDE" + + run git secret changes "$FILE_TO_HIDE" "$SECOND_FILE_TO_HIDE" -d "$TEST_GPG_HOMEDIR" -p "$password" + [ "$status" -eq 2 ] + + # Testing that output has both filename and changes: + [[ "$output" == *"changes in $FILE_TO_HIDE"* ]] + [[ "$output" == *"$new_content"* ]] + + [[ "$output" == *"changes in $SECOND_FILE_TO_HIDE"* ]] + [[ "$output" == *"$second_file_to_hide"* ]] +}