{"thread":{"id":"30582","subject":"Attempt of a git-svn-switch","startedAt":"2012-05-21T22:03:28Z","lastAt":"2012-05-21T22:03:28Z","messageCount":1,"participants":["Ronan Keryell"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"191830","messageId":"87k40519an.fsf@an-dro.info.enstb.org","threadId":"30582","inReplyTo":null,"subject":"Attempt of a git-svn-switch","fromName":"Ronan Keryell","fromEmail":"ronan.keryell@hpc-project.com","sentAt":"2012-05-21T22:03:28Z","receivedAt":"2012-05-21T22:03:28Z","isPatch":false,"sender":{"key":"ronan.keryell@hpc-project.com","avatar":null},"body":"One of my projects relies heavily on many SVN repositories I use through\ngit-svn.\n\nThe upstream SVN URL has changed recently and I found incredibly complex\nand time-consuming to do this (apparent) simple change.\n\nAfterwards, I think it would have been simpler for me and more robust to\nadd a \"switch\" command to git-svn... But anyway, I've done a shell\nscript and I do not have more time to work on it.\nIt is not rocket science but it may be useful to others...\n\nhttps://git.hpc-project.com/cgit/par4all/tree/src/dev/git-svn-switch?h=p4a-own\n\n\n#! /bin/sh\n\n# Switch the SVN URL of a local git-svn repository\n\n# git-svn-switch <old-url-substring> <new-url-substring>\n\n# Do a fetch and replace in the URL old-url-substring by new-url-substring.\n# The rationale for substring is to be able to process many git-svn repository\n\n# Typical use case:\n#   git-svn-switch http://svn.cri.ensmp.fr/svn https://scm.cri.ensmp.fr/svn\n# or to update a bunch of git-svn repositories in the same directory:\n#   for i in *; do (cd $i; git-svn-switch http://svn.cri.ensmp.fr/svn https://scm.cri.ensmp.fr/svn); done\n\n# Basically implement https://git.wiki.kernel.org/index.php/GitSvnSwitch\n# and add a reset to one version in the past to be sure to have new stuff\n# to fetch from the SVN server.\n# It guesses that the previous svn version is the current - 1\n\n\n# Irresponsible of this: Ronan.Keryell at wild-systems.com\n# I think afterwards it would have been easier to add a switch option to\n# git svn instead of hacking this way...\n\n\n# Switch tracing mode on, so that if something goes wrong we can figure\n# out where to resume later, back-track and so on:\nset -vx\n\nold_url_string=\"$1\"\nnew_url_string=\"$2\"\n\nold_url=`git config --get svn-remote.svn.url`\n\n# Do the URL rewriting (we hope there are no '|' in the URL):\nnew_url=`echo \"$old_url\" | sed -e \"s|$old_url_string|$new_url_string|\"`\n\n# Get the previous svn revision so that we can reset to it to be sure we\n# will fetch something (well, we guess here that the previous version is\n# current - 1):\ncurrent_svn_revision=`git svn info | awk '/^Revision:/ { print $2 - 1 }'`\n\n# Go back to previous version:\ngit svn reset -r $current_svn_revision\n\ngit config --replace-all svn-remote.svn.url \"$new_url\"\ngit svn fetch\ngit config --replace-all svn-remote.svn.url \"$old_url\"\ngit svn rebase -l\ngit config --replace-all svn-remote.svn.url \"$new_url\"\ngit svn rebase\n\n\n\n-- \n  Ronan KERYELL                            |\\/  Phone:  +1 408 658 9453\n  Wild Systems / HPC Project               |/)\n  5201 Great America Parkway, Suite 320    K    Ronan.Keryell@wild-systems.com\n  Santa Clara, CA 95054                    |\\   skype:keryell\n  USA                                      | \\  http://wild-systems.com\n"}]}