Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Best way to solve mirroring a remote in Stash?

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

We recently completed a migration from an old gitosis/gitweb/git daemon server to Stash; a handful of repositories had been "fiddled with" on the server, it turns out. The .git/config file was modified and some remotes were added - say, a remote called "upstream" with the url to an open source project out on the interwebs. Then a cron job had been installed to go into the folder on the git server and do a git fetch & prune. The end result is the hosted repos magically stayed up to date on specific "branches" with the open source community. I didn't know about this until the final few days of the move from gitosis to Stash. So not addressing the pro's and con's of whether or not this is wise - that's a seperate question - what's the best way to solve this in Stash?

I would rather not dig into the Stash data folder and manually edit the .git/config file in the handful of repos and run a cron job to do a behind the scenes fetch, mostly because I'm not confident it would work, and I'm also worried about messing around where I shouldn't - Stash's documentation clearly states to not manually modify anything in your data folder. I would like to keep upgrading Stash without a problem, so I don't want to cause a headache for myself down the road. I've checked out the marketplace as well - the two mirroring plugins that are up to date mirror the wrong direction - they allow you to mirror your Stash repo to somewhere else - either another instance of Stash, or another git server completely (bitbucket, github, et al). There's one plugin that looks like it might have worked but it quit being updated after Stash 2.2 and doesn't look viable any longer.

One idea I have is to use Bamboo for this, instead of cron. Make a sh script task to clone the open source repo and push it to our Stash repo. Like this - here’s the old .git config:

[remote "upstream"]

url = git://git.yoctoproject.org/yocto-autobuilder.git

fetch = +refs/heads/*:refs/heads/upstream/*

Here’s my solution:

git clone git://git.yoctoproject.org/yocto-autobuilder.git

cd yocto-autobuilder

git push --prune ssh://git@our-stash.server.com:7999/test/yocto-autobuilder.git +refs/remotes/origin/*:refs/heads/upstream/* +refs/tags/*:refs/tags/*

This seems to work, but I'm not sure if this will work day after day. I'm obviously not a git guru either, so I'm not even sure if this is canon or correct. What do you all think? How would you solve this (in the technical sense - again, please don't address how "smart" this is).
-Kelly Schoenhofen

1 answer

1 accepted

0 votes
Answer accepted
Roger Barnes
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2013

Hi Kelly,

You're right to avoid digging into Stash's data folder for this. The general solution would be to externally poll and push via git, so your approach of using a bamboo task to push updates to Stash is a good one. I'm not sure of the exact syntax for the push command to use, there might be something simpler or more reliable.

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2013

Thanks. I also hit the Expert Bar at Summit13 and they said essentially the same thing. They hemmed and hawwed ;) a little on whether or not to stay out of the data fold; they said in this instance it wouldn't be the end of the world, but they generally agreed to stay out of it, unless the alternative is worst than going into data.

They liked the bamboo git clone & git push method best, with modifying the .git configs in the data folder & a cron job a distant second. I'll mark your response as the answer, thanks!

-Kelly

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events