Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Enable env. substitution in githooks.installDir #144

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ jobs:
default: "test-alpine"
type: string
executor:
size: medium
name: win/server-2022
version: 2023.04.1
version: 2023.11.1
steps:
- checkout
- run:
Expand Down
2 changes: 1 addition & 1 deletion .githooks/pre-commit/cli-docs-up-to-date
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ for file in $STAGED_FILES; do
exit 1
}

git add "$repoDir/docs/cli/"*
# git add "$repoDir/docs/cli/"*

echo "* Docs regenerated." >&2
else
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,7 @@ curl -sL https://raw.githubusercontent.com/gabyx/githooks/main/scripts/install.s
The installer always maintains a Githooks clone inside `<installDir>/release`
for its automatic update logic. The specified custom clone URL and branch will
then be used for further updates in the above example (see
[update machanics](#update-mechanics)).
[update mechanics](#update-mechanics)).

Because the installer **always** downloads the latest release (here from another
URL/branch), it needs deploy settings to know where to get the binaries from.
Expand Down
15 changes: 7 additions & 8 deletions docs/cli/git_hooks_installer.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ Githooks installer application.

### Synopsis

Githooks installer application.
It downloads the Githooks artifacts of the current version
from a deploy source and verifies its checksums and signature.
Then it calls the installer on the new version which
will then run the installation procedure for Githooks.
Githooks installer application. It downloads the Githooks artifacts of the
current version from a deploy source and verifies its checksums and signature.
Then it calls the installer on the new version which will then run the
installation procedure for Githooks.

See further information at https://github.com/gabyx/githooks/blob/main/README.md

Expand All @@ -28,7 +27,7 @@ git hooks installer [flags]
--skip-install-into-existing Skip installation into existing repositories
defined by a search path.
--prefix string Githooks installation prefix such that
`<prefix>/.githooks` will be the installation directory.
`<prefix>/.githooks` will be the installation directory (env. variables e.g. `$X` and '~' allowed).
--template-dir string The preferred template directory to use.
--maintained-hooks strings A set of hook names which are maintained in the template directory.
Any argument can be a hook name `<hookName>`, `all` or `server`.
Expand Down Expand Up @@ -62,6 +61,6 @@ git hooks installer [flags]

### SEE ALSO

* [git hooks](git_hooks.md) - Githooks CLI application
- [git hooks](git_hooks.md) - Githooks CLI application

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
17 changes: 8 additions & 9 deletions docs/dialog/dialog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ dialog

### SEE ALSO

- [dialog entry](dialog_entry.md) - Shows a entry dialog.
- [dialog file-save](dialog_file-save.md) - Shows a file save dialog.
- [dialog file-selection](dialog_file-selection.md) - Shows a file selection
dialog.
- [dialog message](dialog_message.md) - Shows a message dialog.
- [dialog notify](dialog_notify.md) - Shows a notification.
- [dialog options](dialog_options.md) - Shows a options selection dialog.

###### Auto generated by spf13/cobra
* [dialog entry](dialog_entry.md) - Shows a entry dialog.
* [dialog file-save](dialog_file-save.md) - Shows a file save dialog.
* [dialog file-selection](dialog_file-selection.md) - Shows a file selection dialog.
* [dialog message](dialog_message.md) - Shows a message dialog.
* [dialog notify](dialog_notify.md) - Shows a notification.
* [dialog options](dialog_options.md) - Shows a options selection dialog.

###### Auto generated by spf13/cobra
14 changes: 7 additions & 7 deletions docs/dialog/dialog_entry.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ Shows a entry dialog.

### Synopsis

Shows a entry dialog similar to `zenity`. Currently extra buttons are not
supported on all platforms. Unix/Windows supports multiple extra buttons, MacOS
does not.
Shows a entry dialog similar to `zenity`.
Currently extra buttons are not supported on all platforms.
Unix/Windows supports multiple extra buttons, MacOS does not.

# Exit Codes:

- `0` : User pressed `Ok`.
- `1` : User pressed `Cancel` or closed the dialog.
- `2` : The user pressed an extra button. The output contains the index of that
button.
- `2` : The user pressed an extra button.
The output contains the index of that button.

```
dialog entry
Expand Down Expand Up @@ -54,6 +54,6 @@ dialog entry

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
10 changes: 5 additions & 5 deletions docs/dialog/dialog_file-save.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ Shows a file save dialog.
### Synopsis

Shows a file save dialog similar to `zenity`.

# Exit Codes:

- `0` : User pressed `Ok`. The output contains the selected paths separated by
`--separator`. All paths use forward slashes on any platform.
- `0` : User pressed `Ok`. The output contains the selected paths
separated by `--separator`. All paths use forward slashes
on any platform.
- `1` : User pressed `Cancel` or closed the dialog.
- `5` : The dialog was closed due to timeout.

Expand Down Expand Up @@ -48,6 +48,6 @@ dialog file-save

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
9 changes: 5 additions & 4 deletions docs/dialog/dialog_file-selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ Shows a file selection dialog similar to `zenity`.

# Exit Codes:

- `0` : User pressed `Ok`. The output contains the selected paths separated by
`--separator`. All paths use forward slashes on any platform.
- `0` : User pressed `Ok`. The output contains the selected paths
separated by `--separator`. All paths use forward slashes
on any platform.
- `1` : User pressed `Cancel` or closed the dialog.
- `5` : The dialog was closed due to timeout.

Expand Down Expand Up @@ -47,6 +48,6 @@ dialog file-selection

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
13 changes: 7 additions & 6 deletions docs/dialog/dialog_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ Shows a message dialog.

Shows a message dialog similar to `zenity`.

Currently only one extra button is supported on all platforms. Only Unix
supports multiple extra buttons. Use `options` to have more choices.
Currently only one extra button is supported on all platforms.
Only Unix supports multiple extra buttons.
Use `options` to have more choices.

# Exit Codes:

- `0` : User pressed `Ok`.
- `1` : User pressed `Cancel` or closed the dialog.
- `2` : The user pressed an extra button. The output contains the index of that
button.
- `2` : The user pressed an extra button.
The output contains the index of that button.

```
dialog message
Expand Down Expand Up @@ -54,6 +55,6 @@ dialog message

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
4 changes: 2 additions & 2 deletions docs/dialog/dialog_notify.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ dialog notify

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
17 changes: 9 additions & 8 deletions docs/dialog/dialog_options.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ Shows a options selection dialog.

Shows a list selection dialog similar to `zenity`.

Extra buttons are only supported on Unix and Windows. If not using `--multiple`
you can also use the button style options with `--style 1` which uses buttons
instead of a listbox.
Extra buttons are only supported on Unix and Windows.
If not using `--multiple` you can also use the
button style options with `--style 1` which uses buttons instead
of a listbox.

# Exit Codes:

- `0` : `Ok` was pressed. The output contains the indices of the selected items
separated by `--separator`.
separated by `--separator`.
- `1` : `Cancel` was pressed or the dialog was closed.
- `2` : The user pressed an extra button. The output contains the index of that
button on the first line.
- `2` : The user pressed an extra button.
The output contains the index of that button on the first line.
- `5` : The dialog was closed due to timeout.

```
Expand Down Expand Up @@ -61,6 +62,6 @@ dialog options

### SEE ALSO

- [dialog](dialog.md) - Githooks dialog application similar to `zenity`.
* [dialog](dialog.md) - Githooks dialog application similar to `zenity`.

###### Auto generated by spf13/cobra
###### Auto generated by spf13/cobra
12 changes: 2 additions & 10 deletions githooks/apps/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"strings"
"time"

"github.com/mitchellh/go-homedir"
"github.com/pbenner/threadpool"
"github.com/pkg/math"
)
Expand Down Expand Up @@ -196,15 +195,8 @@ func setupSettings(repoPath string) (HookSettings, UISettings) {
func getInstallDir(gitx *git.Context) string {
installDir := hooks.GetInstallDir(gitx)

setDefault := func() {
usr, err := homedir.Dir()
cm.AssertNoErrorPanic(err, "Could not get home directory.")
usr = filepath.ToSlash(usr)
installDir = path.Join(usr, hooks.HooksDirName)
}

if strs.IsEmpty(installDir) {
setDefault()
installDir, _ = hooks.GetDefaultInstallDir()
} else if exists, err := cm.IsPathExisting(installDir); !exists {

log.AssertNoError(err,
Expand All @@ -214,7 +206,7 @@ func getInstallDir(gitx *git.Context) string {
"Install directory at '%s' is missing.",
installDir)

setDefault()
installDir, _ = hooks.GetDefaultInstallDir()

log.WarnF(
"Falling back to default directory at '%s'.\n"+
Expand Down
6 changes: 4 additions & 2 deletions githooks/cmd/common/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ type CmdContext struct {
Cwd string // The current working directory.
GitX *git.Context // The git context in the current working directory.

InstallDir string // The install directory.
CloneDir string // The release clone dir inside the install dir.
InstallDir string // The install directory.
InstallDirRaw string // The raw install directory with out env. variables expanded.

CloneDir string // The release clone dir inside the install dir.

Log cm.ILogContext // The log context.
LogStats cm.ILogStats // The statistics of the log context.
Expand Down
7 changes: 5 additions & 2 deletions githooks/cmd/common/install/install-prompts.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package install

import (
"os"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -43,6 +45,7 @@ func PromptExistingRepos(
}

homeDir, err := homedir.Dir()
homeDir = filepath.ToSlash(homeDir)
cm.AssertNoErrorPanic(err, "Could not get home directory.")

searchDir := gitx.GetConfig(hooks.GitCKPreviousSearchDir, git.GlobalScope)
Expand Down Expand Up @@ -77,13 +80,13 @@ func PromptExistingRepos(
}

searchDir, err = promptx.ShowEntry(
"Where do you want to start the search?",
"Where do you want to start the search\n(env. variables are expanded)?",
searchDir,
prompt.CreateValidatorIsDirectory(homeDir))
log.AssertNoError(err, "Could not show prompt.")
}

searchDir = cm.ReplaceTildeWith(searchDir, homeDir)
searchDir = filepath.ToSlash(os.ExpandEnv(cm.ReplaceTildeWith(searchDir, homeDir)))

if !cm.IsDirectory(searchDir) {
log.WarnF("Search directory\n'%s'\nis not a directory.\n" + existingWarn[idx])
Expand Down
35 changes: 0 additions & 35 deletions githooks/cmd/common/install/load-install.go

This file was deleted.

2 changes: 1 addition & 1 deletion githooks/cmd/common/install/template-dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
func CheckTemplateDir(targetDir string, subFolderIfExists string) (string, error) {
if strs.IsNotEmpty(targetDir) {

targetDir, err := cm.ReplaceTilde(targetDir)
targetDir, err := cm.ReplaceTilde(targetDir, false)
if err != nil {
return "", cm.ErrorF("Could not replace tilde '~' in '%s'.", targetDir)
}
Expand Down
Loading