From 082821bfb9fa3fbb57498f770ff32baa284fbf96 Mon Sep 17 00:00:00 2001 From: Andreas Wachter Date: Fri, 29 Sep 2023 17:10:06 +0200 Subject: [PATCH] added force push (#172) --- conf.example.yml | 3 +++ local/local.go | 4 ++-- types/types.go | 1 + 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/conf.example.yml b/conf.example.yml index 002ca13..7745d3d 100644 --- a/conf.example.yml +++ b/conf.example.yml @@ -220,11 +220,13 @@ destination: organization: whatever # name of the organization to want to backup to visibility: repositories: private # private, public, default: private + force: false # force push to destination onedev: - token: some-token # token_file: token.txt # alternatively, specify token in a file url: http(s)://url-to-onedev organization: whatever # name of the parent project you want to backup to + force: false # force push to destination sourcehut: - token: some-token # as of now only the legacy api works, use the legacy token # token_file: token.txt # alternatively, specify token in a file @@ -233,6 +235,7 @@ destination: url: http(s)://url-to-sourcehut # if empty, it uses https://git.sr.ht visibility: repositories: private # public, unlisted, private, default: public + force: false # force push to destination local: # Export this path from Docker with a volume to make it accessible and more permanent. - path: /some/path/gickup diff --git a/local/local.go b/local/local.go index b73f384..8d9bdd4 100644 --- a/local/local.go +++ b/local/local.go @@ -494,11 +494,11 @@ func CreateRemotePush(repo *git.Repository, destination types.GenRepo, url strin headref, _ := repo.Head() - pushoptions := git.PushOptions{Auth: auth, RemoteName: remote.Config().Name, RefSpecs: []config.RefSpec{config.RefSpec(fmt.Sprintf("%s:%s", headref.Name(), headref.Name()))}} + pushoptions := git.PushOptions{Force: destination.Force, Auth: auth, RemoteName: remote.Config().Name, RefSpecs: []config.RefSpec{config.RefSpec(fmt.Sprintf("%s:%s", headref.Name(), headref.Name()))}} err = repo.Push(&pushoptions) if err == nil || err == git.NoErrAlreadyUpToDate { - pushoptions = git.PushOptions{Auth: auth, RemoteName: remote.Config().Name, RefSpecs: []config.RefSpec{"refs/heads/*:refs/heads/*", "refs/tags/*:refs/tags/*"}} + pushoptions = git.PushOptions{Force: destination.Force, Auth: auth, RemoteName: remote.Config().Name, RefSpecs: []config.RefSpec{"refs/heads/*:refs/heads/*", "refs/tags/*:refs/tags/*"}} return repo.Push(&pushoptions) } diff --git a/types/types.go b/types/types.go index 90684bb..7ada8d1 100644 --- a/types/types.go +++ b/types/types.go @@ -246,6 +246,7 @@ type GenRepo struct { CreateOrg bool `yaml:"createorg"` Visibility Visibility `yaml:"visibility"` Filter Filter `yaml:"filter"` + Force bool `yaml:"force"` Contributed bool `yaml:"contributed"` }