This page is a collection of tips for how to begin as a Developer working on FreeSWITCH.
Developers must first install git: http://git-scm.com/book/en/Getting-Started-Installing-Git
Our https now requires TLS1.2. If your distro does not support this, please report this problem to them. As an alternative you can use ssh to check out packages and code with a JIRA account.
Git https and Behind Proxy
If for any reason you can't reach https://stash.freeswitch.org/ (e.g. you are behind corporate firewalls or proxy) you could use the github mirror like this:
Then you could set your proxy like this:
and it should work:
For most developers, you can get the latest code by changing to your working source code directory, then:
If you only want to obtain the current release branch use:
or more simply:
The contrib area can be downloaded with:
Read and Write
To have commit privileges, you need an ssh public key. You load this key into your Stash Account Profile so that write permissions can be added.
Then, get the latest code with:
If you are in a location where SSH is blocked, or you wish to use HTTPS:
After you check out the code, git needs to be configured for the FreeSWITCH project:
Syncing with Trunk
As the main trunk is undergoing lots of changes, you may from time to time want to pull changes from trunk into your local copy. This can allow you to pull in bug fixes, feature enhancements, etc. This is important in making certain that any of your changes remain compatible with the main trunk.
Applying a Pull Request to Your Local Repository
You may receive a request from someone to try some changes that they've made to the system. They will usually have a repository available somewhere with a branch containing the changes and provide the branch name and URL to you. This is known as a Pull Request (in industry lingo), and the branch in which they made the changes is known as a Topic Branch.
For example, if they forked the code on Stash, they may provide you a URL like git://stash.freeswitch.org/username/FreeSWITCH.git ; with that URL and the name of the branch you can easily pull their changes. The best way to do this is to make a local topic branch to which to apply these changes. That way you can easily delete the branch and switch back to master if you don't like the changes.
Create a local branch and switch to it:
Pull the changes from the user's topic branch into yours:
Your local working set will now match the other user's, and you can now build and test the changes. There are two possible paths to continue from here:
- you didn't like the changes and want to get rid of the new branch;
- or you liked the changes and want to push them to the main repository.
Delete Pulled Branch
To delete your local branch just switch back to master and then delete the topic branch:
Push to Master
If you like the changes you can merge them to your local master branch and then push them to the public repository:
Github has put a nice website up around the pull request workflow that makes it very simple for a contributor to initiate the request, and for others to see the changes that have been made, and make comments on those changes without ever having to pull the changes to their local repository.
There are a few shortcuts you can take if the user has sent a pull request via Github. The pull request URL itself can be used to obtain a patch and apply it to your local master branch and push the changes with two easy commands. If the pull request URL is https://github.com/FreeSWITCH/FreeSWITCH/pull/2 simply append .patch to the URL to get a patch file. We can use curl to grab the patch and push it directly into our local repository with the git am command.
Add your changes to your staging area:
Diff your changes with your local repository:
Commit the changes in your staging area to your local repository:
Diff your changes with the FreeSWITCH remote repository:
Push changes to FreeSWITCH remote repository (requires write access):
Git Bisect - Tracking Down Breaks and Bugs Extremely Rapidly With git
If something was working or behaving correctly before, but is not any more git has a great tool called bisect which can help find the issue with a binary tree search to find where it broke.
The syntax is:
Where bad_commit is a commit that is known to be bad (i.e. HEAD) and good_commit is a commit that was known to work. Optionally, you can specify only a specific sub path (i.e. lib/) where it broke and then it will only look at commits that affected that path or other paths. Here's an example of finding something that broke within the last 10 commits:
Once you do that you are now in bisect mode. You want to compile and test to try to reproduce the bug. Once you know if that version works or not just tell git with:
then it will move on to the next commit for you to test. If you cannot figure out if it was bad or good use 'git bisect skip' to move on to the next commit. Once it figures out what commit (or commits) would be possible to blame it will let you know. The great part is that it is far quicker than trying to do it by hand. Let's say in a worst case scenario you only know it worked 6 months ago and now its broken and there are 1000 commits in between then and now. You would in the worst case only have to test 11 different builds.
When you are done you can use:
to reset back to where you were.
In addition git bisect can find the place that it first broke on its own. If you have a script that can return if it works or doesn't work you can use:
Note that the script (my_script in the above example) should exit with code 0 if the current source code is good, and exit with a code between 1 and 127 (inclusive), except 125, if the current source code is bad.
Then you do not need to do any testing by yourself just let git find the problem commit. Once you know the problem commit there is a far higher chance your bug report will be handled faster when you can tell the developers exactly where to work.
If You Change Code You Should Branch with Git
Git is not like most other source control systems: branching is actually so easy that the recommended method of making feature changes is generally to branch. Branching allows you to make changes and commit them locally even though you most likely cannot commit them directly to FreeSWITCH Master. This also allows you more easily to preserve your changes as you upgrade FreeSWITCH. If you branch for each feature or fix you try to add to FreeSWITCH it makes submitting and updating patches far easier. Branching takes two seconds. Just run:
so for example:
will create a new branch from master for your work. You can switch to a branch by doing:
So git checkout master will change you back to master or git checkout codec_g729_windows will change to your branch. You do not need to commit your changes before changing branches, it will save your place automatically. To update a branch after you do a git pull on master you would run:
In your branch, most of the time git will figure out the proper merging for you without intervention.
Creating Patches with Git
Even though most FreeSWITCH users do not have commit access to the FreeSWITCH git server you should still be working in branches and committing locally changes you make. Users can then get their changes integrated into FreeSWITCH by filing Jira tickets with patches of the changes. To generate a patch for a commit of your work you would do:
You can get commit ids by looking at the "git log" or using tags. You can also just tell it to generate patches for the last 3 commits by:
This can then be attached to a ticket. Aside from the benefits of a normal patch, a formatted patch also will give you attribution as the one who fixed it and includes some additional information to help with git merging.
Checking Out Previous Revisions
To list commits cd to where you have cloned the git repo and type:
The change log is also available on Fisheye.
Then to switch to that commit do:
then, if you want to go back to the master:
Note that if the revision you are trying to switch to is newer than your clone then you will need to first bring your clone up to date:
Cleaning Out Previous Revisions
Michal Bielicki: that will kill everything that is not from the current git
When making large jumps between revisions you'll need to clean your old libs and mods to avoid errors like this:
To fix this just run:
GUIs and Utilities
There are a couple user interfaces to Git available with the Git suite. These GUIs require the tcl/tk toolkits installed.
Portable graphical interface to Git. See the git-gui(1) man page.
The git repository browser. See the gitk(1) man page.
Other Cool Tools
- tig - Curses-based text GUI for git
- magit - emacs addon for git. Travis Cross says it is beyond cool!
- The Git website: http://git-scm.com/
- Git cheat sheet: http://cheat.errtheblog.com/s/git
- Git from the bottom up, very nice Git intro: http://www.newartisans.com/2008/04/git-from-the-bottom-up.html (pdf first link, second paragraph)
- Pro Git, a book on using Git that is freely available online: http://progit.org/
- Git Model: http://nvie.com/git-model
- Developer Documentation
- git commit guidelines — Essential instructions to follow before you commit your patches to the FreeSWITCH tree