Skip to content

Commit 8a86545

Browse files
committed
update-all: create update-all subcommand
The 'update-all' subcommand runs the 'update' subcommand on all registered routes.
1 parent 1f32d18 commit 8a86545

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

cmd/git-bundle-server/subcommand.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ func all() []Subcommand {
99
return []Subcommand{
1010
Init{},
1111
Update{},
12+
UpdateAll{},
1213
}
1314
}

cmd/git-bundle-server/update-all.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"git-bundle-server/internal/core"
6+
"os"
7+
"os/exec"
8+
)
9+
10+
type UpdateAll struct{}
11+
12+
func (UpdateAll) subcommand() string {
13+
return "update-all"
14+
}
15+
16+
func (UpdateAll) run(args []string) error {
17+
exe, err := os.Executable()
18+
if err != nil {
19+
return fmt.Errorf("failed to get path to execuable: %w", err)
20+
}
21+
22+
repos, err := core.GetRepositories()
23+
if err != nil {
24+
return err
25+
}
26+
27+
for route := range repos {
28+
cmd := exec.Command(exe, "update", route)
29+
cmd.Stderr = os.Stderr
30+
cmd.Stdout = os.Stdout
31+
32+
err := cmd.Start()
33+
if err != nil {
34+
return fmt.Errorf("git command failed to start: %w", err)
35+
}
36+
37+
err = cmd.Wait()
38+
if err != nil {
39+
return fmt.Errorf("git command returned a failure: %w", err)
40+
}
41+
}
42+
43+
return nil
44+
}

0 commit comments

Comments
 (0)