Adapt find command for Windows users (#89)

This commit is contained in:
Thomas Miceli 2023-09-17 03:03:54 +02:00 committed by GitHub
parent 3943b53163
commit 6085471b81
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -199,9 +199,7 @@ func CloneTmp(user string, gist string, gistTmpId string, email string) error {
} }
// remove every file (and not the .git directory!) // remove every file (and not the .git directory!)
cmd = exec.Command("find", ".", "-maxdepth", "1", "-type", "f", "-delete") if err = removeFilesExceptGit(tmpRepositoryPath); err != nil {
cmd.Dir = tmpRepositoryPath
if err = cmd.Run(); err != nil {
return err return err
} }
@ -407,6 +405,21 @@ func createDotGitHookFile(repositoryPath string, hook string, content string) er
return nil 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 const preReceive = `#!/bin/sh
disallowed_files="" disallowed_files=""