Skip to content

Commit

Permalink
fixed problem with spaces in names during commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelwittig committed May 3, 2016
1 parent c769c5d commit 9fa6d45
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
6 changes: 3 additions & 3 deletions git-secrets
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ git_grep() {
local options="$1"; shift
local files=$@ combined_patterns=$(load_combined_patterns)
[ -z "${combined_patterns}" ] && return 1
GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" $@
GREP_OPTIONS= LC_ALL=C git grep -nwHEI ${options} "${combined_patterns}" $files
}

# Performs a regular grep, taking into account patterns and recursion.
Expand All @@ -115,7 +115,7 @@ regular_grep() {
local files=$@ patterns=$(load_patterns) action='skip'
[ -z "${patterns}" ] && return 1
[ "${RECURSIVE}" -eq 1 ] && action="recurse"
GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHE "${patterns}" $@
GREP_OPTIONS= LC_ALL=C grep -d "${action}" -nwHE "${patterns}" $files
}

# Process the given status ($1) and output variables ($2).
Expand Down Expand Up @@ -166,7 +166,7 @@ pre_commit_hook() {
# Diff against HEAD if this is not the first commit in the repo.
git rev-parse --verify HEAD >/dev/null 2>&1 && rev="HEAD"
# Filter out deleted files using --diff-filter
scan_with_fn_or_die "scan" "$(git diff-index --diff-filter 'ACMU' --name-only --cached $rev --)"
IFS=$'\n' scan_with_fn_or_die "scan" "$(git diff-index --diff-filter 'ACMU' --name-only --cached $rev --)"
}

# Determines if merging in a commit will introduce tainted history.
Expand Down
9 changes: 9 additions & 0 deletions test/pre-commit.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ load test_helper
[ "${lines[2]}" == "failure2.txt:1:me" ]
}

@test "Rejects commits with prohibited patterns in changeset with filename that contain spaces" {
setup_bad_repo_with_spaces
repo_run git-secrets --install $TEST_REPO
cd $TEST_REPO
run git commit -m 'Contents are bad not the message'
[ $status -eq 1 ]
[ "${lines[0]}" == "da ta.txt:1:@todo more stuff" ]
}

@test "Scans staged files" {
cd $TEST_REPO
repo_run git-secrets --install $TEST_REPO
Expand Down
8 changes: 8 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ setup_bad_repo() {
cd -
}

# Creates a repo that should fail
setup_bad_repo_with_spaces() {
cd $TEST_REPO
echo '@todo more stuff' > "$TEST_REPO/da ta.txt"
git add -A
cd -
}

# Creates a repo that should fail
setup_bad_repo_history() {
cd $TEST_REPO
Expand Down

0 comments on commit 9fa6d45

Please sign in to comment.