FAQ Récupérer, mettre à jour les sources GIT du projet

From Dolibarr ERP CRM Wiki
Jump to navigation Jump to search

Voici les informations sur comment récuperer et travailler avec les sources du projet Dolibarr.

Recevoir la dernière version des sources par téléchargement

Cette méthode vous permet de recevoir les sources de la branche de développement principale (Appelée HEAD). Cette opération consiste à récupérer la dernière version des fichiers de l'application Dolibarr qui sont compilées chaque nuit dans un fichier tgz. Ce fichier est disponible par le lien suivant:

Last GitHub snapshot of Dolibarr source files.

Les nouveaux fichiers écrasent les anciens. Le problème de cette méthode est qu'il faut télécharger et décompresser chaque fois le paquet dès que l'on souhaite recevoir des mises à jour.

Recevoir la dernière version des sources en utilisant un accès anonyme GIT.

Prérequis

  • Avec l'IDE Eclipse

Premièrement, vous devez avoir une installation fonctionnelle de Eclipse. Le plugin EGit doit aussi être installé. Pour l'installer, utilisez Help depuis le menu Eclipse puis cliquez sur Install new softwareet cliquez sur Available software site. Dans la liste des adresses qui apparait, recherchez le lien :

http://download.eclipse.org/egit/updates

Puis, choisissez d'installer EGit.

  • Avec le client GIT en ligne de commande

