Gestion du code source
Notre principal outil de gestion de code est git. Cet article explique comment l'utiliser et les règles générales qui s'appliquent dans le cas de FreeCAD. Il est fortement recommandé d'apprendre comment fonctionne git (il existe beaucoup d'informations et de tutoriels à propos de git sur internet) avant de travailler avec le code source de FreeCAD.
Il existe également de nombreux bons clients graphiques pour git, comme par exemple git-cola, qui rendent le processus de management des dépôts git plus facile. Il existe également une introduction superficielle au "Développement de FreeCad avec GitKraken"
Accès au code source
Tout le monde peut accéder et obtenir une copie du code source de FreeCAD , mais seulement les managers du projets ont les droits d'écriture. Vous pouvez obtenir une copie du code, l'étudier et le modifier autant que vous le souhaitez, mais si vous voulez faire des modifications que vous souhaitez voir incluses dans les sorties officielles, vous devez effectuer un "pull request" via la section "pull requests" du forum FreeCAD.
dans tous les exemples ci-dessous, "GITHUB_USERNAME" represente votre compte GitHub.
Dépôt officiel Github
Un façon simple de commencer à travailler avec le code source de FreeCAD est d'utiliser le dépot officle FreeCAD https://github.com/FreeCAD/FreeCAD
Configuration de votre nom d'utilisateur git
Les utilisateurs doivent faire un commit vers leur dépôt de projet, en utilisant leur nom d'utilisateur GitHub. Si ce n'est pas déjà fait globalement, vous pouvez le régler au niveau local pour le dépôt Git actuel comme ceci :
git config user.name "YOUR NAME" git config user.email "GITHUB_USERNAME@users.noreply.github.com"
Vous pouvez maintenant utiliser une combinaison de commandes "git add" et "git commit" pour créer un, ou plusieurs commits dans votre dépôt local.
A note about Remotes
Please read some background to help you understand better the difference between what origin and upstream mean in the context of git. This section explains how to set the correct upstream and origin remote git repos. Essentially:
origin
= Your fork of the FreeCAD git repo AKA https://github.com/GITHUB_USERNAME/FreeCAD.gitupstream
= The official FreeCAD git repo AKA https://github.com/FreeCAD/FreeCAD.git- This is important to understand because if you
git clone
directly fromupstream
then confusingly, your origin will be listed as https://github.com/FreeCAD/FreeCAD.git
BTW, if you do this accidentally you can use thegit remote rename
command to remedy the situation.
- This is important to understand because if you
So, based on the above, there are 2 main ways to setup your git environment:
- 1st Method: Fork on GitHub and clone your fork locally
- 2nd Method: Clone FreeCAD official directly to your local machine
We recommend the 1st method for the reason mentioned above.
1st Method: Fork on GitHub and clone your fork locally
You will need to re-configure 'remote upstream' as mentioned above in "A note about Remotes"
This method is the recommended way since it takes less steps. You will essentially fork the FreeCAD repo on your own GitHub account and then clone said GitHub fork locally. Then you will set your upstream repo in git. The procedure is as follows:
- Sign up for a GitHub account if you don't already have one
- Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD
- In the top right of the page find and press the "Fork" button (this will essentially git clone the official FreeCAD repo to your personal GitHub repo: https://github.com/GITHUB_USERNAME/FreeCAD.git)
- On your machine, clone your newly created FreeCAD fork by opening a terminal and typing:
git clone https://github.com/GITHUB_USERNAME/FreeCAD.git
- Once the clone process is complete, now set your
upstream
remote repo (see "A note about Remotes"). Find out what and where your remote git repositories are set to. Typegit remote -v
and the output should look similar to:[foo@bar FreeCAD]$ git remote -v origin https://github.com/GITHUB_USERNAME/FreeCAD.git (fetch) origin https://github.com/GITHUB_USERNAME/FreeCAD.git (push)
- Great. Now set your
upstream
repo[foo@bar FreeCAD]$ git remote add upstream https://github.com/FreeCAD/FreeCAD.git
- Check your remotes again, they should look similiar to this:
[foo@bar FreeCAD]$ git remote -v origin https://github.com/GITHUB_USERNAME/FreeCAD.git (fetch) origin https://github.com/GITHUB_USERNAME/FreeCAD.git (push) upstream https://github.com/FreeCAD/FreeCAD.git (fetch) upstream https://github.com/FreeCAD/FreeCAD.git (push)
- Now we can start developing. Please refer to "Git Development Process"
Vous pouvez aussi commencer normalement, sans utiliser le bouton "fork" :
- Clonez le code FreeCAD avec Git
- Faites vos changements sur le code source
- Créez une nouvelle branche
- Extraire cette nouvelle branche (Checkout to that branch)
- Soumettre (Commit) vos changement à cette nouvelle branche
- Créez-vous un compte sur un serveur Git public (github, gitorious, sourceforge ou n'importe quel autre)
- Publiez (Push) votre branche sur ce serveur
Processus de développement Git
Tout d'abord, ne jamais développer sur la branche principale ! Créer une branche locale de développement. Vous pouvez apprendre comment ceci ici.
Ramifications
Une caractéristique importante de Git, est qu'il est extrêmement facile de travailler avec des branches, et, les fusionner. La meilleure pratique recommande de créer une nouvelle branche à chaque fois que vous voulez travailler sur une nouvelle fonctionnalité.
Création d'une branche se fait avec :
git branch myNewBranch git checkout myNewBranch
ou, les deux opérations en un seule :
git checkout -b myNewBranch
vous pouvez toujours vérifier, dans quelle branche vous êtes avec :
git branch
Soumettre
Une fois que vous avez fait un peu de travail, validez le avec :
git commit -a
Contrairement à SVN, vous devez informer avec précision les fichiers à envoyer (ou la totalité avec l'option -a). Votre éditeur de texte s'ouvrira, pour vous permettre d'écrire un message de validation.
Publication de votre travail sur "sourceforge repository"
Si vous avez un developpement que vous voulez voir intégrer au code source de FreeCAD, veuillez poster une note dans la section Pull Request du forum de FreeCAD
Après avoir fait des modifications sur votre branche locale, et, l'engager (commit) (cela signifie s'engager localement), vous pouvez envoyer votre référentiel sur le serveur. Cela ouvre votre branche au public, et, permet aux principaux développeurs d'examiner, et, d'intégrer votre branche en "maître" .
git push <REMOTENAME> <BRANCHNAME> git push origin my-branch
For further info on this subject please read https://help.github.com/articles/pushing-to-a-remote/
Rédaction de bons messages de commit
Vous devriez essayer de travailler en petites sections. Si vous ne pouvez pas résumer vos modifications en une seule phrase, il y a probablement trop longtemps, que vous avez fait un commit. Il est également important de donner une descriptions détaillée, et, utile de votre travail. Pour les messages de commit, FreeCAD a adopté un format qui est mentionné dans le livre Git Pro.
Court sommaire des changements (50 caractères ou plus)
Si nécessaire, bien détailler les textes explicatifs. Ecrivez-en environ 72 caractères ou plus. Dans certains cas, la première ligne est considérée comme l'objet (résumé) d'un email, et, le reste du texte comme le corps. Laisser une ligne blanche pour séparer le résumé, du corps du message (sauf si vous omettez l’entièreté corps); des outils comme rebase peut se confondre si vous exécutez les deux ensemble.
Les paragraphes supplémentaires, viennent après les lignes vides. * Les puces sont très bien aussi - En général, un trait d'union ou un astérisque est utilisé pour la puce, précédé d'un espace unique, avec des lignes blanches entre les deux, mais ici les conventions varient.
Si vous faites beaucoup de travaux connexes, il a été suggéré ici, que l'on doit faire autant de commits que possible, grand ou petit, dans le sens que vous utilisez des messages avec de courtes phrases. Lorsque vous souhaitez faire une fusion, faites un journal log master git .. BRANCH, et, utilisez la sortie comme une base, pour la qualité de votre commit message. Ensuite, lorsque vous effectuez la fusion, utilisez l'option --squash, et, engagez avec le message de validation (commits) de qualité. Cela vous permettra d'être très libéral avec votre commit, et, aidez à assurer un bon niveau de détails des messages de commit sans faire trop de descriptions distinctes.
Advanced git operations
Resolving Merge Conflicts
- git-scm explanation on how conflicts are presented
- GitHub article on resolving merge conflicts via the command-line
- Customize your preferred merge tool when you encounter a git conflict.
Applying patches via git
Git has the capability to merge patches/diffs. To read more about this read the following reference: https://www.drupal.org/node/1399218
git apply [patch-name].patch
Apply a patch via curl
A very handy and powerful feature of git and the command line is the ability to quickly test patches all through the terminal.
curl -O https://github.com/FreeCAD/FreeCAD/commit/[patch-name].patch git apply [patch-name].patch
or alternatively, using bash pipes you can make a sweet 1-liner:
curl https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.patch | git apply -
- Useful tip: Just add .diff or .patch at the end of the URL for a GitHub commit page, Pull Request, or Compare View and it'll show you theplaintext view of that page. Example:
- Regular GitHub page: https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621
- 'Diffed' GitHub page: https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.diff
- 'Patched' GitHub page: https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.patch
Creating patches from git
There are times when one may need to create a patch instead of submitting a PR. The following workflow explains how to do this:
- Make sure you are in the correct branch (i.e. not the master branch) by checking with
git branch -v
- Create the patch: we do this by using the git format-patch command which we patch against the master branch and redirect to STDOUT. We create the patch in the directory outside of the source build (in order not to pollute the source dir itself, this is optional as you can decide the location wherever you want the patch to be created)
git format-patch master --stdout > ../patch.name.patch
- Another method is to use git format-patch HEAD^ or git format-patch HEAD~1 The ^ or 1 can be changed to number of commits that should be covered i.e.: ^^^ or ~3.
git format-patch HEAD^
It will create a patch or series of patches with file name format XXXX-commit-message.patch. An example: 0001-fix-ViewProjMatrix-getProjectionMatrix.patch
Reversing a patch in git
If you've followed the instructions above and then have a change of heart about using the patch, you can quickly reverse it using:
git apply -R path/file.patch
or another way is to use:
git checkout -f
which will remove non-committed changes to the branch
Stashing git commits
Say you're working on a branch and you find yourself making some modification to the source that is out of the scope of your current branch in other words it would be better to add certain commits to a whole other branch and submit it instead of the current one. This is where the git stash command can be very useful. The git stash command can help you to (temporarily but safely) store your uncommitted local changes.
git stash
Then in the future when you want to use these commits you can
git stash apply
or
git stash pop
pop will delete the stash If you have multiple stashes you can
git stash list
To read more about what other functions you can use checkout https://medium.freecodecamp.org/useful-tricks-you-might-not-know-about-git-stash-e8a9490f0a1a
What is the latest FreeCAD Dev Revision
There are 2 ways to do this:
- 1st method: In your cloned git directory type:
git rev-list --count master
- 2nd method: Browse https://github.com/FreeCAD/FreeCAD and read the amount of commits FreeCAD is at.
What is the Revision number of a specific commit hash and visa ver?
git rev-list --count 9948ee4 13541
- some forum topics in this regard:
How is the Revision number in FreeCAD help about generated?
Depuis des dépôts alternatifs
La force de Git est que tout à chacun peut cloner un projet, et commencer à modifier du code. Plusieurs contributeurs fréquents du projet FreeCAD ont leur propre dépôt Git, avec lequel ils réalisent leur travail avant que des modifications soient prêtes pour être incluses dans le code source officiel, ou avec lequel ils expérimentent simplement de nouvelles idées. Dans certains cas, vous pouvez souhaiter cloner votre code FreeCAD depuis un des ces dépôt plutôt que depuis les dépôts officiels, pour pouvoir bénéficier des changements réalisés par leur utilisateurs.
Attention cependant, vous pouvez le faire à vos risques et périls. Seul les deux dépôts ci-dessus garantissent de fonctionner et de contenir un code propre.
Il est également possible de lier plusieurs dépôts distants avec un seul code local, en utilisant la commande "git remote". C'est pratique pour rester synchronisé avec la branche "master", mais gardez un œil sur le travail des différents dévelopers.