From 6085471b81d8527558a73eb20d3f4d978bddf5a1 Mon Sep 17 00:00:00 2001 From: Thomas Miceli <27960254+thomiceli@users.noreply.github.com> Date: Sun, 17 Sep 2023 03:03:54 +0200 Subject: [PATCH] Adapt find command for Windows users (#89) --- internal/git/commands.go | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/internal/git/commands.go b/internal/git/commands.go index 29206f4..502c0dc 100644 --- a/internal/git/commands.go +++ b/internal/git/commands.go @@ -199,9 +199,7 @@ func CloneTmp(user string, gist string, gistTmpId string, email string) error { } // remove every file (and not the .git directory!) - cmd = exec.Command("find", ".", "-maxdepth", "1", "-type", "f", "-delete") - cmd.Dir = tmpRepositoryPath - if err = cmd.Run(); err != nil { + if err = removeFilesExceptGit(tmpRepositoryPath); err != nil { return err } @@ -407,6 +405,21 @@ func createDotGitHookFile(repositoryPath string, hook string, content string) er return nil } +func removeFilesExceptGit(dir string) error { + return filepath.WalkDir(dir, func(path string, d os.DirEntry, err error) error { + if err != nil { + return err + } + if d.IsDir() && filepath.Base(path) == ".git" { + return filepath.SkipDir + } + if !d.IsDir() { + return os.Remove(path) + } + return nil + }) +} + const preReceive = `#!/bin/sh disallowed_files=""