Copy hooks and config files on fork

This commit is contained in:
Thomas Miceli 2023-03-19 00:49:06 +01:00
parent 8998e46fea
commit 5bfd40f9fd
No known key found for this signature in database
GPG key ID: D86C6F6390AF050F
2 changed files with 33 additions and 24 deletions

View file

@ -33,32 +33,12 @@ func InitRepository(user string, gist string) error {
repositoryPath, repositoryPath,
) )
_, err := cmd.Output() err := cmd.Run()
if err != nil { if err != nil {
return err return err
} }
f1, err := os.OpenFile(filepath.Join(repositoryPath, "git-daemon-export-ok"), os.O_RDONLY|os.O_CREATE, 0644) return copyFiles(repositoryPath)
defer f1.Close()
preReceiveDst, err := os.OpenFile(filepath.Join(repositoryPath, "hooks", "pre-receive"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0744)
if err != nil {
return err
}
preReceiveSrc, err := os.OpenFile(filepath.Join("internal", "resources", "pre-receive"), os.O_RDONLY, os.ModeAppend)
if err != nil {
return err
}
_, err = io.Copy(preReceiveDst, preReceiveSrc)
if err != nil {
return err
}
defer preReceiveDst.Close()
defer preReceiveSrc.Close()
return err
} }
func GetNumberOfCommitsOfRepository(user string, gist string) (string, error) { func GetNumberOfCommitsOfRepository(user string, gist string) (string, error) {
@ -189,7 +169,12 @@ func ForkClone(userSrc string, gistSrc string, userDst string, gistDst string) e
cmd = exec.Command("git", "config", "user.name", userDst) cmd = exec.Command("git", "config", "user.name", userDst)
cmd.Dir = repositoryPathDst cmd.Dir = repositoryPathDst
return cmd.Run() err := cmd.Run()
if err != nil {
return err
}
return copyFiles(repositoryPathDst)
} }
func SetFileContent(gistTmpId string, filename string, content string) error { func SetFileContent(gistTmpId string, filename string, content string) error {
@ -274,3 +259,27 @@ func GetGitVersion() (string, error) {
return versionFields[2], nil return versionFields[2], nil
} }
func copyFiles(repositoryPath string) error {
f1, err := os.OpenFile(filepath.Join(repositoryPath, "git-daemon-export-ok"), os.O_RDONLY|os.O_CREATE, 0644)
defer f1.Close()
preReceiveDst, err := os.OpenFile(filepath.Join(repositoryPath, "hooks", "pre-receive"), os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0744)
if err != nil {
return err
}
preReceiveSrc, err := os.OpenFile(filepath.Join("internal", "resources", "pre-receive"), os.O_RDONLY, os.ModeAppend)
if err != nil {
return err
}
_, err = io.Copy(preReceiveDst, preReceiveSrc)
if err != nil {
return err
}
defer preReceiveDst.Close()
defer preReceiveSrc.Close()
return nil
}

View file

@ -51,7 +51,7 @@ func Start() {
return nil return nil
}, },
})) }))
//e.Use(middleware.Recover()) e.Use(middleware.Recover())
e.Use(middleware.Secure()) e.Use(middleware.Secure())
e.Renderer = &Template{ e.Renderer = &Template{