Pour récuperer les sources dans l'intention de les modifier, vous avez besoin d'un compte GitHub, et un client GIT (Les outils GIT en ligne de commande Linux, ou le client GIT d'Eclipse).

Processus de Clone

En verysmall.png Page waiting for translation. To translate, create an account, go back and clic on "Modify".
Fr verysmall.png Page en attente de traduction. Pour traduire, créez un compte, revenez et cliquez sur "Modifier".
Es verysmall.png Página a traducir. Para traducirla, cree una cuenta, vuelva a la página y haga clic en "editar".
It verysmall.png Pagina da tradurre. Per tradurla, crea un utente, torna indietro e clicca su "modifica".
Pt verysmall.png Página a aguardar por tradução. Para traduzir, crie uma conta, volte atrás e clique em "Modificar".
De verysmall.png Seite wartet auf Übersetzung. Um Übersetzung zu erstellen, richte einen Account ein, geh zurück und klicke auf "bearbeiten".
Zh verysmall.png 页面等待翻译。若要翻译本页,先创建一个帐户、登录并返回本页后单击“编辑”。

First, enter value of the repository with reference sources into your GIT client tool.

  • Avec l'IDE Eclipse, choose "Clone GIT repository". Enter GIT URL of project to get.

GIT Url for Dolibarr official source is:

git@github.com:Dolibarr/dolibarr.git
or
git://github.com/Dolibarr/dolibarr.git (lecture seule)

Your Eclipse GIT client will ask you to choose the branches you are interesting in. Branches not selected now could be selected later by doing a "Fetch" from the "Remotes" view, but try to choose only the branch you need. This will save you time and problems later.

  • Avec le client GIT en ligne de commande:

First setup your git client:

git config --global user.name "Your Name"
git config --global user.email "user@domain.com"
git config --list

Then clone repository locally:

git clone git://github.com/Dolibarr/dolibarr.git dolibarr

And, if you are behind a firewall, you can user the alternate URL:

git config --global http.proxy http://proxyuser:proxypass@proxyserver:proxyport
git clone https://gitlogin:gitpassword@github.com/Dolibarr/dolibarr.git dolibarr

Once this step is validated, your GIT client will download all files from remote GIT server. This may last several seconds or minutes.

Once download is finished, go into GIT view - Branches - Local. In most cases, the branch you choosed should be already available.

If not:

  • Avec Eclipse, right click on "Branches - Remotes - The branch you want to duplicate locally".

If you choose "Create Branch", this will duplicate content of branch to work on it locally. If you Choose "Checkout", this will update the view "Working Directory".

  • With GIT on Command Line Interface
git checkout develop
git checkout x.y

This will create local branch and make checkout automatically.


If using Eclipse, once your branch is created locally, create a PHP project from assistant by choosing "Create from existing project" and select directory that is your GIT local repository (Do not choose to create a PHP project from scratch). Then right click on project from your Eclipse workspace and Choose "Team - Share". Select GIT and click on option "Use or create repository in parent folder of project". An alternate method is File->Import, Git->Project from Git, Select the Git repository and Next, Use New project Wizard -> Php project, enter the folder of you GIT local repository.


Then, you can setup Eclipse to avoid it to scan all project files for its build tools (Outline scanner, TODO scanner, syntax scanner...). This will avoid Eclipse to be too slow. For this, right click on project, choose Build Path and setup it like into following screenshot.

Eclipse php build path.png

Récupérer la dernière version des sources avec un accès GIT complet

Prérequis

First you must have a working install of Eclipse. EGit plugin must also have been installed. For this, use the Find And Install process into Eclipse menu, add the GIT update URL:

http://download.eclipse.org/egit/updates

Then choose to install EGit.

You must before create an account on GitHub (https://github.com/) and upload a public RSA or DSA certificate into your account profile.

Processus de clone

Le processus est le même que pour récupérer les sources de manière anonyme (voir ci-dessus), seule l'URL d'accès change.

URL à utiliser pour le clonage GIT:

git@github.com:Dolibarr/dolibarr.git

Noter que une URL HTTP est aussi disponible mais est parfois hors service (aussi prenez de préférence la méthode précédente):

https://yourgitlogin@github.com/Dolibarr/dolibarr.git

Mettre à jour votre repository

Pour mettre à jour votre espace de travail local, faites un clic droit sur le projet Eclipse et sélectionnez "Pull".

Si vous avez apporté des modifications à votre espace de travail Eclipse sur des fichiers qui ont été modifiés dans la référence distante GIT, votre client GIT effectuera un merge automatiquement.

  • S'il y a des conflits, le merge marquera tous les fichiers en conflit comme "conflit" (Voir plus loin pour résoudre cet état).
  • Sinon, vous obtiendrez tous les nouveaux fichiers de version, y compris toutes vos modifications.

If you already have commited some files into your local repository, your workspace will be marked as "Merged". All you have to do is make a commit to validate your local repository as including your changes and changes made by others.

Validez et publiez vos modifications

Pour voir toutes les modifications que vous avez apportées à votre répertoire de travail et en attente d'être ajoutées à Git:

  • Avec l'interface >GIT en ligne de commande:
git status
git diff subdir/filename

To add changes made into your local repository into the GIT index, then commit this index :

  • With Eclipse: Right click on file or directory to commit. Select file to add/remove/update into commit.
  • With GIT Command Line Interface:
git commit -a -m "Commit text"

This will save add and changes into your local branch.

To push them on the GIT repository server,

  • With Eclipse: right click on project and choose "Team - Push to Upstream".
  • With GIT Command Line Interface:
git push

To cancel a commit:

  • With GIT Command Line Interface:
git revert IdCommit  or  git revert HEAD  (for last commit)

Ajouter un commit exterieur dans votre repository courant

Some developers may work and do commit into their own Git repository after forking the project. If you are interesting into getting this changes, you can import them with the following steps with Eclipse:

  • First, go into GIT setup view and right click on "Remotes" of your Eclipse Git working space and choose "Create a remote..."
  • Type name or remote fork the developer has create (in most cases, it's developer Git login). For example: "thedevlogin". Choose also "Configure Fetch".
  • Type URI of Git repository of developer. For example: git://github.com/thedevlogin/dolibarr.git. Also add a refspec value to declare the branch you want to get. For example: refs/heads/master:refs/remotes/thedevlogin/master. Click "Save and Fetch". A new entry will be added into "Remote Tracking" making possible to read/get commits done into this branch.

Now, go on command line of your git repository (in most cases on Linux, it's /home/yourlogin/git/yourdolibarr) and type the git cherry-pick command:

git cherry-pick -x commitid

where commitid is value of commit id you want to get.

Once this is done, go back to Eclipse and make a refresh on project. You will see modified files appears with decorators (with conflicts if there is).

It the cherry-pick fails because of conflicts, you can cancel the cherry-pick try with

git cherry-pick --abort

Résoudre un conflit

Si un fichier est marqué en "Conflit" après un "Pull", ouvrez le fichier et éditez le. Rechercher la chaine "<<<<<<<<<<", vous verrez la partie de code en conflit entre "<<<<<<<<<" et ">>>>>>>>". Editer manuellement les lignes de codes pour avoir le résultat finale en supprimant également les "<<<<<<<<" et ">>>>>>>".

Ensuite, faire un click droit sur le fichier puis choisir "Add".

Si vous préférez annuler complètement toutes les modifications que vous avez apportées à tous les fichiers (afin de restaurer votre espace de travail avec le contenu du repository distant), vous pouvez effectuer une réinitialisation:

  • Avec Eclipse, faites un clic droit sur la ligne supérieure du projet et sélectionnez "Réinitialiser" puis "Hard" then "Reference - HEAD".
  • En utilisant l'outil de ligne de commande GIT, vous pouvez y parvenir avec la commande
git reset --hard HEAD

Tagguer les sources

Avec les outils en Ligne de Commande GIT:

Pour créer un tag sur une version:

git tag -a -m "Release|Maintenance release x.y.z" "x.y.z"
or
git tag -a -f -m "Beta x.y.betai" "x.y.betai_YYYYMMDD" idcommit   # -f force si un tag existe déjà, idcommit permet de choisir le commit à tagguer

git push --tags   # Pour pousser le tags sur le serveur distant

Pour supprimer un tag:

git tag -d "x.y.z_YYYYMMDD"
git push origin :x.y.z_YYYYMMDD    # Pour valider la suppression sur le serveur distant

Créer une nouvelle branche

Voici la commande à utiliser pour créer une nouvelle branche depuis un repository propre develop:

git branch x.y
git push origin x.y

Statistiques

Avec les outils en Ligne de Commande GIT:

Pour compter le nombre de changerment qu'un développeur a fait entre une version x et y:

  • First, run git merge-base to know the id of last common commit between x and y
git merge-base origin/3.1 origin/develop
  • Then run git log to have list of all changes from last common commit to last commit
git log id_found_at_previous_step..HEAD
  • To get total number of added/deleted lines:
git log --ancestry-path --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'


To count number of changes finally between a version x and y (it differs from previous count because in previous count, a change can be done 2 times at two different moment to change differently. With second method, you count change finally found if changes were ok at first try):

  • Use same method than previously but instead of running git log, run git diff.
git diff -b -M --numstat --pretty="%H" id_found_at_previous_step..HEAD | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'


Plus d'information sur l'utilisation de GIT disponible ici.