mirror of
https://github.com/thomiceli/opengist.git
synced 2025-07-09 01:18:04 +02:00
Run git gc for repositories (#90)
This commit is contained in:
@ -2,6 +2,7 @@ package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/thomiceli/opengist/internal/config"
|
||||
"os"
|
||||
"os/exec"
|
||||
@ -263,6 +264,47 @@ func RPC(user string, gist string, service string) ([]byte, error) {
|
||||
return stdout, err
|
||||
}
|
||||
|
||||
func GcRepos() error {
|
||||
subdirs, err := os.ReadDir(filepath.Join(config.GetHomeDir(), "repos"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, subdir := range subdirs {
|
||||
if !subdir.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
subRoot := filepath.Join(config.GetHomeDir(), "repos", subdir.Name())
|
||||
|
||||
gitRepos, err := os.ReadDir(subRoot)
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Cannot read directory")
|
||||
continue
|
||||
}
|
||||
|
||||
for _, repo := range gitRepos {
|
||||
if !repo.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
repoPath := filepath.Join(subRoot, repo.Name())
|
||||
|
||||
log.Info().Msg("Running git gc for repository " + repoPath)
|
||||
|
||||
cmd := exec.Command("git", "gc")
|
||||
cmd.Dir = repoPath
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
log.Warn().Err(err).Msg("Cannot run git gc for repository " + repoPath)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func GetGitVersion() (string, error) {
|
||||
cmd := exec.Command("git", "--version")
|
||||
stdout, err := cmd.Output()
|
||||
|
Reference in New Issue
Block a user