{"id":362,"date":"2022-01-12T22:59:17","date_gmt":"2022-01-12T21:59:17","guid":{"rendered":"https:\/\/ca.rstenpresser.de\/blag\/?p=362"},"modified":"2022-01-12T23:56:57","modified_gmt":"2022-01-12T22:56:57","slug":"contributing-to-the-kicad-library-using-gitlab-and-git","status":"publish","type":"post","link":"https:\/\/ca.rstenpresser.de\/blag\/2022\/01\/contributing-to-the-kicad-library-using-gitlab-and-git\/","title":{"rendered":"Contributing to the Kicad-library using gitlab and git"},"content":{"rendered":"\n<p>For some people it is rather easy to fix bugs in symbols, or create some new footprints. But the actual contributing step requires some working knowledge of git. As always with git, there are lots of different ways to reach the same goal. I will write down my preferred way, together with some explanations on why and how we do this. This post will only cover schematic symbols since the workflow for footprints or 3D-Models is identical.<\/p>\n\n\n\n<p>Not everything is covered in this blog post, for example, the generation of a gitlab user account and its setup are out of scope. Here are a few resource to read up:<\/p>\n\n\n\n<ul><li><a href=\"https:\/\/docs.gitlab.com\/ee\/gitlab-basics\/start-using-git.html\">Using git on the commandline<\/a><\/li><li><a href=\"https:\/\/docs.gitlab.com\/ee\/ssh\/\">Setting up ssh<\/a><\/li><li><a href=\"https:\/\/about.gitlab.com\/blog\/2016\/12\/08\/git-tips-and-tricks\/#add-an-alias-to-checkout-merge-requests-locally\">Useful git alias for fetching merge-requests for review<\/a><\/li><\/ul>\n\n\n\n<p class=\"has-large-font-size\" id=\"own_the_libs\">Get the library<\/p>\n\n\n\n<p>On a typical kicad install, there are also symbol- and footprint-libraries installed. On a linux system they are read-only, so we can&#8217;t edit them. On windows we can change the files, but they might not be up to date with the latest version on gitlab (where all library development takes place). So what we want to do is <strong>clone<\/strong> the official repository and work with those symbols.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/home\/cpresser\/Documents\/KiCad\/\ngit clone git@gitlab.com:kicad\/libraries\/kicad-symbols.git<\/code><\/pre>\n\n\n\n<p>We also need to setup a fork of the symbols-library on gitlab where we can publish our changes. This can be done on the gitlab webpage by pressing the &#8216;fork&#8217; button in the top right on the project page (https:\/\/gitlab.com\/kicad\/libraries\/kicad-symbols\/). Next we need to add this repository as a second <strong>remote<\/strong> to our local git repository.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git remote add cpresser git@gitlab.com:cpresser\/kicad-symbols.git<\/code><\/pre>\n\n\n\n<p class=\"has-large-font-size\" id=\"setup_kicad\">Setup Kicad to use the git library<\/p>\n\n\n\n<p>Next we want that Kicad also uses the library we just cloned. Depending on the operating system you are using, or even the package, there might be differences.  On my system, I had to do two things.<\/p>\n\n\n\n<p>1. Set the path to the library in Kicad, go to Preferences-&gt;Paths<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"626\" height=\"258\" src=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-1.png\" alt=\"\" class=\"wp-image-364\" srcset=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-1.png 626w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-1-300x124.png 300w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/figure>\n\n\n\n<p>2. Use the <strong>sym-lib-table<\/strong> from git. It resides in the <a href=\"https:\/\/forum.kicad.info\/t\/where-are-the-configuration-files-settings-library-tables\/17701\">config folder<\/a>. So on my system I did the following:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd \/home\/cpresser\/.config\/kicad\/6.0\nmv sym-lib-table sym-lib-table.old\nln -s \/home\/cpresser\/Documents\/KiCad\/kicad-symbols\/sym-lib-table .<\/code><\/pre>\n\n\n\n<p>3. Verify that its working. Open Kicad, go to the symbol editor and make some change, e.g. add a text to the default capacitor symbol in the Device library. After that, type <strong>git status<\/strong> and it should look something like this.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"743\" height=\"191\" src=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-2.png\" alt=\"\" class=\"wp-image-365\" srcset=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-2.png 743w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-2-300x77.png 300w\" sizes=\"(max-width: 743px) 100vw, 743px\" \/><\/figure>\n\n\n\n<p>Since that was a useless change, just as a test, undo it with <strong>git restore Device.kicad_sym<\/strong>. Now you are set up do do library work. Yay!<\/p>\n\n\n\n<p class=\"has-large-font-size\" id=\"add_symbol_and_open_mr\">Adding a symbol and opening a MR<\/p>\n\n\n\n<p>Now the setup is complete, we can do some actual work. Lets assume we want to add a new symbol for a Lattice FPGA. In this case, just head over to the library editor inside Kicad and create a new symbol. When done, head back to the command line and type <strong>git diff <\/strong>so see if there are the changes you expect:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"885\" height=\"874\" src=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-3.png\" alt=\"\" class=\"wp-image-367\" srcset=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-3.png 885w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-3-300x296.png 300w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-3-768x758.png 768w\" sizes=\"(max-width: 885px) 100vw, 885px\" \/><\/figure>\n\n\n\n<p>This looks good, there is exactly one hunk (= a group of changed lines) that correspond to the symbol we created in the editor. To upstream this, we need to do a few steps:<\/p>\n\n\n\n<ol><li>Create a new (local) branch<\/li><li>Commit our changes to that branch and write a good commit message<\/li><li>Push that branch to our own fork on gitlab<\/li><\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout -b Add_fake_Lattice_FPGA\ngit add -p\ngit commit\ngit push cpresser Add_fake_Lattice_FPGA<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"211\" src=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-4-1024x211.png\" alt=\"\" class=\"wp-image-368\" srcset=\"https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-4-1024x211.png 1024w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-4-300x62.png 300w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-4-768x158.png 768w, https:\/\/ca.rstenpresser.de\/wp-files\/2022\/01\/image-4.png 1288w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>4. Create a merge request, just use the provided link<\/p>\n\n\n\n<p>Make sure to fill out the merge request template to the best of you knowledge. And please don&#8217;t uncheck the &#8220;<strong>Allow commits from members who can merge to the target branch<\/strong>&#8221; checkbox. It make take some time until a librarian makes a review of you contribution, we are only volunteers and short staffed. <\/p>\n\n\n\n<p>You can repeat this process for every contribution. Make a new branch with a descriptive name for each one. You can switch around different branches using the <strong>git branch &lt;branchname&gt;<\/strong> command.<\/p>\n\n\n\n<p>Once your contribution gets accepted it will get merged into the master branch. You can then safely delete your local branch with <strong>git branch -D &lt;branchname&gt;<\/strong>.<\/p>\n\n\n\n<p class=\"has-large-font-size\" id=\"adding_changes\">Adding changes<\/p>\n\n\n\n<p>In quite a few cases, the library maintainers will require you to do some changes during the review.  As a first step, you need to switch back to your local branch that corresponds to the MR. Next do the changes in the Kicad symbol editor, then head back to the command line to create a commit and push it. Your merge request will automatically get updated.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git checkout Add_fake_Lattice_FPGA\n# &lt;now do changes in kicad symbol editor&gt;\ngit add -p #(stage the changes for a commit)\ngit commit #(create a commit)\ngit push #(push that commit to the remote)<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>For some people it is rather easy to fix bugs in symbols, or create some new footprints. But the actual contributing step requires some working knowledge of git. As always with git, there are lots of different ways to reach the same goal. I will write down my preferred way, together with some explanations on &hellip; <a href=\"https:\/\/ca.rstenpresser.de\/blag\/2022\/01\/contributing-to-the-kicad-library-using-gitlab-and-git\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Contributing to the Kicad-library using gitlab and git<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":294,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[116],"tags":[159,158,156,157],"_links":{"self":[{"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/posts\/362"}],"collection":[{"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/comments?post=362"}],"version-history":[{"count":4,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/posts\/362\/revisions"}],"predecessor-version":[{"id":371,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/posts\/362\/revisions\/371"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/media\/294"}],"wp:attachment":[{"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/media?parent=362"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/categories?post=362"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ca.rstenpresser.de\/blag\/wp-json\/wp\/v2\/tags?post=362"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}