Skip to content

Commit 607a509

Browse files
committed
Register hook in the cloned repo instead of under /etc/
1 parent 592d324 commit 607a509

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

components/supervisor/pkg/supervisor/supervisor.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func installDotfiles(ctx context.Context, cfg *Config, tokenService *InMemoryTok
751751
}
752752

753753
// write some feedback to the terminal
754-
out.WriteString(fmt.Sprintf("# echo linking %s -> %s\n", path, homeFN))
754+
_, _ = out.WriteString(fmt.Sprintf("# echo linking %s -> %s\n", path, homeFN))
755755

756756
return os.Symlink(path, homeFN)
757757
})
@@ -810,7 +810,6 @@ func configureGit(cfg *Config) {
810810
{"alias.lg", "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"},
811811
{"credential.helper", "/usr/bin/gp credential-helper"},
812812
{"safe.directory", "*"},
813-
{"core.hooksPath", "/etc/git/hooks"},
814813
}
815814
if cfg.GitUsername != "" {
816815
settings = append(settings, []string{"user.name", cfg.GitUsername})
@@ -820,7 +819,7 @@ func configureGit(cfg *Config) {
820819
}
821820

822821
if cfg.CommitAnnotationEnabled {
823-
err := setupGitMessageHook()
822+
err := setupGitMessageHook(filepath.Join(cfg.RepoRoot, ".git", "hooks"))
824823
if err != nil {
825824
log.WithError(err).Error("cannot setup git message hook")
826825
}
@@ -842,14 +841,13 @@ const hookContent = `#!/bin/sh
842841
exec /usr/bin/gp git-commit-message-helper --file "$1"
843842
`
844843

845-
func setupGitMessageHook() error {
846-
hookPath := "/etc/git/hooks"
847-
if err := os.MkdirAll(hookPath, 0755); err != nil {
844+
func setupGitMessageHook(path string) error {
845+
if err := os.MkdirAll(path, 0755); err != nil {
848846
return err
849847
}
850848

851-
hookFile := filepath.Join(hookPath, "prepare-commit-msg")
852-
if err := os.WriteFile(hookFile, []byte(hookContent), 0755); err != nil {
849+
fn := filepath.Join(path, "prepare-commit-msg")
850+
if err := os.WriteFile(fn, []byte(hookContent), 0755); err != nil {
853851
return err
854852
}
855853

0 commit comments

Comments
 (0)