Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/_utils/_git_secret_tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ function _get_record_filename {
local filename
filename=$(echo "$record" | awk -F: '{print $1}')

# remove / in top level file
if [[ $filename == "/"* ]]; then
filename="${filename:1}"
fi

echo "$filename"
}

Expand Down Expand Up @@ -304,6 +309,12 @@ function _git_normalize_filename {

local result
result=$(git ls-files --full-name -o "$filename")

# if file is in the top level, append a / so only that top level file is considered
if [[ $filename != *"/"* ]]; then
result="/$result"
fi

echo "$result"
}

Expand Down
12 changes: 6 additions & 6 deletions tests/test_add.bats
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function teardown {

local files_list
files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]
[ "$files_list" = "/$filename" ]

# Cleaning up:
rm "$filename" ".gitignore"
Expand Down Expand Up @@ -70,7 +70,7 @@ function teardown {
echo "content" > "$test_file"

local quoted_name
quoted_name=$(printf '%q' "$test_file")
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"
Expand Down Expand Up @@ -114,7 +114,7 @@ function teardown {
[ "$status" -eq 0 ]

[[ -f "$current_dir/.gitignore" ]]
run file_has_line "$nested_dir/$test_file" "$current_dir/.gitignore"
run file_has_line "/$nested_dir/$test_file" "$current_dir/.gitignore"
[ "$output" = '0' ]

# .gitignore was not created:
Expand Down Expand Up @@ -205,7 +205,7 @@ function teardown {

local files_list
files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]
[ "$files_list" = "/$filename" ]

# Cleaning up:
rm "$filename" ".gitignore"
Expand Down Expand Up @@ -268,12 +268,12 @@ function teardown {

local files_list
files_list=$(cat "$path_mappings")
[ "$files_list" = "$filename" ]
[ "$files_list" = "/$filename" ]

# Ensuring the file is correctly git-ignored
run git check-ignore "$filename"
[ "$status" -eq 0 ]

# Cleaning up:
rm "$filename" ".gitignore"
}
}
10 changes: 5 additions & 5 deletions tests/test_hide.bats
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ function teardown {
[ "$status" -eq 0 ]

# File must be removed:
[ ! -f "$FILE_TO_HIDE" ]
[ ! -f "/$FILE_TO_HIDE" ]
}


Expand All @@ -287,7 +287,7 @@ function teardown {
[ "$status" -eq 0 ]

# File must be removed:
[ ! -f "$FILE_TO_HIDE" ]
[ ! -f "/$FILE_TO_HIDE" ]

# It should be verbose:
[[ "$output" == *"removing unencrypted files"* ]]
Expand All @@ -311,8 +311,8 @@ function teardown {
[ "$status" -eq 0 ]

# File must be removed:
[ ! -f "$FILE_TO_HIDE" ]
[ ! -f "$second_file" ]
[ ! -f "/$FILE_TO_HIDE" ]
[ ! -f "/$second_file" ]

# It should be verbose:
[[ "$output" == *"removing unencrypted files"* ]]
Expand All @@ -330,4 +330,4 @@ function teardown {
run git secret hide
[ "$status" -eq 0 ]
[[ "$output" == *"git-secret: done. 1 of 1 files are hidden."* ]]
}
}