Untangle the spaghetti. Slightly.
This commit is contained in:
parent
7e6ee5d65e
commit
2ac05f29d1
2 changed files with 49 additions and 39 deletions
40
gerritcp.go
40
gerritcp.go
|
@ -5,8 +5,6 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
|
@ -29,43 +27,7 @@ func main() {
|
|||
panic(fmt.Sprintf("Failed parsing '%s': %s", *configFile, err))
|
||||
}
|
||||
|
||||
_, err = git.PlainClone(*dir, true, &git.CloneOptions{
|
||||
URL: cfg.Sites.Upstream.FullURL(),
|
||||
Auth: nil,
|
||||
RemoteName: "upstream",
|
||||
SingleBranch: false,
|
||||
NoCheckout: true,
|
||||
})
|
||||
if err != nil && err != git.ErrRepositoryAlreadyExists {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(*dir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = repo.CreateRemote(&config.RemoteConfig{
|
||||
Name: "downstream",
|
||||
URLs: []string{cfg.Sites.Downstream.FullURL()},
|
||||
})
|
||||
if err != nil && err != git.ErrRemoteExists {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(&git.FetchOptions{
|
||||
RemoteName: "upstream",
|
||||
})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(&git.FetchOptions{
|
||||
RemoteName: "downstream",
|
||||
})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
panic(err)
|
||||
}
|
||||
repo := openRepo(dir, cfg)
|
||||
|
||||
fmt.Println(repo)
|
||||
}
|
||||
|
|
48
repo.go
Normal file
48
repo.go
Normal file
|
@ -0,0 +1,48 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-git/v5"
|
||||
"github.com/go-git/go-git/v5/config"
|
||||
)
|
||||
|
||||
func openRepo(dir *string, cfg *configFormat) *git.Repository {
|
||||
_, err := git.PlainClone(*dir, true, &git.CloneOptions{
|
||||
URL: cfg.Sites.Upstream.FullURL(),
|
||||
Auth: nil,
|
||||
RemoteName: "upstream",
|
||||
SingleBranch: false,
|
||||
NoCheckout: true,
|
||||
})
|
||||
if err != nil && err != git.ErrRepositoryAlreadyExists {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
repo, err := git.PlainOpen(*dir)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
_, err = repo.CreateRemote(&config.RemoteConfig{
|
||||
Name: "downstream",
|
||||
URLs: []string{cfg.Sites.Downstream.FullURL()},
|
||||
})
|
||||
if err != nil && err != git.ErrRemoteExists {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(&git.FetchOptions{
|
||||
RemoteName: "upstream",
|
||||
})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = repo.Fetch(&git.FetchOptions{
|
||||
RemoteName: "downstream",
|
||||
})
|
||||
if err != nil && err != git.NoErrAlreadyUpToDate {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return repo
|
||||
}
|
Loading…
Reference in a new issue