Source code management

From FreeCAD Documentation
Revision as of 17:47, 20 February 2017 by FuzzyBot (talk | contribs) (Updating to match new version of source page)

Our main source code management tool is git. This article explains how to use it and how some general rules apply in the case of FreeCAD. You are highly advised to learn how git works first (there are a lot of tutorials and docs available for git on the internet) before working with the FreeCAD source code.

There are also many good graphical clients to git, such as git-cola, that make the whole process of managing git repositories easier.

Source Code Access

Everybody can access and get a copy of the FreeCAD source code, but only the FreeCAD project managers have write access to it. You can get a copy of the code, study it and modify it as you wish, but if you make a change that you wish to see included in the official source code, you need to ask for a pull request on the pull requests section of the FreeCAD forum.

NOTE

In all examples below, "USERNAME" represents your GitHub user account.


Official GitHub Repo

An easy way to start with the FreeCAD source code is using the official FreeCAD repository at https://github.com/FreeCAD/FreeCAD

Setting your git username

Users should commit to their project repository using their GitHub username. If that is not already set globally, you can set it locally for the current Git repository like this:

git config user.name "YOUR NAME"
git config user.email "USERNAME@users.noreply.github.com"

Ahora puedes utilizar alguna combinación de los comandos "git add" y "git commit" para crear uno o más envíos en tu repositorio local.

Fork on GitHub

You can start simply by using the "fork" button on top of the above page. This will create a copy of the FreeCAD repository on your own GitHub account. The general procedure is as follows:

  1. Sign up for a GitHub account
  2. Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD
  3. Press the "Fork" button
  4. On your machine, clone your newly created FreeCAD fork:
    git clone https://github.com/USERNAME/FreeCAD.git
  5. Create and checkout a new branch simultaneously
    git checkout -b newfeature
  6. Commit your changes to that new branch
  7. Push that new branch to your GitHub repo

Git clone to your local machine

You can also start normally, without using the "fork" button:

  1. Clone the FreeCAD code with git:
    git clone https://github.com/FreeCAD/FreeCAD.git
  2. Create and checkout a new branch simultaneously
    git checkout -b newfeature
  3. Commit your changes to that new branch
  4. Create an account on a public git server (GitHub, GitLab, etc...)
  5. Push your branch to that server

Important Note: If you have code you wish to see merged into the FreeCAD source code, please post a note in the Pull Requests section of the FreeCAD forum.

Alternative repositories

The beauty of git is that everybody can clone a project, and start modifying the code. Several frequent collaborators of the FreeCAD project have their own git repository, where they build up their work before it is ready to be included in the official source code, or simply where they experiment new ideas. In certain cases, you might want to clone your FreeCAD code from one of these, instead of the official repos, to benefit from the changes their users did.

Be warned, though, that this is at your own risk, and only the official repository above is fully guaranteed to work and contain clean code.

It is also possible to attach several remote repositories to a same local FreeCAD git code, using the "git remote" command. This is useful to keep in sync with the master code branch, but keep an eye on the work of different developers.

Git Development Process

First of all never develop on the master branch! Create a local branch for development. You can learn how to do this here.

Ramificado

Una importante característica de Git es que es extremadamente sencillo trabajar con ramas y fusionarlas. La mejor forma de trabajar recomienda crear una nueva rama siempre que quieras trabajar en una nueva característica. La creación de una rama se hace con:

git branch myNewBranch
git checkout myNewBranch

o, ambas operaciones en una:

git checkout -b myNewBranch

siempre puedes comprobar con que rama estas:

git branch

Envío

Una vez que hagas algo de trabajo, envíalo con:

git commit -a

A diferencia de SVN, tienes que especificar los archivos que quieres enviar (o todos con la opción -a). Tu editor de texto se abrirá para permitirte escribir un mensaje de envío.

Publishing your work on your GitHub repository

After done some changes on your local branch and commit it (this means commit locally) you can push your repository to the server. This opens your branch to the public and allows the main developers to review and integrate your branch into master.

git push my-branch

Escribiendo buenos mensajes de envío

Deberías tratar de trabajar en pedazos pequeños. Si no puedes resumir tus cambios en una frase, entonces posiblemente ha pasado pasado demasiado tiempo desde que hiciste un envío. También es importante que ofrezcas descripciones de tu trabajo que sean útiles y ayuden. Para los mensajes de envío, FreeCAD ha adoptado un formato mencionado en el libro Pro Git (mira #Otras lecturas).

 Resumen corto (50 caracteres o menos) de cambios
Texto de explicación más detallado, si es necesario. En unos 72 caracteres.
En algunos contextos, la primera línea es tratada como el tema
de un email y el resto del texto como el cuerpo. La línea en blanco
separando el tema del cuerpo es crítica (a menos que omitas el cuerpo por
completo); las herramientas de recálculo se pueden confundir si pones los
dos juntos.

Más párrafos van después de líneas en blanco. 

 - Las listas con viñetas también están bien

 - Tipicamente un guión o asterisco se utiliza para la viñeta, precedido 
   por un espacio en blanco, con líneas en blanco en medio, pero las 
   convenciones aquí varían

Si estas haciendo un montón de trabajo relacionado, se sugiere aquí que deberías hacer tantos envíos grandes o pequeños como sea necesario para que tengan sentido en lo que estés trabajando utilizado los mensajes cortos de envío. Cuando quieras fusionarlos, haz un registro master..BRANCH y utiliza el resultado para tu mensaje de envío. Cuando fusionas con el principal utiliza la opción --squash y envía con tu mensaje de envío. Esto te permitirá ser muy liberal con tus envíos y ayudar a proporcionar un buen nivel de detalle en los mensajes de envío sin demasiadas descripciones distintas.

Otras lecturas