forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
client
compose
config
container
context
dns
formatter
git
branch.go
clone.go
commit.go
common.go
init.go
push.go
read.go
remote.go
integration
limit
lint
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
.drone.yml
.e2e.env.sample
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
29 lines
576 B
Go
29 lines
576 B
Go
package git
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/go-git/go-git/v5/config"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// CreateRemote creates a new git remote in a repository
|
|
func CreateRemote(repo *git.Repository, name, url string, dryRun bool) error {
|
|
if dryRun {
|
|
logrus.Debugf("dry run: remote %s (%s) not created", name, url)
|
|
return nil
|
|
}
|
|
|
|
if _, err := repo.CreateRemote(&config.RemoteConfig{
|
|
Name: name,
|
|
URLs: []string{url},
|
|
}); err != nil {
|
|
if !strings.Contains(err.Error(), "remote already exists") {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|