Newline not added to .gitignore entry on add (#645)

* Fix Newline not added to .gitignore entry on add (#643)
* Updates to CHANGELOG.md
* Add tests
pull/689/head
Pedro Sobota 3 years ago committed by GitHub
parent 7a285d79ac
commit ac3b77a5bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,9 +2,15 @@
## {{Next Version}}
### Bugfixes
- Fix adding newlines to `.gitignore` entries (#643)
### Misc
- Rename `killperson` command to `removeperson` (#684)
- Moves `file_has_line` utility to tests and fixes how it is used
## 0.4.0

@ -181,20 +181,6 @@ function _set_config {
}
function _file_has_line {
# First parameter is the key, second is the filename.
local key="$1" # required
local filename="$2" # required
local contains
contains=$(grep -qw "$key" "$filename"; echo $?)
# 0 on contains, 1 for error.
echo "$contains"
}
# this sets the global variable 'temporary_filename'
# currently this function is only used by 'hide'
function _temporary_file {
@ -339,7 +325,7 @@ function _add_ignored_file {
local full_path
full_path=$(_append_root_path '.gitignore')
printf '%q' "$filename" >> "$full_path"
printf '%q\n' "$filename" >> "$full_path"
}

@ -78,6 +78,22 @@ function test_user_password {
}
# Files:
function file_has_line {
# First parameter is the key, second is the filename.
local key="$1" # required
local filename="$2" # required
local contains
contains=$(grep -Fqw "$key" "$filename"; echo $?)
# 0 on contains, 1 or 2 for error.
echo "$contains"
}
# GPG:
function stop_gpg_agent {

@ -65,19 +65,27 @@ function teardown {
}
@test "run 'add' for file ignored with '-i'" {
@test "run 'add' for file ignored with '-i' and '.gitignore' contents" {
local test_file="$TEST_DEFAULT_FILENAME"
touch "$test_file"
echo "content" > "$test_file"
local quoted_name
quoted_name=$(printf '%q' "$test_file")
# add -i is now a no-op (See #225) so this tests that -i does nothing.
run git secret add -i "$test_file"
[ "$status" -eq 0 ]
run _file_has_line "$test_file" ".gitignore"
[ "$status" -eq 0 ]
run file_has_line "$quoted_name" ".gitignore"
[ "$output" = '0' ]
rm "$test_file"
local expected=.gitsec/keys/random_seed$'\n'\!\*.sec$'\n'$quoted_name
echo "$expected" > '.expected'
[ "$(cmp '.expected' '.gitignore'; echo $?)" -eq 0 ]
rm "$test_file" '.expected'
}
@ -107,8 +115,8 @@ function teardown {
[ "$status" -eq 0 ]
[[ -f "$current_dir/.gitignore" ]]
run _file_has_line "$test_file" "$current_dir/.gitignore"
[ "$status" -eq 0 ]
run file_has_line "$test_file" "$current_dir/.gitignore"
[ "$output" = '0' ]
# .gitignore was not created:
[[ ! -f ".gitignore" ]]

Loading…
Cancel
Save