Fix for windows (#375)

* add test for travis-ci windows support
* Make 'ps' command options platform specific *nix/windows
* Add _clean_path for windows,  apply to all homedir input arguments
* export GITSECRET_DIST="windows" in git hook if running windows
* Bash lint fixes
pull/408/head
Jonas Karlsson 5 years ago committed by Josh Rabinowitz
parent 8adb7d5741
commit 54f74ede6a

@ -27,6 +27,11 @@ if [[ "$GITSECRET_DIST" == "brew" ]]; then
brew install gawk
fi
# Windows
if [[ "$GITSECRET_DIST" == "windows" ]]; then
choco install make shellcheck -y
fi
# Linux:
if [[ "$TRAVIS_OS_NAME" == "linux" ]] && [[ -n "$KITCHEN_REGEXP" ]]; then
update_linux

@ -12,10 +12,14 @@ function run_kitchen_tests {
bundle exec kitchen test --test-base-path="$PWD/.ci/integration" $KITCHEN_REGEXP
}
# Only running `make test` on standard (non-docker) builds,
# since it is called inside the docker container anyway.
# Local builds:
if [[ "$GITSECRET_DIST" == "brew" ]]; then
# Only running `make test` on standard (non-docker) build,
# since it is called inside the docker container anyway.
make test
fi
if [[ "$GITSECRET_DIST" == "windows" ]]; then
make test
fi

@ -3,6 +3,10 @@ dist: xenial
matrix:
fast_finish: true
include:
- os: windows
env: GITSECRET_DIST="windows"
sudo: required
language: sh
- os: linux
env: KITCHEN_REGEXP="gnupg1-alpine-latest"
services: docker
@ -90,8 +94,7 @@ matrix:
rvm: 2.6
before_install:
- gem update --system
- gem install bundler
- if [[ "$TRAVIS_OS_NAME" != "windows" ]]; then gem update --system && gem install bundler; fi
before_script:
- chmod +x ".ci/before_script.sh" && ".ci/before_script.sh"

@ -33,11 +33,14 @@ uninstall:
# Testing:
#
# The $(shell echo $${PWD}) construct is to access *nix paths under windows
# Under git for windows '$PATH' is set to windows paths, e.g. C:\Something
# Using a sub-shell we get the raw *nix paths, e.g. /c/Something
.PHONY: test
test: clean build
@chmod +x "./utils/tests.sh"; sync; \
export SECRET_PROJECT_ROOT="${PWD}"; \
export PATH="${PWD}/vendor/bats-core/bin:${PWD}:${PATH}"; \
export SECRET_PROJECT_ROOT="$(shell echo $${PWD})"; \
export PATH="$(shell echo $${PWD})/vendor/bats-core/bin:$(shell echo $${PWD}):$(shell echo $${PATH})"; \
"./utils/tests.sh"
#

@ -147,6 +147,12 @@ function _os_based {
# File System:
function _clean_path {
# This function transforms windows paths to *nix paths
# shellcheck disable=SC2001
echo "$1" | sed 's#^\([a-zA-Z]\):/#/\1/#'
}
function _set_config {
# This function creates a line in the config, or alters it.
@ -359,7 +365,7 @@ function _get_git_root_path {
# since `.gitsecret` (or value set by SECRETS_DIR env var) must be on the same level.
local result
result=$(git rev-parse --show-toplevel)
result=$(_clean_path "$(git rev-parse --show-toplevel)")
echo "$result"
}

@ -13,7 +13,7 @@ function cat {
p) passphrase=$OPTARG;;
d) homedir=$OPTARG;;
d) homedir=$(_clean_path "$OPTARG");;
*) _invalid_option_for 'cat';;
esac

@ -11,7 +11,7 @@ function changes {
p) passphrase=$OPTARG;;
d) homedir=$OPTARG;;
d) homedir=$(_clean_path "$OPTARG");;
*) _invalid_option_for 'changes';;
esac

@ -22,7 +22,7 @@ function reveal {
p) passphrase=$OPTARG;;
d) homedir=$OPTARG;;
d) homedir=$(_clean_path "$OPTARG");;
*) _invalid_option_for 'reveal';;
esac

@ -34,7 +34,7 @@ function tell {
m) self_email=1;;
d) homedir=$OPTARG;;
d) homedir=$(_clean_path "$OPTARG");;
*) _invalid_option_for 'tell';;
esac

@ -31,7 +31,6 @@ BEGIN { OFS=":"; FS=":"; }
# This command is used with absolute homedir set and disabled warnings:
GPGTEST="$SECRETS_GPG_COMMAND --homedir=$TEST_GPG_HOMEDIR --no-permission-warning --batch"
# Personal data:
# these two are 'normal' keys
@ -66,9 +65,15 @@ function test_user_password {
function stop_gpg_agent {
local username
username=$(id -u -n)
ps -wx -U "$username" | gawk \
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' \
> /dev/null 2>&1
if [[ "$GITSECRET_DIST" == "windows" ]]; then
ps -l -u "$username" | gawk \
'/gpg-agent/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' \
> /dev/null 2>&1
else
ps -wx -U "$username" | gawk \
'/gpg-agent --homedir/ { if ( $0 !~ "awk" ) { system("kill "$1) } }' \
> /dev/null 2>&1
fi
}

@ -11,6 +11,9 @@ if [[ "$BRANCH_NAME" != '(no branch)' ]]; then
# so some tests will be skipped. It is done, because `git rev-parse`
# is not working when running from pre-commit hook. See #334
export BATS_RUNNING_FROM_GIT=1
if [[ "$(uname -s)" == MINGW* ]]; then
export GITSECRET_DIST="windows"
fi
# Run tests:
make test

Loading…
Cancel
Save