Pull the latest changes for each repository
This commit is contained in:
parent
7020a76013
commit
f91b6e4cbd
3 changed files with 41 additions and 5 deletions
37
internal/repositories/update.go
Normal file
37
internal/repositories/update.go
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
package repositories
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Update(repositoryPath string) error {
|
||||||
|
repositoryPath = strings.TrimSuffix(repositoryPath, "/.git")
|
||||||
|
|
||||||
|
err := os.Chdir(repositoryPath)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to change directory to %s: %w", repositoryPath, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Updating %s\n", repositoryPath)
|
||||||
|
|
||||||
|
commands := [][]string{
|
||||||
|
{"git", "fetch", "--all", "--jobs=4", "--progress", "--prune"},
|
||||||
|
{"git", "pull", "--rebase"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, args := range commands {
|
||||||
|
cmd := exec.Command(args[0], args[1:]...)
|
||||||
|
cmd.Stdout = os.Stdout
|
||||||
|
cmd.Stderr = os.Stderr
|
||||||
|
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
return fmt.Errorf("%s failed: %w", strings.Join(args, " "), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
7
main.go
7
main.go
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
|
@ -19,20 +18,20 @@ func main() {
|
||||||
dirs := cfg.Directories
|
dirs := cfg.Directories
|
||||||
|
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
repositories, err := repositories.FindInDirectory(dir)
|
repositoryPaths, err := repositories.FindInDirectory(dir)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.SplitSeq(repositories, "\n")
|
lines := strings.SplitSeq(repositoryPaths, "\n")
|
||||||
|
|
||||||
for repositoryPath := range lines {
|
for repositoryPath := range lines {
|
||||||
if repositoryPath == "" {
|
if repositoryPath == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println(repositoryPath)
|
repositories.Update(repositoryPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
todo.txt
2
todo.txt
|
|
@ -1,4 +1,4 @@
|
||||||
* Load directories from a configuration file
|
* Load directories from a configuration file
|
||||||
|
* Update the repositories within each directory.
|
||||||
|
|
||||||
Update the repositories within each directory.
|
|
||||||
Make depth configurable per directory.
|
Make depth configurable per directory.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue