Translation(s): ?English - Italiano

(!) ?Discussion


ToDo: translation in progress :)

Usare Git su Alioth

Creare un repository

Progetto di manutenzione collaborativa

Invece di registrare progetti separati per i pacchetti è consigliabile utilizzare il progetto di manutenzione collaborativa, per maggiori informazioni si veda la pagina ?Alioth/PackagingProject. Una volta concesso l'accesso a tale progetto (gli sviluppatori Debian hanno accesso in modo predefinito, mentre gli altri devono fare richiesta) è possibile avviare immediatamente il progetto Git ospitato accedendo su alioth.debian.org e creare un repository git in /git/collab-maint/.

Eseguire lo script setup-repository:

$ umask 002
$ cd /git/collab-maint
$ ./setup-repository <progetto> 'descrizione'

Progetto separato

Per i progetti registrati separatamente Alioth creerà un repository chiamato /git/<gruppo-progetto> di proprietà del proprio gruppo di progetto (a condizione che si sia selezionato Git come tipo di repository desiderato, vedere ?Alioth/FAQ#vcs-repos).

È possibile invece creare molteplici repository in questa directory:

$ umask 002
$ mkdir <progetto>.git
$ cd <progetto>.git
$ git --bare init --shared
$ vim description
$ mv hooks/post-update.sample hooks/post-update
$ chmod +x hooks/post-update

Caricamento iniziale

È possibile farlo manualmente come descritto qui o utilizzare git-buildpackage, come descritto alla pagina http://honk.sigxcpu.org/projects/git-buildpackage/manual-html/gbp.import.html#GBP.IMPORT.NEW.UPSTREAM

Quindi inserire un contenuto in tale repository, usando git fetch/pull su git.debian.org o git push su git.debian.org da una macchina remota. Vedere sotto per gli URL Git utilizzabili.

<!> Esempio: creare un repository Git locale e inserirvi del codice sorgente esistente:

$ cd /percorso/del/codice/<progetto>
$ git init
$ git config user.name '<proprio_nome>'
$ git config user.email '<propria_email>'
$ git config gitweb.owner '<proprio_nome>'
$ git add .
$ git commit -m 'Initial import of <progetto> version <versione>'
$ git tag <versione>

<!> Esempio: caricare un progetto su un repository collab-maint in Alioth:

$ cd /percorso/del/<progetto>.git
$ git remote add alioth ssh://<utente>@git.debian.org/git/collab-maint/<progetto>.git
$ git push alioth <nome_ramo>
$ git push alioth --tags

Accesso ai repository

Sono acceessibili da git usando sftp, rsync tramite ssh o un server http per l'accesso in sola lettura. Si noti che http://git.debian.org viene aggiornato ogni sei ore da cron, perciò ci vuole un po' di pazienza quando si crea un nuovo repository... alla fine apparirà. Per esempio, si potrà fare il check out del proprio ramo tramite sftp con:

$ git clone ssh://<utente>@git.debian.org/git/<gruppo>/<progetto>.git

Gli utenti anonimi potranno beneficiare di un accesso in sola lettura con i seguenti comandi, <gruppo> potrebbe ad esempio essere il nome del pacchetto o, se ospitato in collaborazione, collab-maint.

$ git clone git://git.debian.org/git/<gruppo>/<progetto>.git
$ git clone http://git.debian.org/git/<gruppo>/<progetto>.git

È consigliato utilizzare il protocollo nativo git in quanto molto più efficiente che clonare via HTTP, ma se il proprio firewall limita l'accesso alla porta 9418 allora lo si farà tramite HTTP. Si noti che in questo modo sarà necessario scaricare nuovamente tutti gli oggetti se il repository su Alioth viene rimpacchettato.

Manutenzione del repository

I repository Git tendono a crescere piuttosto velocemente, di tanto in tanto bisogna comprimerli per risparmiare spazio e mantenere prestazioni ottimali (per non avere troppi file nella sottodirectory degli oggetti).

$ cd /git/<gruppo>/<progetto>.git
$ git repack && git gc

Tali operazioni sono generalmente sicure (e possono essere eseguite tramite cron).

È possibile ottimizzare ancora di più con alcune opzioni, ma poi la gente che recupera tramite HTTP (pessima idea!) potrebbe avere problemi e non è sicuro eseguirle quando qualcun altro sta utilizzando il repository (per esempio caricando le nuove revisioni). Perciò questi comandi non vanno inseriti in cron:

$ git repack -a -d && git gc --prune

Impostazione delle notifiche

Invio email con diff

Modificare i valori pertinenti nelle righe seguenti:

$ cd <progetto>.git
# Per inviare diff ad una mailing list:
$ git config --add hooks.mailinglist "project-commit@lists.alioth.debian.org"
# Per inviare diff a PTS:
$ git config --add hooks.bcc "<pacchetto_sorgente>_cvs@packages.qa.debian.org"
# Crea la notifica:
$ cat >hooks/post-receive <<END
#!/bin/sh
exec /usr/local/bin/git-commit-notice
END
$ chmod a+x hooks/post-receive

Invio notifiche su IRC tramite un bot CIA

Ecco alcuni notificatori creati per CIA: http://cia-vc.googlecode.com/svn/trunk/cia/htdocs/clients/git/

Se già si utilizza il notificatore git illustrato sopra è possibile configurare CIA semplicemente con l'aggiunta di alcune variabili:

$ cd <project>.git
# Required to activate it
$ git config --add hooks.cia-project mioprogetto
$ git config --add hooks.cia-use-rpc 1 # Solo se si desidera inviare con XML RPC invece di email
$ git config --add hooks.cia-rpc-uri http://cia.vc/RPC2 # Solo per usare un altro server CIA

Uso di repository Git personali

Creazione di repository Git personali

È anche possibile avere repository Git personali. Accedere ad alioth, quindi:

$ mkdir ~/public_git
$ chmod a+xr public_git  # fornisce l'accesso al demone git
$ exit

Considerare $PRJ come il nome del progetto, $PRJDIR il percorso del repository locale del progetto e 'login' il nome dell'utente su Alioth.

export PRJ=progetto                            # il nome del progetto esportato (es. 'pbuilder')
export PRJDIR=~/progetto                       # il percorso dell'attuale repository git locale
export login=nomeutente                        # il nome dell'utente su Alioth

Uscire dalla sessione per preparare il repository che sarà pubblicato, quindi copiare su Alioth.

git clone --bare $PRJDIR $PRJ.git              # crea la directory esportabile 
touch $PRJ.git/git-daemon-export-ok            # comunica al demone git che è un repository pubblico
chmod a+x $PRJ.git/hooks/post-update           # prelevamento tramite http funzionante
(cd $PRJ.git && git-update-server-info)        # prelevamento tramite http funzionante
scp -r $PRJ.git/ $login@alioth.debian.org:public_git/ # copia il repository su Alioth

Verificare che il repository sia visibile (può richiedere del tempo, però, vedere sotto) utilizzando un browser per accedere al nuovo repository:

http://git.debian.org/?p=users/$login/$PRJ.git;a=summary

Verificare che funzioni in qualche directory vuota temporanea:

git clone git://git.debian.org/~$login/$PRJ.git
# in alternativa si può usare il (lento) metodo di prelievo tramite http 
#git clone http://git.debian.org/git/users/$login/$PRJ.git

Nota 1: rsync è molto più veloce di scp: rsync -av -e "ssh -l $login" $PRJ.git/ alioth.debian.org:public_git/$PRJ.git/

Nota 2: usare sshfs per creare il repository produce alcuni errori e pare più lento rispetto a creare il repository sul disco locale e quindi trasferirlo su Alioth con scp.

I link simbolici utilizzati per l'interfaccia gitweb vengono aggiornati ogni sei ore.

Saranno disponibili tramite i seguenti URL:

$ git clone git://git.debian.org/~$login/$PRJ.git

Maintaining the published Git repository up to date

Pushing to that repo is done with:

$ git push ssh://$login@alioth.debian.org/~$login/public_git/$PRJ.git

Personal Git repository - the morph way

Probably it's only me (hence the 'morph way' ;) ) but I'd like start from scratch, with an empty repository and then start adding content to it. That's how to do it.

This is a real example that I've created from this doc. Login to alioth with your user, then issue:

$ mkdir ~/public_git
## give access to git daemon
$ chmod a+xr public_git
$ cd public_git
## create the project repository directory
$ mkdir test.git
$ cd test.git/
## initialize a bare git repository in it
$ git init --bare
Initialized empty Git repository in /srv/alioth.debian.org/chroot/home/users/morph/public_git/test.git/
## set the description of the project
$ echo 'the project description' > description

work on alioth is done. You can have a look at the empty repo at:

http://git.debian.org/?p=users/morph/test.git

On our machine, we can clone the repo with:

$ git clone git+ssh://morph@git.debian.org/git/users/morph/test.git
Initialized empty Git repository in /home/morph/tmp/test/.git/
warning: You appear to have cloned an empty repository.
fatal: The remote end hung up unexpectedly

Don't worry about the "fatal" error: it's the way git says you've cloned an empty repository.

you can now start working on the repository:

$ cd test
$ echo "dummy file" > f
$ git add .
$ git ci -a -m "commit message"
[master (root-commit) 8ba3ab1] commit message
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 f
$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 214 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To git+ssh://morph@git.debian.org/git/users/morph/test.git
 * [new branch]      master -> master

now that the new branch 'master' is setup, you can git push normally without having to specify repo and ref. Now also gitweb is showing some info :)

Convert a SVN Alioth repository to Git

Here we'd like to provide a sequence of steps to follow to convert a SVN repository to a Git one (supposing they're both on Alioth). We will give a practical example converting reportbug repository.

First, you have to reconfigure your FusionForge project to indicate that you want to use git (see ?dedicated section in FAQ) so that /git/<project> is created. Once this is done, you can create as many git repository in it as you want.

Ref: http://gitready.com/beginner/2009/02/04/converting-from-svn.html

Create the author file

SVN stores commit authors information as SVN username, while Git uses fullnames and email addresses.

If you convert a repository without an author file, the commits will belong to a fake user made of the <SVN username>@<SVN UUID> as returned by

~/deb/reportbug$ svn info | grep UUID
Repository UUID: 692dde74-6b68-4300-bcb1-27de2ae967a4

In order to create a complete author file, we need to know everyone that has ever committed to the SVN repository; to achieve this, we can use this script:

$ svn log "svn://svn.debian.org/svn/reportbug/" | awk -F'|' '/^r[0-9]+/ { print $2 }' | sort -u
 appaji-guest
 bignose-guest
 lawrencc
 morph
 morph-guest
 (no author)
 root

(replace the correct SVN url for your project). Now we can create a file that contains this information:

...
svn username = fullname <email address>
...
morph = Sandro Tosi <morph@debian.org>
...

that maps SVN usernames to Git ones; manually edit and store that file where you prefer for later usage. If you are converting from a group-maintained package or package set, there might already be one which you can use.

Please note that if git svn clone finds an SVN author that's not in this file, it will exit with an error and won't finish cloning the repository.

Convert the repository

We are now ready to convert the repository. We will use git-svn, a great bidirectional interface between SVN and Git (you can work on Git and commit on Svn, and fetch the work done on SVN).

Let's first create a directory to contains the converted Git repo (if the same <project> name as SVN is not right) and then do the actual conversion:

mkdir pkg
git svn clone svn://svn.debian.org/svn/pkg --prefix=svn-import/ --stdlayout --authors-file=<author filename> --no-metadata pkg

Note:

  • we used clone from git svn since it does "init + fetch" in a single pass
  • we added prefix as these branches will be converted later and a common prefix makes this easier
  • --author-file specifies the location of the author file, previously defined
  • --no-metadata will remove the SVN url from every commit messages (something like "git-svn-id: svn://svn.debian.org/svn/pkg/trunk@696 692dde74-6b68-4300-bcb1-27de2ae967a4"); we used it because we want to remove SVN, if you plan to maintain both repositories, then remove this option
  • pkg/ is the destination dir

Convert remote tags and branches to local one

After conversion, the SVN tags and branches are all Git remote branches. We would like to convert them to Git proper tags and to local tags and branches.

Let's start with converting tags. If you would like to sign the tags with your GPG/PGP key, add the option -s to the git tag command:

for branch in `git branch -r`; do
    if [ `echo $branch | egrep "svn-import/tags/.+$"` ]; then
        version=`basename $branch`
        subject=`git log -1 --pretty=format:"%s" $branch`
        GIT_COMMITTER_DATE=`git log -1 --pretty=format:"%ci" $branch` \
            git tag -f -m "$subject" "debian/$version" "$branch^"

        git branch -d -r $branch
    fi
done

where we list all the "tags/*" branches, convert to tag and remove the remote branch.

If it's a one-way migration (SVN will not be used anymore), then SVN compatibility references can be removed:

git branch -d -r svn-import/trunk
git config --remove-section svn-remote.svn
rm -rf .git/svn .git/{logs/,}refs/remotes/svn/

Now we can convert the remaining remote branches to local ones:

git config remote.origin.url .
git config --add remote.origin.fetch +refs/remotes/*:refs/heads/*
git fetch

And finally we can import the upstream source:

git symbolic-ref HEAD refs/heads/upstream
git rm --cached -r .
git commit --allow-empty -m 'initial upstream branch'
git checkout -f master
git merge upstream
git-import-orig ../foo_1.2.3.orig.tar.gz

Ref: http://github.com/nothingmuch/git-svn-abandon/tree/master Ref: http://blogs.frugalware.org/vmiklos/2007/12/09/svn_ggit_conversion_using_git_svn Ref: http://frank.thomas-alfeld.de/wp/2008/08/30/converting-git-svn-tag-branches-to-real-tags/ Ref: http://upsilon.cc/~zack/blog/posts/2008/03/git-buildpackage_from_debian-only_to_debian+upstream/

Prepare the repository for publishing on web

What we have up to now is a Git repository "injected" in a checkout copy. We would like to publish that repository to the web, so other clients can clone on their machine.

We start by creating a new repository:

morph@alioth:~/reportbug$ git clone --bare reportbug reportbug.git
Initialized empty Git repository in /srv/alioth.debian.org/chroot/home/users/morph/reportbug/reportbug.git/

that also allows for a big size reduction:

morph@alioth:~/reportbug$ du -hs reportbug reportbug.git/
35M     reportbug
1.4M    reportbug.git/

Now we need to edit the description of the repository (the one that gitweb will display):

echo "Reportbug - reports bugs in the Debian distribution" > reportbug.git/description

We are now ready to copy the resulting repository to its final destination:

cp -r reportbug.git /git/reportbug/

Now point your browser to http://git.debian.org/?p=reportbug/reportbug.git and enjoy! To get a local repository run:

git clone git://git.debian.org/git/reportbug/reportbug.git
git clone git+ssh://git.debian.org/git/reportbug/reportbug.git

(in the 2 flavors for anonymous and ssh authentication) on your machine.


?CategoryAlioth