Using Git and GitLab¶
The ctools source code is version controlled using Git that is managed through a GitLab web interface.
Every developer need to create a user in GitLab and have an own copy (a so called fork) of the ctools code in his/her user space. There is hence no need or possibility to push to the main ctools repository. Once you forked from the ctools repository, you can create feature branches and add some new code (or correct a bug), and issue a pull request so that your change gets included in the trunk. Our Git workflow is identical to the one you typically use on GitHub. You may in fact also use GitHub for your code developments, as the ctools source code is mirrored to GitHub in a read only repository.
Before you start¶
Make sure you configured your Git using your user name and e-mail address (you only need to do this once on your machine):
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
In addition, you may need to add
$ git config --global http.sslverify "false"
so that you have no SSL certificate error when you access the repository.
Overview¶
The figure below illustrates the Git workflow that we use for the ctools development. Permanent branches are shown as black lines, temporary branches as grey lines. The yellow area is the ctools repository, the light blue area is your forked user space. There are three permanent branches in the ctools repository:
the
masterbranch that holds the latest releasethe
develbranch that is the trunk on which development progressesthe
integrationbranch that is used for code integration
A temporary release branch is used for hotfixes and generally for code
testing prior to any release.
As developer you will work in your user space and work on temporary
feature branches.
Forking the project¶
As the first step you need to create a fork of the project in your user
space.
Connect to GitLab and select the
ctools
project and click on Fork in the top-right corner.
This brings you to a screen that invites you to select the user into which the project should be forked. Select your user space.
After a short while a fork will be created that now is under your ownership.
Now you can clone this fork using
$ git clone https://gitlab.in2p3.fr/[user]/ctools.git
where [user] is your
GitLab
user name.
To keep in sync with the ctools repository you should add it as
a remote repository using
$ git remote add upstream https://gitlab.in2p3.fr/ctools/ctools.git
You can then type
$ git pull upstream devel
to pull in changes from the devel branch of ctools in your
repository.
Modifying or adding code¶
To work on a new feature or to correct a bug you should always create a new branch. You do this by typing
$ git checkout devel
$ git pull upstream devel
$ git checkout -b 5783-correct-event-selection
which makes sure that you are on your devel branch, then pulls in changes
from the ctools repository, and finally creates the
5783-correct-event-selection branch.
New branches should always start with an issue number, followed by
a meaningful name that indicates what the branch is good for (use hyphens
to separate words).
You can find the relevant issue number using the
GitLab issue tracker.
Suppose that your goal is to correct a bug in the event selection in
ctselect.
You would then probably modify the ctselect.cpp file that is found in the
src/ctselect repository.
Once you have verified that the bug is correct you should commit your changes.
First stage the files you want to commit:
$ git add src/ctselect/ctselect.cpp
and then commit your change:
$ git commit -m "Corrected event selection in ctselect (#5783)
>
> The event selection in ctselect was not done correctly in case
> that no time intervals are specified. This is fixed now."
where the message in quotes should be comprised of a single line subject that describes what was changed, and a message body that describes why the change was made. Subject line and message body should be separated by a blank line (see How to Write a Git Commit Message).
To make the changes available to other users, and specifically to allow their merging into the ctools repository, you need to push you local changes into your GitLab’s repository. You do this by typing
$ git push origin 5783-correct-event-selection
Note that the origin argument specifies that you want to push your
changes into the same repository from which you cloned the code.