Convertire un repository Svn in Git

From RVM Wiki
Revision as of 12:04, 6 September 2011 by Gabriele.vivinetto (talk | contribs)
Jump to navigation Jump to search

Manualmente

Script per convertire i repository di etc/

  • Assicurarsi che il repository SVN sia in
/files/svn/repositories/etc
  • Assicurarsi che il percorso del repository sia
file:///files/svn/repositories/etc/trunk
#!/bin/bash
sudo apt-get install git-core git-svn
sudo mkdir -p /files/git/repos/etc
cd /files/git/repos/etc
sudo chmod 750 /files/git/repos/etc
sudo chown -R :www-data /files/git/
sudo git init --bare
echo "/etc $(hostname -f) Git Repository" | sudo tee description > /dev/null
cd /tmp/
sudo rm -rf svn
mkdir svn
cd svn
sudo svn co file:///files/svn/repositories/etc .
sudo svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
vi authors-transform.txt
sudo rm -rf /tmp/git
sudo mkdir /tmp/git
cd /tmp/git
sudo git svn clone file:///files/svn/repositories/etc --no-metadata -A ../svn/authors-transform.txt .
sudo git svn show-ignore | sudo tee  .gitignore
sudo git add .gitignore

sudo git config --global user.name "Root $(hostname)"
sudo git config --global user.email root@$(hostname -f)
git config --global user.name "Gabriele Vivinetto"
git config --global user.email gabriele.vivinetto@rvmgroup.it

sudo git commit -m 'Convert svn:ignore properties to .gitignore.'
sudo git remote add etc /files/git/repos/etc
sudo git config remote.etc.push 'refs/remotes/*:refs/heads/*'
sudo git push etc
sudo chmod a+rX /files/git/repos/etc
cd /files/git/repos/etc
sudo git symbolic-ref HEAD refs/heads/git-svn
sudo git branch -m git-svn master
cd /tmp/
sudo rm -rf /tmp/etc
sudo mkdir etc
cd etc/
sudo git clone /files/git/repos/etc .
if [ -d trunk ]
then
        sudo git mv trunk/* .
        sudo git mv trunk/.pwd.lock .
        sudo git mv trunk/.serial.conf.old .
        sudo git commit -a -m "* removed trunk"
fi
sudo git push
  • Convertire la etc/ attuale
cd /
sudo tar cvf /files/etc.tar etc/
cd /etc
sudo rm -rf $(sudo find . -name \.svn)
sudo mv /tmp/etc/.git .
sudo mv /tmp/etc/.gitignore .
sudo git status
sudo git add .
sudo git commit -a -m "First git commit"
sudo git push


  • Pulire la etc:
yes  | sudo update-alternatives --force --all > /dev/null ; sudo git commit -a -m "Removed broken link in alternatives/
sudo git rm $(sudo find . -name \*\.dpkg-\*); sudo git commit -a -m "Removed *.dpkg-*"
sudo git rm $(sudo find . -name \*\.ucf-\*);  sudo git commit -a -m "Removed *.ucf-*"
sudo git rm .pwd.lock *.drbl* *.old; sudo git commit -a -m "Removed unused files"
sudo git rm $(sudo find . -name \*\.old\*);  sudo git commit -a -m "Removed *.old*"
sudo git push

Procedura in dettaglio

  • Installare il convertitore git-svn
sudo apt-get install git-core git-svn
  • Fare il commit del repository
cd /etc
sudo ~/bin/svnaddmissing
sudo ~/bin/svndelmissing
sudo svn ci -m "* Last svn commit."
  • Creare il repo git vuoto ed inizializzarlo
sudo mkdir -p /files/git/repos/etc
cd /files/git/repos/etc
sudo chmod 750 /files/git/repos/etc
sudo chown -R :www-data /files/git/
sudo git init --bare
  • Fare il checkout del repository svn per estrarre gli autori
cd /tmp/
mkdir svn
cd svn
sudo svn co file:///files/svn/repositories/etc .
  • Verificare che abbia la struttura standard trunk/ branches/ tags
  • Estrarre gli autori
sudo svn log -q | awk -F '|' '/^r/ {sub("^ ", "", $2); sub(" $", "", $2); print $2" = "$2" <"$2">"}' | sort -u > authors-transform.txt
  • Editare nomi ed email
vi authors-transform.txt
root = Root Fireman <root@fireman.mannesmann.priv>
  • Convertire il repository CHE DEVE AVERE IL LAYOUT STANDARD trunk/ tags/ branches/ SENZA CHE CI SIA STATA LA CONVERSIONE DA UN ALTRO FORMATO. Si perderanno tutti i commit precedenti alla formalizzazioen della struttura standard
sudo mkdir /tmp/git
cd /tmp/git
  • Per standard layout
sudo git svn clone file:///files/svn/repositories/etc --no-metadata -A ../svn/authors-transform.txt --stdlayout .
  • Se invece il repository ha un solo folder principale:
sudo git svn clone file:///files/svn/repositories/etc --no-metadata -A ../svn/authors-transform.txt .
  • Convertire gli ignore per standard layout
sudo git svn show-ignore -i trunk | sudo tee  .gitignore
  • Convertire gli ignore per NON standard layout
sudo git svn show-ignore | sudo tee  .gitignore
  • Aggiungere il file .gitignore
sudo git add .gitignore
sudo git commit -m 'Convert svn:ignore properties to .gitignore.'
  • Linkare il repository locale a quello remoto:
sudo git remote add etc /files/git/repos/etc
  • Tweak per i percorsi svn
sudo git config remote.etc.push 'refs/remotes/*:refs/heads/*'
  • Fare il push
sudo git push etc
(oppure sudo git push etc trunk) ? 
  • Convertire il trunk nel repository centrale
sudo chmod a+rX /files/git/repos/etc
cd /files/git/repos/etc
  • Se ha lo standard layout:
sudo git symbolic-ref HEAD refs/heads/trunk
sudo git branch -m trunk master
  • Se ha solo un folder principale:
sudo git symbolic-ref HEAD refs/heads/git-svn
sudo git branch -m git-svn master
  • Se ha lo standard layout, creare lo script per convertire i branches e tags
sudoedit convert-tags-branches
git for-each-ref --format='%(refname)' refs/heads/tags |
cut -d / -f 4 |
while read ref
do
  git tag "$ref" "refs/heads/tags/$ref";
  git branch -D "tags/$ref";
done
sudo chmod +x convert-tags-branches
  • Convertire il branches ed i tag
sudo ./convert-tags-branches
  • Se ha un solo un folder principale
cd /tmp/
sudo mkdir etc
cd etc/
sudo git clone /files/git/repos/etc .
sudo git mv trunk/* .
sudo git mv trunk/.pwd.lock .
sudo git mv trunk/.serial.conf.old .
sudo git commit -a -m "* removed trunk"
sudo git push
  • Risistemare le permission
cd /tmp
sudo chmod 750 /files/git/repos/etc
  • Provare a fare un clone:
cd /tmp
mkdir test
cd test
sudo git clone /files/git/repos/etc/ .
  • Per linkare la working copy attuale, fare un clone nuovo, per avere un repository pulito
cd /tmp
sudo mkdir etc
cd etc
sudo git clone /files/git/repos/etc .
  • Pulire la working copy dai flder .svn
cd /etc/
for RES in $(sudo find . -name \.svn); do sudo rm -rf $RES; done
  • Spostare il repository clonato
sudo mv /tmp/etc/.git .
  • Eventualmente aggiungere dei files .placeholder nelle directories vuote, perchè git non le versiona (ma questo è un lavoro da fare seguendo Gestire /etc sotto git con etckeeper ...):
 #sudo find . -type d -empty | grep -v \.git
  • Verificare eventuali discrepanze ed allineare
sudo git status
sudo git add .
sudo git commit -a -m "* First git commit"
sudo git push


Riferimenti

Con git-svn-migrate

Lo script è compatibile solo con git>=1.7 (NON va da lenny) IN OGNI CASO ANCHE DA SQUEEZE NON VA

  • Installare il convertitore git-svn
sudo apt-get install git-core git-svn
  • Scaricare lo script di conversione
cd /tmp/
  • Fino a che i fix con /bin/bash non sono stati integrati, prelevare da
git clone https://github.com/mallman/git-svn-migrate.git
e cambiare gli interpreti in /bin/bash
poi si può usare il repository originale
git clone https://github.com/JohnAlbin/git-svn-migrate
cd git-svn-migrate/

  • Fare l'ultimo commit sul repository svn
  • Creare il file contenente l'elenco dei repository da convertire
vi repositories-list.txt
file:///files/svn/repositories/etc
  • Creare il file con gli autori:
sudo ./fetch-svn-authors.sh --url-file=repositories-list.txt > author-transform.txt
  • Editarlo per correggerlo:
vi author-transform.txt
root = Root Crosrv01 <root@crosrv01.cross.priv>
  • Convertire il repository:
sudo ./git-svn-migrate.sh --url-file=repositories-list.txt --authors-file=author-transform.txt /tmp/git-converted


  • Creare la dir per il repo centrale git vuoto
sudo mkdir -p /files/git/repos/etc
cd /files/git/repos/etc
  • Spostarci quello convertito
sudo mv /tmp/git-converted/etc.git/* /files/git/repos/etc

Riferimenti