diff --git a/src/commands/git_secret_changes.sh b/src/commands/git_secret_changes.sh index b669cda9..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="$1" - 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 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"* ]] +}