Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to automatically push to remote mirror repository #3480

Open
bzeme opened this issue Feb 9, 2018 · 14 comments

Comments

@bzeme
Copy link

commented Feb 9, 2018

I like the feature of mirroring the repositories by pulling the remote repositories.

Is it possible to make gitea to push local repositories to remote mirror repositories?

It's nice if gitea is able to automatically push local repositories to remote mirror repositories such as github, gitlab or other git services.

@lunny lunny added the kind/proposal label Feb 9, 2018
@mxmehl

This comment has been minimized.

Copy link

commented Feb 12, 2018

Good idea, I have been looking for such a option already.

IMHO this would increase adoption of Gitea. People would be more inclined to using Gitea if they knew that they could easily mirror stuff to GitLab/Github without having to fiddle with hooks.

@wjh

This comment has been minimized.

Copy link

commented Feb 22, 2018

I'm also pretty interested in this, and wouldn't mind having a go at implementing it if someone could point me in the right direction!

@thehowl

This comment has been minimized.

Copy link
Contributor

commented Mar 3, 2018

Right now I am doing this on a project of mine. Since I am the admin of the instance, I have access to the git hooks of the repos, and I can add this as the post-receive hook:

#!/bin/bash
git push --mirror --quiet https://user:token@github.com/osuripple/hanayo.git &> /dev/null
echo 'osuripple/hanayo updated'

Of course, this is just a hack, and a proper mechanism would be gladly appreciated.

@ulm0

This comment has been minimized.

Copy link

commented Aug 6, 2018

this would be a really nice feature to have in Gitea, please!

@sci4me

This comment has been minimized.

Copy link

commented Aug 12, 2018

Yeah this would be an amazingly useful feature!

@ghost

This comment has been minimized.

Copy link

commented Aug 13, 2018

Is this really just a limitation of other systems disguised to look like a feature in Gitea? If Webhooks can do it why run the risk and adding complexity trying to make Gitea manage features absent from other products?

Now, if we could have an SVN push mirror that would be extremely useful use case for the ad hoc nature of the umptysquillion poorly managed WordPress SVN repos in existence today who would gladly being porting over go Gitea to simplify their workflow and reduce premature aging.

@snth

This comment has been minimized.

Copy link

commented Nov 9, 2018

@thehowl Thanks. I made a slight modification so I don't have to wait for the push to the mirror to complete (which can be slow).

#!/bin/bash
git push --mirror --quiet https://user:token@github.com/osuripple/hanayo.git &> /dev/null &
echo 'osuripple/hanayo update initiated.'

Of course now you no longer have a confirmation that the push succeeded but a main motivation for my use case of gitea was to avoid the long lags of updates to slow remote hosts.

@pklapperich

This comment has been minimized.

Copy link

commented Mar 15, 2019

The git hook trick won't work for mirror repos. And a lot of services don't respond to inbound webhooks, for example gitea itself doesn't, a simple ssh server acting as a git remote, etc. Having this built in would be useful.

@lunny

This comment has been minimized.

Copy link
Member

commented Mar 16, 2019

You have to store the token or private key on gitea if we implement that.

@chotaire

This comment has been minimized.

Copy link

commented Apr 7, 2019

This is a very interesting feature!

@belliash

This comment has been minimized.

Copy link

commented May 3, 2019

+1

@HarvsG

This comment has been minimized.

Copy link

commented Jul 18, 2019

This would be a very useful feature. It would be great to have a system where users could develop a project on our hosted Gitea instance and then 'publish' it to a public git service by setting it up as a mirrored repo.

@millergarym

This comment has been minimized.

Copy link

commented Sep 22, 2019

You have to store the token or private key on gitea if we implement that.

No, ssh auth forwarding could be used.

@petrac-daniel

This comment has been minimized.

Copy link

commented Oct 1, 2019

After I used the hack from above, I've written an post receive script to update the remote repo with all changes from gitea. All changes made in gitea will be automatically pushed to the "mirror repo" but not the other way around. Updating the gitea repo is still manually.

It is unfortunately still necessary to update the config file of the repo and the git authentication on the maschine running gitea:

[remote "origin"]
	url = <remote_url_here>
	fetch = +refs/heads/*:refs/remotes/origin/*

#!/usr/bin/env bash

z40=0000000000000000000000000000000000000000

while read local_ref local_sha remote_ref remote_sha
do
    if [[ $remote_ref =~ refs\/heads\/(.+) ]]; then
        branch_name=${BASH_REMATCH[1]}
        
        if [ "$local_sha" = $z40 ]
        then
            # Handle delete
            echo HANDLE DELETE BRANCH ON <remote_url_here>
            echo ----------
            git push --delete origin $branch_name
            echo ----------
        else
            echo HANDLE PUSH BRANCH ON ON <remote_url_here>
            echo ----------
            git push --set-upstream origin $branch_name
            echo ----------
        fi
    else
        echo "unable to parse remote branch $branch_name"
    fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.