Skip to content

Commit

Permalink
Merge pull request #231 from joshrabinowitz/hide-in-subdir
Browse files Browse the repository at this point in the history
fix for issue #230 (git secret hide fails in subdir). Also disables builds on alpine-latest for #232
  • Loading branch information
joshrabinowitz committed Jul 13, 2018
2 parents 4797c99 + 826dfeb commit e515eb8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 23 deletions.
24 changes: 12 additions & 12 deletions .travis.yml
Expand Up @@ -7,12 +7,12 @@ matrix:
sudo: required
language: ruby
rvm: 2.4
- os: linux
env: KITCHEN_REGEXP="gnupg1-alpine-latest"
services: docker
sudo: required
language: ruby
rvm: 2.4
#- os: linux
# env: KITCHEN_REGEXP="gnupg1-alpine-latest"
# services: docker
# sudo: required
# language: ruby
# rvm: 2.4
- os: linux
env: KITCHEN_REGEXP="gnupg1-debian-latest"
services: docker
Expand All @@ -37,12 +37,12 @@ matrix:
sudo: required
language: ruby
rvm: 2.4
- os: linux
env: KITCHEN_REGEXP="gnupg2-alpine-latest"
services: docker
sudo: required
language: ruby
rvm: 2.4
#- os: linux
# env: KITCHEN_REGEXP="gnupg2-alpine-latest"
# services: docker
# sudo: required
# language: ruby
# rvm: 2.4
- os: linux
env: KITCHEN_REGEXP="gnupg2-debian-latest"; GITSECRET_DIST="deb"
services: docker
Expand Down
16 changes: 5 additions & 11 deletions src/commands/git_secret_hide.sh
Expand Up @@ -120,12 +120,6 @@ function hide {
# make sure all the unencrypted files needed are present
local to_hide=()
while read -r record; do
local filename
filename=$(_get_record_filename "$record")

if [[ ! -f "$filename" ]]; then
_abort "file not found: $filename"
fi
to_hide+=("$record") # add record to array
done < "$path_mappings"

Expand All @@ -138,11 +132,6 @@ function hide {
fsdb_file_hash=$(_get_record_hash "$record")
encrypted_filename=$(_get_encrypted_filename "$filename")

# Checking that file is valid:
if [[ ! -f "$filename" ]]; then
_abort "file not found: $filename"
fi

local recipients
recipients=$(_get_recipients)

Expand All @@ -154,6 +143,11 @@ function hide {
input_path=$(_append_root_path "$filename")
output_path=$(_append_root_path "$encrypted_filename")

# Checking that file is valid:
if [[ ! -f "$input_path" ]]; then
_abort "file not found: $input_path"
fi

file_hash=$(_get_file_hash "$input_path")

# encrypt file only if required
Expand Down
22 changes: 22 additions & 0 deletions tests/test_hide.bats
Expand Up @@ -37,6 +37,28 @@ function teardown {
[ -f "$encrypted_file" ]
}

@test "run 'hide' from inside subdirectory" {
# Preparations:
local root_dir='test_sub_dir'
mkdir -p "$root_dir"
local second_file="$root_dir/second_file.txt"
local second_content="some content"
set_state_secret_add "$second_file" "$second_content"

# Verify that the second file is there:
[ -f "$second_file" ]

# cd into the subdir
cd "$root_dir"

# Now it should hide 2 files:
run git secret hide
[ "$status" -eq 0 ]

# cd back
cd ".."
}

@test "run 'hide' with missing file" {
# Preparations:
local second_file="second_file.txt"
Expand Down

0 comments on commit e515eb8

Please sign in to comment.