diff --git a/cmd/ugitd/main.go b/cmd/ugitd/main.go index afb48cd..6dfa3d9 100644 --- a/cmd/ugitd/main.go +++ b/cmd/ugitd/main.go @@ -143,12 +143,12 @@ func requiredFS(repoDir string) error { if err != nil { return err } - fi.WriteString("#!/usr/bin/env bash\n") - fi.WriteString(fmt.Sprintf("%s pre-receive-hook\n", bin)) - fi.WriteString(fmt.Sprintf(`for hook in %s.d/*; do + fmt.Fprintln(fi, "#!/usr/bin/env bash") + fmt.Fprintf(fi, "%s pre-receive-hook\n", bin) + fmt.Fprintf(fi, `for hook in %s.d/*; do test -x "${hook}" && test -f "${hook}" || continue "${hook}" -done`, fp)) +done`, fp) fi.Close() return os.Chmod(fp, 0o755) @@ -162,7 +162,7 @@ func preReceive() { opts := make([]*packp.Option, 0) if pushCount, err := strconv.Atoi(os.Getenv("GIT_PUSH_OPTION_COUNT")); err == nil { - for idx := 0; idx < pushCount; idx++ { + for idx := range pushCount { opt := os.Getenv(fmt.Sprintf("GIT_PUSH_OPTION_%d", idx)) kv := strings.SplitN(opt, "=", 2) if len(kv) == 2 { diff --git a/internal/git/grep.go b/internal/git/grep.go index d10c933..f92567d 100644 --- a/internal/git/grep.go +++ b/internal/git/grep.go @@ -18,8 +18,8 @@ type GrepResult struct { // Grep performs a naive "code search" via git grep func (r Repo) Grep(search string) ([]GrepResult, error) { - if strings.HasPrefix(search, "=") { - search = regexp.QuoteMeta(strings.TrimPrefix(search, "=")) + if after, ok := strings.CutPrefix(search, "="); ok { + search = regexp.QuoteMeta(after) } re, err := regexp.Compile(search) if err != nil { diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go index a6dec7b..e094092 100644 --- a/internal/ssh/ssh.go +++ b/internal/ssh/ssh.go @@ -48,4 +48,4 @@ var ( type noopLogger struct{} -func (n noopLogger) Printf(format string, v ...interface{}) {} +func (n noopLogger) Printf(format string, v ...any) {} diff --git a/internal/ssh/wish.go b/internal/ssh/wish.go index bdf504b..6bdb167 100644 --- a/internal/ssh/wish.go +++ b/internal/ssh/wish.go @@ -168,7 +168,7 @@ func gitPack(s Session, gitCmd string, repoDir string, repoName string) error { } // Fatal prints to the session's STDOUT as a git response and exit 1. -func Fatal(s ssh.Session, v ...interface{}) { +func Fatal(s ssh.Session, v ...any) { msg := fmt.Sprint(v...) // hex length includes 4 byte length prefix and ending newline pktLine := fmt.Sprintf("%04x%s\n", len(msg)+5, msg)