Skip to content

Commit

Permalink
added force push (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperspencer authored Sep 29, 2023
1 parent 77024fb commit 082821b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions conf.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down

0 comments on commit 082821b

Please sign in to comment.