forked from toolshed/abra
.gitea
cli
cmd
pkg
app
autocomplete
catalogue
client
config
container
context
dns
envfile
formatter
git
add.go
branch.go
clone.go
commit.go
common.go
diff.go
init.go
push.go
read.go
remote.go
integration
limit
lint
log
recipe
secret
server
service
ssh
test
upstream
web
scripts
tests
.dockerignore
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
AUTHORS.md
Dockerfile
LICENSE
Makefile
README.md
go.mod
go.sum
renovate.json
44 lines
831 B
Go
44 lines
831 B
Go
package git
|
|
|
|
import (
|
|
"coopcloud.tech/abra/pkg/log"
|
|
"github.com/go-git/go-git/v5"
|
|
"github.com/go-git/go-git/v5/config"
|
|
)
|
|
|
|
// Push pushes the latest changes & optionally tags to the default remote
|
|
func Push(repoDir string, remote string, tags bool, dryRun bool) error {
|
|
if dryRun {
|
|
log.Debugf("dry run: no git changes pushed in %s", repoDir)
|
|
return nil
|
|
}
|
|
|
|
commitRepo, err := git.PlainOpen(repoDir)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
opts := &git.PushOptions{}
|
|
if remote != "" {
|
|
opts.RemoteName = remote
|
|
}
|
|
|
|
if err := commitRepo.Push(opts); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf("git changes pushed")
|
|
|
|
if tags {
|
|
opts.RefSpecs = append(opts.RefSpecs, config.RefSpec("+refs/tags/*:refs/tags/*"))
|
|
|
|
if err := commitRepo.Push(opts); err != nil {
|
|
return err
|
|
}
|
|
|
|
log.Debugf("git tags pushed")
|
|
}
|
|
|
|
return nil
|
|
}
|