Skip to content

Instantly share code, notes, and snippets.

@mattn
Last active December 15, 2015 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mattn/158681fd382f787ab4a0 to your computer and use it in GitHub Desktop.
Save mattn/158681fd382f787ab4a0 to your computer and use it in GitHub Desktop.
GOPATH 内の git リポジトリで全部 git gc するやつ
package main
import (
"log"
"os"
"os/exec"
"path/filepath"
"strings"
)
func main() {
b, err := exec.Command("ghq", "list").CombinedOutput()
if err != nil {
log.Fatal(err)
}
for _, line := range strings.Split(string(b), "\n") {
for _, p := range filepath.SplitList(os.Getenv("GOPATH")) {
repo := filepath.FromSlash(filepath.Join(p, "src", line))
if _, err = os.Stat(filepath.Join(repo, ".git")); err != nil {
continue
}
log.Print(repo)
cmd := exec.Command("git", "gc")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Dir = repo
if err = cmd.Run(); err != nil {
log.Print(err)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment