There was a bug with sed command, when trying to remove filename with slashes.

Now it is fixed. See `_delete_line` function.
Closes #23
This commit is contained in:
sobolevn 2016-05-22 00:05:55 +03:00
parent c25b1a2bca
commit d523d8b8a9
6 changed files with 26 additions and 14 deletions

View File

@ -85,7 +85,8 @@ function _file_has_line {
function _delete_line { function _delete_line {
_os_based __delete_line $@ local escaped_path=$(echo "$1" | sed -e 's/[\/&]/\\&/g')
sed -i.bak "/$escaped_path/d" "$2"
} }

View File

@ -6,11 +6,6 @@ function __replace_in_file_linux {
} }
function __delete_line_linux {
sed -i.bak "/$1/d" "$2"
}
function __temp_file_linux { function __temp_file_linux {
local filename=$(mktemp) local filename=$(mktemp)
echo "$filename" echo "$filename"

View File

@ -6,11 +6,6 @@ function __replace_in_file_osx {
} }
function __delete_line_osx {
sed -i.bak "/$1/d" "$2"
}
function __temp_file_osx { function __temp_file_osx {
: "${TMPDIR:=/tmp}" : "${TMPDIR:=/tmp}"
local filename=$(mktemp -t _gitsecrets_XXX ) local filename=$(mktemp -t _gitsecrets_XXX )

View File

@ -26,7 +26,7 @@ function reveal {
while read line; do while read line; do
local encrypted_filename=$(_get_encrypted_filename "$line") local encrypted_filename=$(_get_encrypted_filename "$line")
local base="$SECRETS_GPG_COMMAND --use-agent -q --decrypt" local base="$SECRETS_GPG_COMMAND --use-agent -q --decrypt --yes"
if [[ ! -z "$homedir" ]]; then if [[ ! -z "$homedir" ]]; then
base="$base --homedir=$homedir" base="$base --homedir=$homedir"
fi fi

View File

@ -5,6 +5,11 @@ load _test_base
FIRST_FILE="file_to_hide1" FIRST_FILE="file_to_hide1"
SECOND_FILE="file_to_hide2" SECOND_FILE="file_to_hide2"
# There was a bug with `sed` an slashes:
# see https://github.com/sobolevn/git-secret/issues/23
FOLDER="somedir"
FILE_IN_FOLDER="${FOLDER}/file_to_hide3"
function setup { function setup {
install_fixture_full_key "$TEST_DEFAULT_USER" install_fixture_full_key "$TEST_DEFAULT_USER"
@ -12,8 +17,8 @@ function setup {
set_state_git set_state_git
set_state_secret_init set_state_secret_init
set_state_secret_tell "$TEST_DEFAULT_USER" set_state_secret_tell "$TEST_DEFAULT_USER"
set_state_secret_add "$FIRST_FILE" "$FIRST_FILE" set_state_secret_add "$FIRST_FILE" "somecontent"
set_state_secret_add "$SECOND_FILE" "$SECOND_FILE" set_state_secret_add "$SECOND_FILE" "somecontent2"
} }
@ -41,6 +46,22 @@ function teardown {
} }
@test "run 'remove' with slashes in filename" {
mkdir -p "$FOLDER"
set_state_secret_add "$FILE_IN_FOLDER" "somecontent3"
git secret hide
run git secret remove "$FILE_IN_FOLDER"
[ "$status" -eq 0 ]
local mapping_contains=$(grep "$FILE_IN_FOLDER" "$SECRETS_DIR_PATHS_MAPPING"; echo $?)
[ "$mapping_contains" -eq 1 ]
local enctypted_file=$(_get_encrypted_filename $FILE_IN_FOLDER)
[ -f "$enctypted_file" ]
}
@test "run 'remove -c'" { @test "run 'remove -c'" {
git secret hide git secret hide