Showing posts with label svn. Show all posts
Showing posts with label svn. Show all posts

05 April 2012

Poll svn server for changes with git clone


Just for convenience, paste this in a git bash window:


while true; do date; echo "Polling svn server..."; git svn fetch;
echo "Sleeping."; sleep 300; done


Then just refresh your favourite git log viewer.

Get the gist: poll-svn.sh gist

That's all folks!

04 February 2010

openlayers svn into git

Initial clone:
git svn clone -T trunk/openlayers/ -t tags/openlayers/ -b branches/openlayers/ http://svn.openlayers.org/ openlayers.git

"http://svn.openlayers.org/tags/openlayers/docs-2.8/" is in the wrong place and gets pulled in by the git clone.

I should have used --no-follow-parent to avoid the docs-2.8 tag pulling in docs history but not going to re-clone now. If you are repeating this, try this instead:
git svn clone --no-follow-parent -T trunk/openlayers/ -t tags/openlayers/ -b branches/openlayers/ http://svn.openlayers.org/ openlayers.git

Find the errant docs branches & eliminate:
cd openlayers.git
for x in `git for-each-ref --format="%(refname)" 'refs/remotes/tags/docs*'`; do git update-ref -d $x; done

# http://dound.com/2009/04/git-forever-remove-files-or-folders-from-history/
# expunge old objects (I think this works)
git reflog expire --all
git gc --aggressive --prune

Then run: http://www.shatow.net/fix-svn-refs.sh to create real git tags.

If you just want the result you can download a copy complete with svn metadata from http://www.timwise.co.uk/openlayers-dev/openlayers.git.tgz

You will then be able to run
git svn fetch

to get updates from the openlayers svn server.

There is a published copy at http://github.com/timabell/openlayers, though it doesn't have the svn metadata.



I also tackled the docs folder:

The docs directory has no matching branch or tag directories, so the following is sufficient:
git svn clone -T trunk/doc http://svn.openlayers.org/ openlayers-doc.git
git gc --aggressive --prune

You can download this from http://www.timwise.co.uk/openlayers-dev/openlayers-doc.git.tgz



Anything else I come up with will end up at http://www.timwise.co.uk/openlayers-dev/

10 September 2008

error "Not a valid object name" filtering an ex-svn git repo with renames

Under git version 1.5.4.3, which as of writing is the current in ubuntu 8.04 hardy heron, trying to split out a folder from a git repo where the repo was an import from subversion (svn), and the folder was renamed in the past causes a failure as show below:

#!/bin/bash -v
rm -rf test-case
mkdir test-case
cd test-case/
svnadmin create svnrepo
export repo="`pwd`/svnrepo"
mkdir -p import/a
echo '1' >> import/a/file.txt
svn import -m 'initial import' import file://$repo/trunk/
svn co file://$repo/trunk/ checkout
echo '2' >> checkout/a/file.txt
svn ci -m "file modified" checkout
svn mv -m "moving file" file://$repo/trunk/a file://$repo/trunk/b
svn up checkout
echo '3' >> checkout/b/file.txt
svn ci -m "modified again" checkout
svn log -v checkout
mkdir -p gitcopy/a
git svn clone file://$repo/trunk/ gitcopy/a
cd gitcopy/a
git filter-branch --subdirectory-filter a #fails [1]
cd ../../
mkdir gitcopy/b
git svn clone file://$repo/trunk/ gitcopy/b
cd gitcopy/b
git filter-branch --subdirectory-filter b


The marked line above fails with the following error:
[1] Rewrite bcfe73ef303832b6112a2419dc1da5f782672c14 (3/3)fatal: Not a valid object name bcfe73ef303832b6112a2419dc1da5f782672c14:a

This has been fixed in the latest build of git: version 1.6.0.1.294.gda06a and no longer fails.

The "fatal: Not a git repository" error message that filter branch produces doesn't seem to matter.

29 May 2008

sharing work between computers with a usb flash drive and git


I couldn't find anything exactly matching this on the net when I was figuring it out, so here's what I did.

This is working against a remote svn (subversion) server, but applies even without one.

On the first computer, grab your git working copy from svn with git-svn clone (or clone a git repo, or just start a new one).

mkdir ~/project.git
cd ~/project.git
git-svn clone svn://project-server/trunk
git repack #for good measure


Plugin your usb flash drive/stick/external harddrive, I'll presume it's a vfat/fat32/fat16 formated device mounted at /media/flash.
Create an empty repository on the drive, I'll use a bare one as there's no need to keep the working copy as well.

mkdir /media/flash/project.git
git --bare init /media/flash/project.git


Then add the flash drive git repo as a remote source in your local git repo. "flash" is the name I've given to the remote branch reference, you can call it whatever you like.

git remote add flash /media/flash/project.git

If you push immediately it will fail (as I discovered) because fat doesn't support the execute flag on files, so all the hooks are automatically active. I deleted all the hooks as I wasn't planning on using them, this may be wrong so no promises, but it seems ok so far for me. So remove the hooks with:

rm /media/flash/project.git/hooks/*

Then push your current local copy to the flash drive with:

git push flash

This will copy all your committed work onto the flash drive, even if you haven't pushed it upstream to the svn server with "git-svn dcommit" yet. Bonus! It won't copy any of your branches across though, so you if you want them you can add those independently with:

git push flash mybranch

Now move over to the second computer and plug the flash drive in. I'm making the same assumptions on paths and devices. Do another completely independent svn checkout as above:

mkdir ~/project.git
cd ~/project.git
git-svn clone svn://project-server/trunk
git repack #for good measure


Then add the flash drive's repo to the git repo on the second pc and pull all changes from the flash drive, optionally including any branches:

git remote add flash /media/flash/project.git
git pull flash master
git pull flash mybranch #if you like


When you've committed changes to git or pulled the latest changes from svn on either pc, you can then update the flash drive with the simple command:

git push flash

Which pushes all your changes on your master branch on to the flash drive. You are now ready to run the pull command on the other computer to get back in sync:

git pull flash master

If you don't push changes to the flash drive before committing to svn then things will be very simple. If you push changes to the flash drive, and then commit them to the svn server you will need to do a little more work. This is because when you run "git svn dcommit" it pushes your latest git commits to the svn server, deletes your locally committed changes, and then fetches them back from the svn server. This means that git won't recognise your local changes as being the same as the ones on the flash drive because they have different commit message and SHA1 hash. Attempting to push to the flash drive fails with the message "! [rejected] master -> master (non-fast forward)" as the old copy of the commits are still there.

To resolve this you need to throw away the matching set of changes on the flash drive. To do this you can use git reset as follows, where HEAD~1 should be the number of commits you need to throw away (eg HEAD~3 to throw away the last 3 commits that were pushed to the flash drive):

cd /media/flash/project.git
git --bare log #to see how many changes don't have svn information
git --bare reset HEAD~1


You can then push your changes as above.

cd ~/project.git
git push flash


I've glossed over subtleties with fetch vs pull, but hopefully you will find this useful.

This howto makes use of git's ability to pull from multiple sources, and I've found that git quite happily copes with changes that were checked in to svn coming via the flash drive, even when later running "git-svn rebase".

Please do comment or contact me with any problems, errors, extra info and feedback, and let me know if it was useful.