https://wiki.freecad.org/api.php?action=feedcontributions&user=Opus&feedformat=atomFreeCAD Documentation - User contributions [en]2024-03-28T19:40:34ZUser contributionsMediaWiki 1.40.1https://wiki.freecad.org/index.php?title=Source_code_management&diff=413070Source code management2019-02-07T15:54:32Z<p>Opus: External link corrections</p>
<hr />
<div><languages/><br />
<translate><br />
<!--T:1--><br />
Our main source code management tool is [http://en.wikipedia.org/wiki/Git_%28software%29 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.<br />
<br />
<!--T:2--><br />
There are also many good graphical clients to git, such as [http://github.com/git-cola/git-cola git-cola], that make the whole process of managing git repositories easier. FYI there also exists a cursory intro to [[Developing FreeCAD with GitKraken]]. <br />
<br />
== Source Code Access == <!--T:3--><br />
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 [http://forum.freecadweb.org/viewforum.php?f=17 pull requests] section of the FreeCAD forum.<br />
<br />
<!--T:37--><br />
{{Note|NOTE|In all examples below, "GITHUB_USERNAME" represents your GitHub user account.}}<br />
<br />
=== Official GitHub Repo === <!--T:5--><br />
An easy way to start with the FreeCAD source code is using the official FreeCAD repository at<br />
</translate><br />
'''https://github.com/FreeCAD/FreeCAD'''<br />
<translate><br />
<br />
=== Setting your git username === <!--T:18--><br />
Users should commit to their project repository using their GitHub username. <br />
If that is not already set globally, you can set it locally for the current Git repository like this:<br />
</translate><br />
git config user.name "YOUR NAME"<br />
git config user.email "GITHUB_USERNAME@users.noreply.github.com"<br />
<translate><br />
<!--T:19--><br />
You can now use some combination of "'''git add'''" and "'''git commit'''" commands to create one or more <br />
commits in your local repository.<br />
<br />
==== A note about Remotes ==== <!--T:39--><br />
Please read some [https://stackoverflow.com/questions/9257533/what-is-the-difference-between-origin-and-upstream-on-github#9257901 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. <br />
Essentially: <br />
* '''<code>origin</code>''' = Your fork of the FreeCAD git repo AKA https://github.com/GITHUB_USERNAME/FreeCAD.git<br />
* '''<code>upstream</code>''' = The official FreeCAD git repo AKA https://github.com/FreeCAD/FreeCAD.git<br />
*: '''This is important to understand because if you <code>git clone</code> directly from <code>upstream</code> then <u>confusingly</u>, your origin will be listed as''' https://github.com/FreeCAD/FreeCAD.git <br/>BTW, if you do this accidentally you can use the '''<code>git remote rename</code>''' command to remedy the situation.<br />
So, based on the above, there are 2 main ways to setup your git environment:<br />
* [[Source_code_management#Clone_Official_FreeCAD_git_repo_to_your_local_machine|1st Method: Fork on GitHub and clone your fork locally]]<br />
* [[Source_code_management#Clone_Official_FreeCAD_git_repo_to_your_local_machine|2nd Method: Clone FreeCAD official directly to your local machine]]<br />
We recommend the 1st method for the reason mentioned above.<br />
<br />
<div class="mw-collapsible mw-collapsed toccolours"><br />
==== 1st Method: Fork on GitHub and clone your fork locally ==== <!--T:40--><br />
<div class="mw-collapsible-content"><br />
{{Note|Important Note|You will need to re-configure 'remote upstream' as mentioned above in "[[Source_code_management#A_note_about_Remotes|A note about Remotes]]"}}<br />
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:<br />
<ol><br />
<li>[https://github.com/join Sign up] for a GitHub account if you don't already have one </li><br />
<li>Go to the FreeCAD repo: https://github.com/FreeCAD/FreeCAD</li><br />
<li>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) </li><br />
<li>On your machine, clone your newly created FreeCAD fork by opening a terminal and typing:<br />
<pre>git clone https://github.com/GITHUB_USERNAME/FreeCAD.git</pre></li><br />
<li>Once the clone process is complete, now set your '''<code>upstream</code>''' remote repo (see "[[Source_code_management#A_note_about_Remotes|A note about Remotes]]"). Find out what and where your remote git repositories are set to. Type '''<code>git remote -v</code>''' and the output should look similar to:<br />
<pre> [foo@bar FreeCAD]$ git remote -v<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (fetch)<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (push)</pre></li><br />
<li>Great. Now set your '''<code>upstream</code>''' repo<br />
<pre>[foo@bar FreeCAD]$ git remote add upstream https://github.com/FreeCAD/FreeCAD.git</pre></li><br />
<li>Check your remotes again, they should look similiar to this:<br />
<pre> [foo@bar FreeCAD]$ git remote -v<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (fetch)<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (push)<br />
upstream https://github.com/FreeCAD/FreeCAD.git (fetch)<br />
upstream https://github.com/FreeCAD/FreeCAD.git (push)</pre></li><br />
</li><br />
<li>Now we can start developing. Please refer to "[[Source_code_management#Git_Development_Process|Git Development Process]]"</li><br />
</ol><br />
</div></div><br />
<br />
<div class="mw-collapsible mw-collapsed toccolours"><br />
==== 2nd Method: Clone Official FreeCAD git repo to your local machine ==== <!--T:7--><br />
<div class="mw-collapsible-content"><br />
{{Note|Important Note|You will need to re-configure both 'remote origin' and 'remote upstream' please refer to above "[[Source_code_management#A_note_about_Remotes|A note about Remotes]]"}}<br />
This method of setuping your git environment takes a few more steps then the 1st method. You will clone the FC git repo directly to your local machine and then alter your remotes via the terminal. The procedure is as follows:<br />
<ol><br />
<li>Clone the FreeCAD code with git: <br />
<pre>git clone https://github.com/FreeCAD/FreeCAD.git</pre></li><br />
<li>Create an account on a public git server (GitHub, GitLab, etc... for our purposes we're assuming it's GitHub)</li> <br />
<li>Find out what and where your remote git repositories are set to:<br />
<pre>git remote -v</pre></li><br />
<li>This will return something that looks like the following:<br />
<pre>[foo@bar FreeCAD]$ git remote -v<br />
origin https://github.com/FreeCAD/FreeCAD.git (fetch)<br />
origin https://github.com/FreeCAD/FreeCAD.git (push)</pre></li><br />
<li>As was explained above in "[[Source_code_management#A_note_about_Remotes|A note about Remotes]]" you need to modify these remote git repo addresses.<br /> <br />
So first set up your '''<code>origin</code>''' remote:<br />
<pre>[foo@bar FreeCAD]$ git remote add origin https://github.com/GITHUB_USERNAME/FreeCAD.git</pre></li><br />
<li>Then we set up our '''<code>upstream</code>''' remote:<br />
<pre>[foo@bar FreeCAD]$ git remote add upstream https://github.com/FreeCAD/FreeCAD.git</pre></li><br />
<li>Check your remotes again, they should look similiar to this:<br />
<pre> [foo@bar FreeCAD]$ git remote -v<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (fetch)<br />
origin https://github.com/GITHUB_USERNAME/FreeCAD.git (push)<br />
upstream https://github.com/FreeCAD/FreeCAD.git (fetch)<br />
upstream https://github.com/FreeCAD/FreeCAD.git (push)</pre></li><br />
<li>Now we can start developing. Please refer to "[[Source_code_management#Git_Development_Process|Git Development Process]]"</li><br />
</ol><br />
</div></div><br />
<br />
== Git Development Process == <!--T:23--><br />
First of all '''NEVER DEVELOP ON THE ''master'' BRANCH!''' <br />
Instead, create a local branch for development. You can learn in more depth by reading [https://book.git-scm.com/book/en/v2/Git-Branching-Basic-Branching-and-Merging Git-Branching-Basic-Branching-and-Merging chapter on git-scm]. Below is a summary:<br />
<br />
=== Branching === <!--T:24--><br />
An important feature of Git is that it is extremely easy to work with branches and merge <br />
them together. Best practices recommend to create a new branch whenever you want to work <br />
on a new feature. Creating a branch is done with:<br />
</translate><br />
git branch myNewBranch<br />
git checkout myNewBranch<br />
<translate><br />
<!--T:25--><br />
or you can combine both git branch && git checkout together by using the ''-b'' flag<br />
</translate><br />
git checkout -b myNewBranch<br />
<translate><br />
<!--T:26--><br />
How do you know which branch you are currently using? Easy, type:<br />
</translate><br />
git branch<br />
<translate><br />
<br />
=== Committing === <!--T:27--><br />
Once you did some work, you commit them with:<br />
</translate><br />
<pre>git commit -a</pre><br />
<translate><br />
<!--T:28--><br />
Unlike SVN, you need to specifically tell which files to commit (or all with the <br />
-a option). Your text editor will open to allow you to write a commit message.<br /><br />
Please read more about [[Source_code_management#Writing_good_commit_messages|Writing good commit messages]] in the below section.<br />
<br />
=== Publishing your work on your GitHub repository=== <!--T:29--><br />
{{Note|Important Note|If you have code you wish to see merged into the FreeCAD source code, please post a note in the Pull Request section of the FreeCAD forum}}<br />
After you're correctly branched made some modifications to your local branch and commit them 'locally', you can push your repository to your remote git server (in this example we're assuming GitHub). This opens your branch to the public and allows the main developers to review and integrate your branch into ''master''. <br />
</translate><br />
git push <REMOTENAME> <BRANCHNAME> <br />
git push origin my-branch<br />
<translate><br />
<!--T:41--><br />
<small>For further info on this subject please read https://help.github.com/articles/pushing-to-a-remote/</small><br />
<br />
=== Writing good commit messages === <!--T:31--><br />
You should try to work in small chunks. If you cannot summarize your changes in one <br />
sentence, then it has probably been too long since you have made a commit. It is also <br />
important that you have helpful and useful descriptions of your work. For commit messages, <br />
FreeCAD has adopted a format mentioned in book Pro Git (see [[#Further Reading]]).<br />
<br />
<!--T:32--><br />
Short (50 chars or less) summary of changes<br />
<br />
More detailed explanatory text, if necessary. Wrap it to about 72<br />
characters or so. In some contexts, the first line is treated as the<br />
subject of an email and the rest of the text as the body. The blank<br />
line separating the summary from the body is critical (unless you omit<br />
the body entirely); tools like rebase can get confused if you run the<br />
two together.<br />
<br />
Further paragraphs come after blank lines. <br />
<br />
- Bullet points are okay, too<br />
<br />
- Typically a hyphen or asterisk is used for the bullet, preceded by a<br />
single space, with blank lines in between, but conventions vary here<br />
<br />
<!--T:33--><br />
If you are doing a lot of related work, it has been suggested <br />
[http://forum.freecadweb.org/viewtopic.php?f=10&t=2062&p=14887#p14886 here] <br />
that one should make as many commits large or small as makes sense for what you are working <br />
on using the short one sentence commit messages. When you want to merge, do a<br />
<pre>git log master..BRANCH</pre> <br />
and use the output as a basis for your quality commit message. <br />
Then when you merge to master use the --squash option and commit with your quality commit message. <br />
This will allow you to be very liberal with your commits and help to provide a good level of detail <br />
in commit messages without so many distinct descriptions.<br />
<br />
== Advanced git operations == <!--T:42--><br />
=== Resolving Merge Conflicts ===<br />
* [https://git-scm.com/docs/git-merge#_how_conflicts_are_presented git-scm explanation on how conflicts are presented] <br />
* [https://help.github.com/articles/resolving-a-merge-conflict-using-the-command-line/ GitHub article on resolving merge conflicts via the command-line]<br />
* [https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration#_external_merge_tools Customize your preferred merge tool] when you encounter a git conflict.<br />
<br />
=== Applying patches via git === <!--T:43--><br />
Git has the capability to merge patches/diffs. To read more about this read the following reference: https://www.drupal.org/node/1399218<br />
git apply [patch-name].patch<br />
<br />
==== Apply a patch via curl ==== <!--T:47--><br />
A very handy and powerful feature of git and the command line is the ability to quickly test patches all through the terminal.<br />
curl -O https://github.com/FreeCAD/FreeCAD/commit/[patch-name].patch<br />
git apply [patch-name].patch<br />
or alternatively, using bash pipes you can make a sweet 1-liner:<br />
curl https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.patch | git apply -<br />
<br />
<!--T:52--><br />
* 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:<br />
::Regular GitHub page: <small>https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621</small><br />
::'Diffed' GitHub page: <small>https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.diff</small><br />
::'Patched' GitHub page: <small>https://github.com/FreeCAD/FreeCAD/commit/c476589652a0f67b544735740e20ff702e8d0621.patch</small><br />
<br />
=== Creating patches from git === <!--T:49--><br />
There are times when one may need to create a patch instead of submitting a PR. The following workflow explains how to do this:<br />
<ol><br />
<li>Make sure you are in the correct branch (i.e. not the master branch) by checking with<br />
<pre>git branch -v</pre></li> <br />
<li>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)<br />
<pre>git format-patch master --stdout > ../patch.name.patch</pre></li><br />
<li>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.<br />
<pre>git format-patch HEAD^</pre></li> It will create a patch or series of patches with file name format XXXX-commit-message.patch. An example: 0001-fix-ViewProjMatrix-getProjectionMatrix.patch<br />
<br />
<!--T:55--><br />
</ol><br />
<br />
=== Reversing a patch in git === <!--T:53--><br />
If you've followed the instructions above and then have a change of heart about using the patch, you can quickly reverse it using:<br />
git apply -R path/file.patch<br />
or another way is to use: <br />
git checkout -f<br />
which will remove non-committed changes to the branch<br />
<br />
== Stashing git commits == <!--T:54--><br />
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. <br />
git stash<br />
Then in the future when you want to use these commits you can <br />
git stash apply <br />
or <br />
git stash pop<br />
'''pop''' will delete the stash <br />
If you have multiple stashes you can <br />
git stash list<br />
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<br />
<br />
== What is the latest FreeCAD Dev Revision == <!--T:48--><br />
There are 2 ways to do this:<br />
* 1st method: In your cloned git directory type: <br />
git rev-list --count master<br />
* 2nd method: Browse https://github.com/FreeCAD/FreeCAD and read the amount of commits FreeCAD is at.<br />
<br />
<br />
== What is the Revision number of a specific commit hash and visa ver? == <!--T:50--><br />
git rev-list --count 9948ee4<br />
13541<br />
<br />
<!--T:56--><br />
* some forum topics in this regard:<br />
** https://forum.freecadweb.org/viewtopic.php?f=10&t=26673<br />
** https://forum.freecadweb.org/viewtopic.php?t=5308<br />
** https://forum.freecadweb.org/viewtopic.php?f=18&t=12883&p=103207#p103203<br />
** https://forum.freecadweb.org/viewtopic.php?f=10&t=31118<br />
<br />
== How is the Revision number in FreeCAD help about generated? == <!--T:51--><br />
* https://forum.freecadweb.org/viewtopic.php?f=4&t=3025<br />
<br />
== Alternative repositories == <!--T:20--><br />
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.<br />
<br />
<!--T:21--><br />
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.<br />
<br />
<!--T:22--><br />
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.<br />
<br />
== Using git in a Graphical User Interface == <!--T:44--><br />
* [[Developing FreeCAD with GitKraken]]<br />
<br />
== Further reading == <!--T:34--><br />
<br />
<!--T:35--><br />
* [https://wiki.spheredev.org/index.php/Git_for_the_lazy Git for the lazy]<br />
* [https://git-scm.com/book The entire Pro Git book]<br />
<br />
<!--T:36--><br />
[[Category:Hubs]]<br />
[[Category:Developer Documentation]]<br />
<br />
</translate><br />
{{clear}}</div>Opushttps://wiki.freecad.org/index.php?title=Licence&diff=316999Licence2018-08-27T14:27:10Z<p>Opus: Wrong link to CC license</p>
<hr />
<div><languages/><br />
<translate><br />
== Licences used in FreeCAD == <!--T:5--><br />
<br />
<!--T:19--><br />
FreeCAD uses two different licenses, one for the application itself, and one for the documentation:<br />
<br />
<!--T:6--><br />
'''[[wikipedia:LGPL|Lesser General Public Licence, version 2 or superior (LGPL2+)]]''' For all of the FreeCAD source code found in the [https://github.com/FreeCAD/FreeCAD official Git repository]<br />
<br />
<!--T:22--><br />
'''[http://creativecommons.org/licenses/by/3.0/ Creative Commons Attribution 3.0 License (CC-BY-3.0)]''' For the documentation on http://www.freecadweb.org<br />
<br />
<!--T:7--><br />
See FreeCAD's [https://github.com/FreeCAD/FreeCAD/blob/master/package/debian/copyright debian copyright file] for more details about the licenses used by the different open-source components used in FreeCAD<br />
<br />
== Impact of the licences == <!--T:12--><br />
<br />
<!--T:23--><br />
Below is a friendlier explanation of what the LGPL license means for you:<br />
<br />
==== All users ==== <!--T:13--><br />
Anybody can download, use and redistribute FreeCAD free of charge, without any restriction. Your copy of FreeCAD is truly yours, as are the files you produce with FreeCAD. You will not be forced to update FreeCAD after a certain time, nor change your usage of FreeCAD. Using FreeCAD doesn't bind you to any kind of contract or obligation. The FreeCAD source code is public and can be inspected, so it is possible to verify that it doesn't do things without your knowledge such as sending your private data somewhere.<br />
<br />
==== Professional users ==== <!--T:14--><br />
FreeCAD can be used freely for any kind of purpose, being private, commercial or institutional. Any version of FreeCAD can be deployed and installed anywhere, any number of times. You can also modify and adapt FreeCAD for your own purposes without any restriction. However, you cannot make the FreeCAD developers liable for possible damage or business loss that could occur from using FreeCAD.<br />
<br />
==== Open-source software developers ==== <!--T:15--><br />
You can use FreeCAD as a base to develop your own application, or simply extend it by creating new modules for it. If FreeCAD is embedded into your own application, you can choose either the GPL or the LGPL license, or any other license that is compatible with LGPL, to allow the use of your work in proprietary software or not. If you are developing a module to be used as an extension, and don't include any of the FreeCAD code in it, then you can choose any license you want. However, if you wish to see your module used as much as possible, it is a good idea to use the same LGPL license as FreeCAD itself, so parts of your code can be more easily reused in other future modules or even in FreeCAD itself.<br />
<br />
==== Closed-source software developers ==== <!--T:16--><br />
You can use FreeCAD as a base for your own application, and are not forced to make your application open source. The LGPL license, however, ask for two basic things: 1) that you clearly inform your users that your application is using FreeCAD and that FreeCAD is LGPL-licensed, and 2) that you clearly separate your own application form the FreeCAD components. That is usually done by either dynamically linking to the FreeCAD components, so users are allowed to change it, or making the FreeCAD source code, along with the modifications you brought to it, available to your users. You will get support from the FreeCAD developers as long as it is not a one way street.<br />
<br />
==== Files ==== <!--T:24--><br />
The models and other files produced with FreeCAD are not subject to any license stated above, nor bound to any kind of restriction or ownership. Your files are truly yours. You can set the owner of the file and specify your own license terms for the files you produce inside FreeCAD, via menu File -> Project Information.<br />
<br />
== Statement of the main developer == <!--T:1--><br />
I know that the discussion on the ''"right"'' licence for open source occupied a significant portion of internet bandwidth and so is here the reason why, in my opinion, FreeCAD should have this one.<br />
<br />
<!--T:2--><br />
I chose the [http://en.wikipedia.org/wiki/LGPL LGPL] for the project and I know the pro and cons about the LGPL and will give you some reasons for that decision.<br />
<br />
<!--T:3--><br />
FreeCAD is a mixture of a library and an application, so the GPL would be a little bit strong for that. It would prevent writing commercial modules for FreeCAD because it would prevent linking with the FreeCAD base libs. You may ask why commercial modules at all? Therefore Linux is good example. Would Linux be so successful when the GNU C Library would be GPL and therefore prevent linking against non-GPL applications? And although I love the freedom of Linux, I also want to be able to use the very good NVIDIA 3D graphic driver. I understand and accept the reason NVIDIA does not wish to give away driver code. We all work for companies and need payment or at least food. So for me, a coexistence of open source and closed source software is not a bad thing, when it obeys the rules of the LGPL. I would like to see someone writing a Catia import/export processor for FreeCAD and distribute it for free or for some money. I don't like to force him to give away more than he wants to. That wouldn't be good neither for him nor for FreeCAD.<br />
<br />
<!--T:4--><br />
Nevertheless this decision is made only for the core system of FreeCAD. Every writer of an application module may make his own decision.<br />
<br />
<!--T:17--><br />
{{docnav|Dialog creation|Tracker}}<br />
<br />
<!--T:18--><br />
[[Category:Developer Documentation]]<br />
<br />
</translate><br />
{{clear}}</div>Opus