Skip to content

Commit

Permalink
feat: ready to merge to main
Browse files Browse the repository at this point in the history
  • Loading branch information
telemachus committed Oct 18, 2024
1 parent bcd90da commit bb57eb9
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 30 deletions.
5 changes: 3 additions & 2 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,21 +101,22 @@ func (app *App) Mirror(repos []Repo) {
})
ch := make(chan Publisher)
for _, repo := range repos {
go mirror(repo, ch)
go app.mirror(repo, ch)
}
for range repos {
result := <-ch
result.Publish(app.QuietWanted)
}
}

func mirror(repo Repo, ch chan<- Publisher) {
func (app *App) mirror(repo Repo, ch chan<- Publisher) {
args := []string{"push", "--mirror", repo.Remote}
cmd := exec.Command("git", args...)
cmd.Dir = repo.Dir
cmdString := fmt.Sprintf("`git %s` (in %s)", strings.Join(args, " "), cmd.Dir)
err := cmd.Run()
if err != nil {
app.ExitValue = exitFailure
ch <- Failure{msg: fmt.Sprintf("%s: %s: %s", appName, cmdString, err)}
}
ch <- Success{msg: fmt.Sprintf("%s: %s", appName, cmdString)}
Expand Down
8 changes: 4 additions & 4 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ package cli

const (
appName = "gitmirror"
appVersion = "v0.0.3"
appVersion = "v0.1.0"
appUsage = `usage: gitmirror [-config FILENAME]
options:
-config FILENAME Specify a configuration file (default = ~/.gitmirror.toml)
-config FILENAME Specify a configuration file (default = ~/.gitmirror.json)
-quiet/-q Suppress output unless an error occurs
-help Show this message
-version Show version`
Expand All @@ -20,7 +20,7 @@ options:
func Run(args []string) int {
app := &App{ExitValue: exitSuccess}
configFile, isDefault := app.ParseFlags(args)
wanted := app.Unmarshal(configFile, isDefault)
app.Mirror(wanted)
repos := app.Unmarshal(configFile, isDefault)
app.Mirror(repos)
return app.ExitValue
}
26 changes: 26 additions & 0 deletions cli/testdata/backups.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"remote": "backup",
"dir": "/home/username/foo"
},

{
"remote": "backblaze",
"dir": "/Users/foo/bar"
},

{
"remote": "backup",
"dir": "/home/username/bar"
},

{
"remote": "rsync",
"dir": "foo/bar"
},

{
"remote": "backup",
"dir": "foo/bar/buzz"
}
]
19 changes: 0 additions & 19 deletions cli/testdata/backups.toml

This file was deleted.

10 changes: 5 additions & 5 deletions cli/unmarshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const (
exitSuccess = 0
)

func makeRepos() []*cli.Repo {
return []*cli.Repo{
func makeRepos() []cli.Repo {
return []cli.Repo{
{Remote: "backup", Dir: "/home/username/foo"},
{Remote: "backblaze", Dir: "/Users/foo/bar"},
{Remote: "backup", Dir: "/home/username/bar"},
Expand All @@ -35,7 +35,7 @@ func TestUnmarshalSuccess(t *testing.T) {
t.Parallel()
expected := makeRepos()
app := &cli.App{}
actual := app.Unmarshal("testdata/backups.toml", false)
actual := app.Unmarshal("testdata/backups.json", false)
if app.ExitValue != exitSuccess {
t.Fatal("app.ExitValue != exitSuccess")
}
Expand All @@ -47,7 +47,7 @@ func TestUnmarshalSuccess(t *testing.T) {
func TestUnmarshalFailure(t *testing.T) {
t.Parallel()
app := &cli.App{}
app.Unmarshal("testdata/nope.toml", false)
app.Unmarshal("testdata/nope.json", false)
if app.ExitValue != exitFailure {
t.Errorf("expected exit status: %d; actual exit status: %d", exitFailure, app.ExitValue)
}
Expand All @@ -57,7 +57,7 @@ func TestUnmarshalReplace(t *testing.T) {
t.Parallel()
expected := makeRepos()
app := &cli.App{}
actual := app.Unmarshal("testdata/backups.toml", false)
actual := app.Unmarshal("testdata/backups.json", false)
if app.ExitValue != exitSuccess {
t.Fatal("app.ExitValue != exitSuccess")
}
Expand Down

0 comments on commit bb57eb9

Please sign in to comment.