Skip to content

Commit

Permalink
Change Readme prompt default to 'No' (#43)
Browse files Browse the repository at this point in the history
- Change Readme prompt default to 'No'.
- Fix not-working test 111.
  • Loading branch information
gabyx authored Aug 31, 2021
1 parent 0189029 commit 5dd8713
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 69 deletions.
71 changes: 36 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,40 @@ jobs:

workflows:
version: 2
# test-all:
# jobs:
# - linux:
# matrix:
# parameters:
# test:
# [
# "test-alpine",
# "test-alpine-nolfs",
# "test-alpine-user",
# "test-corehookspath",
# "test-whitespace",
# "test-testsuite",
# "test-rules",
# ]
# filters: &filters
# branches:
# only: &task-branches
# - /feature\/.*/
# - /bugfix\/.*/
# - linux:
# matrix:
# parameters:
# test: ["test-coverage"]
# filters:
# branches:
# only:
# - /feature\/.*/
# - /bugfix\/.*/
# - "main"
test-all:
jobs:
- linux:
matrix:
parameters:
test:
[
"test-alpine",
"test-alpine-nolfs",
"test-alpine-user",
"test-corehookspath",
"test-whitespace",
"test-testsuite",
"test-rules",
]
filters: &filters
branches:
only: &task-branches
- /feature\/.*/
- /bugfix\/.*/
- linux:
matrix:
parameters:
test: ["test-coverage"]
filters:
branches:
only:
- /feature\/.*/
- /bugfix\/.*/
- "main"

- windows:
matrix:
parameters:
test: ["test-windows"]
filters: *filters

# - windows:
# matrix:
# parameters:
# test: ["test-windows"]
# filters: *filters
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Build Status](https://travis-ci.org/gabyx/githooks.svg?branch=main)](https://travis-ci.org/gabyx/githooks)
[![Coverage Status](https://coveralls.io/repos/github/gabyx/Githooks/badge.svg?branch=main)](https://coveralls.io/github/gabyx/Githooks?branch=main)
[![goreleaser](https://github.com/gabyx/Githooks/actions/workflows/release.yml/badge.svg)](https://github.com/gabyx/Githooks/actions/workflows/release.yml)
[![goreleaser](https://github.com/gabyx/Githooks/actions/workflows/release.yml/badge.svg?branch=prepare-v2.0.3)](https://github.com/gabyx/Githooks/actions/workflows/release.yml)
[![Go Report Card](https://goreportcard.com/badge/github.com/gabyx/githooks)](https://goreportcard.com/report/github.com/gabyx/githooks)
[![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/nlohmann/json/master/LICENSE.MIT)
[![GitHub Releases](https://img.shields.io/github/release/gabyx/githooks.svg)](https://github.com/gabyx/githooks/releases)
Expand Down
8 changes: 5 additions & 3 deletions githooks/cmd/common/install/disable-hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@ func GetHookDisableCallback(

log.AssertNoError(err, "Could not show prompt.")

if userAnswer == "s" || userAnswer == "a" {
uiSettings.DeleteDetectedLFSHooks = userAnswer // Store the decision.
if userAnswer == "s" {
uiSettings.DeleteDetectedLFSHooks = "n" // Store the decision.
} else if userAnswer == "a" {
uiSettings.DeleteDetectedLFSHooks = "y" // Store the decision.
}

}
Expand All @@ -54,7 +56,7 @@ func GetHookDisableCallback(

return hooks.DeleteHook
default:
log.WarnF("Previous hook '%s' will be disabled (backuped)", file)
log.WarnF("Previous hook '%s' will be disabled (backed up)", file)

return hooks.BackupHook
}
Expand Down
6 changes: 3 additions & 3 deletions githooks/cmd/common/install/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ func setupReadme(
}

answer, err := uiSettings.PromptCtx.ShowOptions(
msg, "(Yes, no, all, skip all)",
"Y/n/a/s",
"Yes", "No", "All", "Skip All")
msg, "(No, yes, all, skip all)",
"N/y/a/s",
"No", "Yes", "All", "Skip All")
log.AssertNoError(err, "Could not show prompt.")

switch answer {
Expand Down
6 changes: 3 additions & 3 deletions githooks/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ func runDeleteDetectedLFSHooks(ctx *ccm.CmdContext, opts *SetOptions) {

switch {
case opts.Set:
err := ctx.GitX.SetConfig(opt, "a", git.GlobalScope)
err := ctx.GitX.SetConfig(opt, "y", git.GlobalScope)
ctx.Log.AssertNoErrorPanicF(err, "Could not set Git config '%s'.", opt)
ctx.Log.InfoF("Detected LFS hooks will now automatically be deleted during install.")

Expand All @@ -604,9 +604,9 @@ func runDeleteDetectedLFSHooks(ctx *ccm.CmdContext, opts *SetOptions) {
case opts.Print:
conf := ctx.GitX.GetConfig(opt, git.GlobalScope)
switch {
case conf == "a":
case conf == "a" /* legacy */ || conf == "y":
ctx.Log.Info("Detected LFS hooks are automatically deleted during install.")
case conf == "n":
case conf == "s" /* legacy */ || conf == "n":
ctx.Log.Info("Detected LFS hooks are not automatically deleted during install",
"but instead backed up.")
default:
Expand Down
2 changes: 1 addition & 1 deletion githooks/cmd/installer/installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@ func storeSettings(log cm.ILogContext, settings *Settings, uiSettings *install.U
if strs.IsNotEmpty(uiSettings.DeleteDetectedLFSHooks) {
err := git.Ctx().SetConfig(
hooks.GitCKDeleteDetectedLFSHooksAnswer, uiSettings.DeleteDetectedLFSHooks, git.GlobalScope)
log.AssertNoError(err, "Could not store config 'githooks.deleteDetectedLFSHooks'.")
log.AssertNoError(err, "Could not store config '%v'.", uiSettings.DeleteDetectedLFSHooks)
}

err := settings.RegisteredGitDirs.Store(settings.InstallDir)
Expand Down
2 changes: 1 addition & 1 deletion githooks/hooks/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ var lfsDetectionRe = regexp.MustCompile(`(git\s+lfs|git-lfs)`)
type HookDisableOption int

const (
// BackupHook defines that a hook file gets backuped.
// BackupHook defines that a hook file gets backed up.
BackupHook HookDisableOption = 1
// DeleteHook defines that a hook file gets deleted.
DeleteHook HookDisableOption = 2
Expand Down
6 changes: 3 additions & 3 deletions tests/step-055.sh
Original file line number Diff line number Diff line change
Expand Up @@ -175,22 +175,22 @@ if ! echo "$OUT" | grep "step4.1" | grep -q -E "ns-path: +'ns:gh-self/post-commi
fi

# Check if we can get the location
root1=$(git hooks shared root "ns:repo1")
root1=$("$GH_INSTALL_BIN_DIR/cli" shared root "ns:repo1")
if [ "$root1" != "$location1" ]; then
echo "! Unexpected cli shared root output (15):"
echo "'$root1' != '$location1'"
exit 1
fi

root2=$(git hooks shared root "ns:repo2")
root2=$("$GH_INSTALL_BIN_DIR/cli" shared root "ns:repo2")
if [ "$root2" != "$location2" ]; then
echo "! Unexpected cli shared root output (16):"
echo "'$root2' != '$location2'"

exit 1
fi

root3=$(git hooks shared root "ns:repo3")
root3=$("$GH_INSTALL_BIN_DIR/cli" shared root "ns:repo3")
if [ "$root3" != "$location3" ]; then
echo "! Unexpected cli shared root output (17):"
echo "'$root3' != '$location3'"
Expand Down
25 changes: 14 additions & 11 deletions tests/step-111.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,45 +40,47 @@ y
$GH_TEST_TMP
y
n
s
" | "$GH_TEST_BIN/cli" installer --stdin || exit 1

if [ -f "$GH_TEST_TMP/test109.1/.git/hooks/pre-commit.disabled.githooks" ]; then
echo '! Expected hook to be deleted'
echo '! Expected hook to be deleted (1)'
exit 1
fi
if [ ! -f "$GH_TEST_TMP/test109.2/.git/hooks/pre-commit.disabled.githooks" ] &&
[ ! -f "$GH_TEST_TMP/test109.3/.git/hooks/pre-commit.disabled.githooks" ]; then
echo '! Expected hook to be moved'
echo '! Expected hook to be moved (2)'
exit 1
fi

cd "$GH_TEST_TMP/test109.2" &&
git commit --allow-empty -m 'Init' 2>/dev/null || exit 1
if grep 'Previous2' "$GH_TEST_TMP/test-109.out"; then
echo '! Expected hook to be disabled'
echo '! Expected hook to be disabled (3)'
exit 1
fi

cd "$GH_TEST_TMP/test109.3" &&
git commit --allow-empty -m 'Init' 2>/dev/null || exit 1
if grep 'Previous3' "$GH_TEST_TMP/test-109.out"; then
echo '! Expected hook to be disabled'
echo '! Expected hook to be disabled (4)'
exit 1
fi

out=$("$GH_INSTALL_BIN_DIR/cli" config delete-detected-lfs-hooks --print)
if ! echo "$out" | grep -q "default disabled and backed up"; then
echo "! Expected the correct config behavior"
if ! echo "$out" | grep -q "but instead backed up"; then
echo "! Expected the correct config behavior (5)"
echo "$out"
exit 1
fi

# For coverage
"$GH_INSTALL_BIN_DIR/cli" config delete-detected-lfs-hooks --reset || exit 1
out=$("$GH_INSTALL_BIN_DIR/cli" config delete-detected-lfs-hooks --print)
if ! echo "$out" | grep -q "default disabled and backed up"; then
echo "! Expected the correct config behavior"
if ! echo "$out" | grep -q "left to the user"; then
echo "! Expected the correct config behavior (6)"
echo "$out"
exit 1
fi

# Reset every repo and do again
Expand All @@ -93,15 +95,16 @@ echo "n
y
$GH_TEST_TMP
N
a
" | "$GH_TEST_BIN/cli" installer --stdin || exit 1

if [ ! -f "$GH_TEST_TMP/test109.1/.git/hooks/pre-commit.disabled.githooks" ]; then
echo '! Expected hook to be moved'
echo '! Expected hook to be moved (7)'
exit 1
fi
if [ -f "$GH_TEST_TMP/test109.2/.git/hooks/pre-commit.disabled.githooks" ] &&
[ -f "$GH_TEST_TMP/test109.3/.git/hooks/pre-commit.disabled.githooks" ]; then
echo '! Expected hook to be deleted'
echo '! Expected hook to be deleted (8)'
exit 1
fi
18 changes: 10 additions & 8 deletions tests/test-coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,22 @@ RUN git config --global githooks.deleteDetectedLFSHooks "n"
# Replace some statements which rely on proper CLI output
# The built instrumented executable output test&coverage shit...
RUN sed -i -E 's@cli" shared root-from-url(.*)\)@cli" shared root-from-url\1 | grep "^/")@g' \\
"\$GH_TESTS"/step-* && \\
sed -i -E 's@cli" shared root(.*)\)@cli" shared root\1 | grep "^/")@g' \\
"\$GH_TESTS"/step-*
# Replace all runnner/cli/dialog/'git hooks' invocations.
# Foward over 'coverage/forwarder'.
RUN sed -i -E 's@"(.GH_INSTALL_BIN_DIR|.GH_TEST_BIN)/cli"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1/cli"@g' \\
"\$GH_TESTS/exec-steps.sh" \\
"\$GH_TESTS"/step-*
RUN sed -i -E 's@"(.GH_INSTALL_BIN_DIR|.GH_TEST_BIN)/runner"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1/runner"@g' \\
"\$GH_TESTS"/step-*
RUN sed -i -E 's@"(.GH_INSTALL_BIN_DIR|.GH_TEST_BIN)/dialog"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1/dialog"@g' \\
"\$GH_TESTS"/step-*
RUN sed -i -E 's@".DIALOG"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1"@g' \\
"\$GH_TESTS"/step-*
RUN sed -i -E 's@git hooks@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\$GH_INSTALL_BIN_DIR/cli"@g' \\
"\$GH_TESTS"/step-* && \\
sed -i -E 's@"(.GH_INSTALL_BIN_DIR|.GH_TEST_BIN)/runner"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1/runner"@g' \\
"\$GH_TESTS"/step-* && \\
sed -i -E 's@"(.GH_INSTALL_BIN_DIR|.GH_TEST_BIN)/dialog"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1/dialog"@g' \\
"\$GH_TESTS"/step-* && \\
sed -i -E 's@".DIALOG"@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\1"@g' \\
"\$GH_TESTS"/step-* && \\
sed -i -E 's@git hooks@"\$GH_TEST_REPO/githooks/coverage/forwarder" "\$GH_INSTALL_BIN_DIR/cli"@g' \\
"\$GH_TESTS"/step-*
${ADDITIONAL_INSTALL_STEPS:-}
Expand Down

0 comments on commit 5dd8713

Please sign in to comment.