DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Nic has posted 15 posts at DZone. View Full User Profile

Checkout A Git Clone Of An SVN Repository In Parent Folder

11.22.2007
| 9109 views |
  • submit to reddit
        Here is a quick executable cmd that you run inside a folder checked out with Subversion. It will clone the repository using Git into the parent folder as <projname>.git

Stick this code into ~/bin/gitify and add ~/bin to your path:

#!/usr/bin/env ruby -wKU

# get svn info location
svnurl = `svn info | grep "^URL:"`.gsub('URL: ','').chomp

# project = basename
project = File.basename(Dir.pwd)

puts cmd = "git-svn clone #{svnurl} ../#{project}.git"

`#{cmd}`
    

Comments

Snippets Manager replied on Wed, 2007/05/16 - 7:54pm

...and we have a winner! alias testme="ruby -wKUe 'a=%{git-svn};b=%{clone};c=%{`svn info`}.to_s.to_a[1][5..-2];d=%{../}+File.basename(Dir.pwd)+%{.git};system(a,b,c,d);'"

Snippets Manager replied on Wed, 2007/05/16 - 7:54pm

Whoops, that last `#{c}` should be a `#{p}`...

Snippets Manager replied on Wed, 2007/05/16 - 7:54pm

I reworked this to try and fit it into a shell alias, but I believe running `svn status` is killing it somewhere... but anyway, here you go for anyone else that wants a go at it! ruby -wKUe 'p=%{git-svn clone }+`svn info`.to_a[1][5..-2]+%{ ../}+File.basename(Dir.pwd)+%{.git};`#{c}`;'