Last active
December 17, 2015 23:54
-
-
Save matipan/ba8916b14d59a2f17542 to your computer and use it in GitHub Desktop.
Script that walks a certain directory tree and runs git status -sb on each git repository
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"os" | |
"os/exec" | |
"path/filepath" | |
) | |
type Repo struct { | |
Path string | |
Name string | |
Status []byte | |
} | |
func main() { | |
reposlice := make([]Repo, 0) | |
cmd := exec.Command("git", "status", "-sb") | |
filepath.Walk(filepath.Join(os.Getenv("HOME"), "Code"), func(path string, info os.FileInfo, err error) error { | |
if info.IsDir() { | |
if _, cerr := os.Stat(filepath.Join(path, ".git")); os.IsNotExist(cerr) { | |
return filepath.SkipDir | |
} | |
cmd.Dir = path | |
out, err := cmd.Output() | |
if err != nil { | |
return err | |
} | |
reposlice = append(reposlice, Repo{ | |
Path: path, | |
Name: filepath.Base(path), | |
Status: out, | |
}) | |
} | |
return nil | |
}) | |
for _, val := range reposlice { | |
fmt.Println(val) | |
} | |
} | |
func (r Repo) String() string { | |
return fmt.Sprintf("The repository %v in the path %v has the following status: %v", r.Name, r.Path, r.Status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment