cooperspencer / gickup

https://cooperspencer.github.io/gickup-documentation/
Apache License 2.0
955 stars 33 forks source link

Force push mirroring to GitHub #171

Closed iay closed 11 months ago

iay commented 11 months ago

My current use case involves mirroring existing development repositories to private repositories in a GitHub organization: we're considering moving to GitHub at some point, and we'd want to overlap for a while.

I had already done some mirroring manually a couple of years back, and in most case Gickup has been able to update the previously created repositories on GitHub. One exception is a repository in which a development topic branch has since been rebased; this results in a ERR non-fast-forward update failure in Gickup.

I know you've had discussions about forced pull (https://github.com/cooperspencer/gickup/discussions/144) but the way Gickup handles the GitHub destination in particular means this is an independent issue. Because Gickup always creates a new temporary local repository in this case, there's never a question of force-fetching, only force-pushing.

As an experiment, I added Force: true to the two calls to git.PushOptions in lines 497 and 501 of local.go:

    pushoptions := git.PushOptions{Force: true, Auth: auth, ...

    ...

        pushoptions = git.PushOptions{Force: true, Auth: auth, ...

This seems to make the error message go away. I phrase it like that because this is literally the first time I've changed a line of Go code (thanks for the way I can just docker build to do this, by the way) and I have less than no idea what I'm doing. Seems plausible, though?

cooperspencer commented 11 months ago

You are welcome :smile: I would make this configurable so that you can enable the force push if needed.

iay commented 11 months ago

It would be fine (for me) if this was a configuration option, and probably safer (for you) if that code is used by something other than the GitHub destination.

cooperspencer commented 11 months ago

I added the option to force push in force_push Can you test it? There's just a new parameter called force for the GitHub destination.

iay commented 11 months ago

I should be able to test in an hour or so; I need to generate a failure first, of course, as my previous case is fixed :)

iay commented 11 months ago

I can confirm that setting destination.github.force to true in a version built from that branch does what I want: rebasing or commit --amending a development branch doesn't prevent pushes to GitHub; mirroring includes the manipulated branch and everything appears to be mirrored across correctly.

cooperspencer commented 11 months ago

thanks a lot. I'll merge it then and create a new release.

cooperspencer commented 11 months ago

just released v0.10.20 with this feature

iay commented 11 months ago

Confirming the image of 0.10.20 works for me. Thanks again.