From a4a8ea62ed74b954e674c5fc347ee4b4b738222f Mon Sep 17 00:00:00 2001 From: joshr Date: Mon, 16 Apr 2018 21:50:28 -0400 Subject: [PATCH 1/4] better error messages --- src/_utils/_git_secret_tools.sh | 2 +- src/main.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index 1e1a38b2..7dee588b 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -424,7 +424,7 @@ function _get_gpg_local { function _abort { local message="$1" # required - >&2 echo "$message abort." + >&2 echo "git-secret: abort: $message" exit 1 } diff --git a/src/main.sh b/src/main.sh index f4f52eaf..c9f21e3a 100755 --- a/src/main.sh +++ b/src/main.sh @@ -7,7 +7,7 @@ function _check_setup { local is_tree is_tree=$(_is_inside_git_tree) if [[ "$is_tree" -ne 0 ]]; then - _abort "repository is broken. try running 'git init' or 'git clone'." + _abort "Not in dir with git repo. Use 'git init' or 'git clone', then in repo use 'git secret init'" fi # Checking if the '.gitsecret' is not ignored: From 0dc00367f91d871949d13ea85c181c16f124bfd0 Mon Sep 17 00:00:00 2001 From: joshr Date: Mon, 16 Apr 2018 21:58:32 -0400 Subject: [PATCH 2/4] improve message when .git exists but not .gitsecret --- src/_utils/_git_secret_tools.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index 7dee588b..cf4f7341 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -484,7 +484,9 @@ function _secrets_dir_exists { full_path=$(_get_secrets_dir) if [[ ! -d "$full_path" ]]; then - _abort "$full_path does not exist." + local name + name=$(basename "$full_path") + _abort "secrets directory '$name' does not exist. Use 'git secret init' to initialize git-secret" fi } From 33adc19682886a61de6463f7dfb73b13f7b092ca Mon Sep 17 00:00:00 2001 From: joshr Date: Mon, 16 Apr 2018 22:24:11 -0400 Subject: [PATCH 3/4] fix test to match _abort() output --- tests/test_init.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_init.bats b/tests/test_init.bats index 2a212731..79d3fad5 100644 --- a/tests/test_init.bats +++ b/tests/test_init.bats @@ -71,6 +71,6 @@ function teardown { mkdir "$secrets_dir" run git secret init - [ "$output" = "already inited. abort." ] + [ "$output" = "git-secret: abort: already inited." ] [ "$status" -eq 1 ] } From 4766df2110135eaf59c935a522fbe19f3f3a7b01 Mon Sep 17 00:00:00 2001 From: joshr Date: Mon, 16 Apr 2018 22:52:06 -0400 Subject: [PATCH 4/4] improve error messages in add, killperson, remove, tell, and main --- src/_utils/_git_secret_tools.sh | 4 ++-- src/commands/git_secret_add.sh | 2 +- src/commands/git_secret_killperson.sh | 2 +- src/commands/git_secret_remove.sh | 2 +- src/commands/git_secret_tell.sh | 2 +- src/main.sh | 4 ++-- 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/_utils/_git_secret_tools.sh b/src/_utils/_git_secret_tools.sh index cf4f7341..c4f91f4c 100644 --- a/src/_utils/_git_secret_tools.sh +++ b/src/_utils/_git_secret_tools.sh @@ -486,7 +486,7 @@ function _secrets_dir_exists { if [[ ! -d "$full_path" ]]; then local name name=$(basename "$full_path") - _abort "secrets directory '$name' does not exist. Use 'git secret init' to initialize git-secret" + _abort "directory '$name' does not exist. Use 'git secret init' to initialize git-secret" fi } @@ -510,7 +510,7 @@ function _secrets_dir_is_not_ignored { fi if [[ ! $ignores -eq 1 ]]; then - _abort "'$git_secret_dir' is ignored." + _abort "'$git_secret_dir' is in .gitignore" fi } diff --git a/src/commands/git_secret_add.sh b/src/commands/git_secret_add.sh index 8e2476fe..450b697a 100644 --- a/src/commands/git_secret_add.sh +++ b/src/commands/git_secret_add.sh @@ -52,7 +52,7 @@ function add { if [[ ! "${#not_ignored[@]}" -eq 0 ]]; then # And show them all at once. local message - message="these files are not ignored: $* ;" + message="these files are not in .gitignore: $* ;" if [[ "$auto_ignore" -eq 0 ]]; then # This file is not ignored. user don't want it to be added automatically. diff --git a/src/commands/git_secret_killperson.sh b/src/commands/git_secret_killperson.sh index f27dcd33..0d637583 100644 --- a/src/commands/git_secret_killperson.sh +++ b/src/commands/git_secret_killperson.sh @@ -22,7 +22,7 @@ function killperson { local emails=( "$@" ) if [[ ${#emails[@]} -eq 0 ]]; then - _abort "at least one email is required." + _abort "at least one email is required for killperson." fi # Getting the local `gpg` command: diff --git a/src/commands/git_secret_remove.sh b/src/commands/git_secret_remove.sh index 94fc8791..8eada67f 100644 --- a/src/commands/git_secret_remove.sh +++ b/src/commands/git_secret_remove.sh @@ -37,7 +37,7 @@ function remove { # Checking if file exists: if [[ ! -f "$path" ]]; then - _abort "$item is not a file." + _abort "not a file: $item" fi # Deleting it from path mappings: diff --git a/src/commands/git_secret_tell.sh b/src/commands/git_secret_tell.sh index 0dd11b04..bb0e5db1 100644 --- a/src/commands/git_secret_tell.sh +++ b/src/commands/git_secret_tell.sh @@ -77,7 +77,7 @@ function tell { fi if [[ ! -s "$keyfile" ]]; then - _abort 'gpg key is empty. check your key name: "gpg --list-keys".' + _abort "no keyfile found for '$email'. Check your key name: 'gpg --list-keys'." fi # Importing public key to the local keychain: diff --git a/src/main.sh b/src/main.sh index c9f21e3a..2277d1d1 100755 --- a/src/main.sh +++ b/src/main.sh @@ -7,7 +7,7 @@ function _check_setup { local is_tree is_tree=$(_is_inside_git_tree) if [[ "$is_tree" -ne 0 ]]; then - _abort "Not in dir with git repo. Use 'git init' or 'git clone', then in repo use 'git secret init'" + _abort "not in dir with git repo. Use 'git init' or 'git clone', then in repo use 'git secret init'" fi # Checking if the '.gitsecret' is not ignored: @@ -27,7 +27,7 @@ function _check_setup { function _incorrect_usage { - echo "$1" + echo "git-server: abort: $1" usage exit "$2" }