Adds fix to the `changes` command

Changes:
1. Fixes #80, there was a pipe to null, which broke the output
2. Also changed the `diff` formating
3. Also added test case to test deletions
pull/90/head
sobolevn 7 years ago
parent 9d0a2ac1c1
commit 8a1fe788f8
No known key found for this signature in database
GPG Key ID: FF672D568AE3C73E

@ -23,7 +23,7 @@ matrix:
language: ruby
- os: linux
env: GITSECRET_DIST="none"; GITSECRET_GPG_DEP="gnupg"; SECRETS_GPG_COMMAND="gpg"
sudo: required
sudo: false
language: ruby
- os: linux
env: GITSECRET_DIST="none"; GITSECRET_GPG_DEP="gnupg2"; SECRETS_GPG_COMMAND="gpg2"

@ -432,9 +432,9 @@ function _decrypt {
fi
if [[ ! -z "$passphrase" ]]; then
echo "$passphrase" | $base --batch --yes --no-tty --passphrase-fd 0 \
"$encrypted_filename" > /dev/null 2>&1
echo "$passphrase" | $base --quiet --batch --yes --no-tty --passphrase-fd 0 \
"$encrypted_filename"
else
$base "$encrypted_filename" > /dev/null 2>&1
$base --quiet "$encrypted_filename"
fi
}

@ -31,17 +31,16 @@ function changes {
for filename in $filenames; do
local decrypted
local content
local diff_result
# Now we have all the data required:
decrypted=$(_decrypt "$filename" "0" "0" "$homedir" "$passphrase")
content=$(cat "$filename")
# Let's diff the result:
diff_result=$(diff <(echo "$decrypted") <(echo "$content")) || true
diff_result=$(diff -u <(echo "$decrypted") "$filename") || true
# There was a bug in the previous version, since `diff` returns
# exit code `1` when the files are different.
echo "changes in ${filename}: ${diff_result}"
echo "changes in ${filename}:"
echo "${diff_result}"
done
}

@ -40,7 +40,22 @@ function teardown {
# Testing that output has both filename and changes:
[[ "$output" == *"changes in $FILE_TO_HIDE"* ]]
[[ "$output" == *"$new_content"* ]]
[[ "$output" == *"+$new_content"* ]]
}
@test "run 'changes' with one file changed (with deletions)" {
local password=$(test_user_password "$TEST_DEFAULT_USER")
local new_content="replace"
echo "$new_content" > "$FILE_TO_HIDE"
run git secret changes -d "$TEST_GPG_HOMEDIR" -p "$password" "$FILE_TO_HIDE"
[ "$status" -eq 0 ]
# Testing that output has both filename and changes:
[[ "$output" == *"changes in $FILE_TO_HIDE"* ]]
[[ "$output" == *"-$FILE_CONTENTS"* ]]
[[ "$output" == *"+$new_content"* ]]
}
@ -64,12 +79,13 @@ function teardown {
# Testing that output has both filename and changes:
[[ "$output" == *"changes in $FILE_TO_HIDE"* ]]
[[ "$output" == *"$new_content"* ]]
[[ "$output" == *"+$new_content"* ]]
[[ "$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"
@ -84,8 +100,8 @@ function teardown {
# Testing that output has both filename and changes:
[[ "$output" == *"changes in $FILE_TO_HIDE"* ]]
[[ "$output" == *"$new_content"* ]]
[[ "$output" == *"+$new_content"* ]]
[[ "$output" == *"changes in $SECOND_FILE_TO_HIDE"* ]]
[[ "$output" == *"$second_file_to_hide"* ]]
[[ "$output" == *"+$second_file_to_hide"* ]]
}

Loading…
Cancel
Save