From 2fe309663d362d1fdd3b1b27fb25f83a292f0967 Mon Sep 17 00:00:00 2001 From: Thomas Miceli Date: Mon, 10 Apr 2023 22:44:58 +0200 Subject: [PATCH] Remove pre-receive hook script file --- internal/git/commands.go | 37 +++++++++++++++++++++++++--------- internal/resources/pre-receive | 25 ----------------------- 2 files changed, 28 insertions(+), 34 deletions(-) delete mode 100644 internal/resources/pre-receive diff --git a/internal/git/commands.go b/internal/git/commands.go index 5dc6eed..d6e86fe 100644 --- a/internal/git/commands.go +++ b/internal/git/commands.go @@ -2,7 +2,6 @@ package git import ( "fmt" - "io" "opengist/internal/config" "os" "os/exec" @@ -276,17 +275,37 @@ func copyFiles(repositoryPath string) error { return err } - preReceiveSrc, err := os.OpenFile(filepath.Join("internal", "resources", "pre-receive"), os.O_RDONLY, os.ModeAppend) - if err != nil { + if _, err = preReceiveDst.WriteString(preReceive); err != nil { return err } - _, err = io.Copy(preReceiveDst, preReceiveSrc) - if err != nil { - return err - } - defer preReceiveDst.Close() - defer preReceiveSrc.Close() return nil } + +const preReceive = `#!/bin/sh + +disallowed_files="" + +while read -r old_rev new_rev ref +do + while IFS= read -r file + do + case $file in + */*) + disallowed_files="${disallowed_files}${file} " + ;; + esac + done <