简体   繁体   中英

How can I exclude pull requests from git mirror clone

I want to mirror clone a Bitbucket Repository to another Bitbucket Repository. I manage this with a shell script, which does the following:

git clone --mirror <sourceUrl>
git remote set-url --push origin <targetUrl>
git push --mirror

Now I'm getting the following error when pushing because Bitbucket does not allow to push pull requests (which are created on the Source Bitbucket):

remote: You are attempting to update refs that are reserved for Bitbucket's pull
remote: request functionality. Bitbucket manages these refs automatically, and they may
remote: not be updated by users.
remote:
remote: Rejected refs:
remote:         refs/pull-requests/21/from
remote:         refs/pull-requests/23/from
remote:         refs/pull-requests/23/merge
remote:         refs/pull-requests/24/from
remote:         refs/pull-requests/24/merge
To ...
 ! [remote rejected] refs/pull-requests/21/from -> refs/pull-requests/21/from (pre-receive hook declined)
 ! [remote rejected] refs/pull-requests/23/from -> refs/pull-requests/23/from (pre-receive hook declined)
 ! [remote rejected] refs/pull-requests/23/merge -> refs/pull-requests/23/merge (pre-receive hook declined)
 ! [remote rejected] refs/pull-requests/24/from -> refs/pull-requests/24/from (pre-receive hook declined)
 ! [remote rejected] refs/pull-requests/24/merge -> refs/pull-requests/24/merge (pre-receive hook declined)
error: failed to push some refs to '...'

I solved the Problem with a Hint from http://christoph.ruegg.name/blog/git-howto-mirror-a-github-repository-without-pull-refs.html by adapting the fetch refs with the following workaround.

I created a new bare Repository and adapted the config the following way:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = true
[remote "origin"]
    fetch = +refs/heads/*:refs/heads/*
    fetch = +refs/tags/*:refs/tags/*
    url = <sourceUrl>
    mirror = true
    pushurl = <targetUrl>

Then I perform a Git Pull and Git Push and everything is fine.

Nevertheless the Workaround is not a beautiful solution because creating an empty bare repository and then overwriting it is weird so I want an alternative.

Questions:

  • I can add the needed fetch Configuration with "git clone --config" (before git clone performs it's initial fetch) but can I remove the original fetch = +refs/*:refs/* Configuration also with the "git clone" Command? This would solve the problem, that the Pull Requests are pulled initially
  • Is it possible to remove the pull requests from the bare repository after the pull?
  • Is it possible to exclude the pull requests from the push?

Thanks to Ivan.

His command solved my Problem. I only had to add the "-r" parameter to xargs to react on empty greps:

git show-ref | cut -d' ' -f2 | grep 'pull-request' | xargs -r -L1 git update-ref -d

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM