lunedì 6 dicembre 2010

Creare un repo git condiviso

Sulla mia box attuale ho due dischi in raid 1 su cui si trova la /home. Per sviluppare ho una vm QEMU/KVM con sopra Ubuntu 10.04 Server, il cui disco però non risiede sul suddetto raid.

Dato che voglio avere una certa ridondanza per i dati, volevo fare in modo di avere un repository git centralizzato sulla macchina host (nella home, quindi sul raid) da cui clonare nella vm (ed eventualmente sul portatile) per sviluppare e poi pushare di nuovo sul repo sul raid.

Inizialmente ho semplicemente creato un repository sulla macchina host, l'ho clonato sulla vm, ma al momento di effettuare il push usciva questo simpatico errore:

vm ➤ git push
Counting objects: 36, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (23/23), done.
Writing objects: 100% (25/25), 84.45 KiB, done.
Total 25 (delta 6), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To host:c0ding/ruby/project
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'host:c0ding/ruby/project'

Il problema era che essendo loggato anche sulla macchina host ed avendo un repository "aperto", git si rifiutava di farmi mischiare le due cose. Inizialmente, per risolvere, mi sono limitato a creare un nuovo branch sulla macchina host:

host$ git checkout -b temp-repo

La soluzione più corretta, però, l'ho trovata su stack overflow (e sul sito linkato, pro git): era necessario creare un "bare repository", ovvero un repository che contiene solo i dati GIT e nessun altro file.

Quindi ho fatto:

host$ rm -rf ~/c0ding/ruby/project

vm ➤ git clone --bare project project.git  # creazione bare repo
vm ➤ scp -r project.git host:c0ding/ruby/  # copia del repo sull'host
vm ➤ rm -rf project project.git            # rimozione vecchi repo sulla vm
vm ➤ git clone host:c0ding/ruby/project.git # clone nuovo repo sulla vm
vm ➤ cd project
vm ➤ git log

commit xxx
Author: Gilberto "Velenux" Ficara
Date:   Mon Nov 1 15:40:20 2010 +0100

Added Cucumber, JQuery support gems. Created DB.

commit xxx
Author: Gilberto "Velenux" Ficara
Date:   Mon Nov 1 14:42:03 2010 +0100

Initial commit

vm ➤ 

Nessun commento:

Posta un commento