top of page
Search
alexanderskoglund

How to use git and KiCad when cooperating

Updated: Oct 28, 2022

What to do when your customer doesn't use version control; how you can use git and shell scripts to automatize import sequence

For version control I use git; a tool that has become industry standard for software development. I stated using it sometime around 2010 when I first came in contact with github.com and have been using ever since. However, not everybody is using a version control tool, not in electronics and not if you are old enough to have developed the habit for "save as..." as you preferred version control tool. In my experience, experienced (i.e., older) electronics engineers quite often fall into this category. So here are some tricks to help you when you are interacting with a colleague of customer who does not use a proper version control. Here I will assume you use git, KiCad and a Linux terminal. Another assumption is that you where not thoughtful from start (just like me) and realized that the method of working will deteriorate if you don't take action; i.e., some post processing is needed.


Step #1 - You receive an email


You receive an email with a zip file named my_project-2022-09-10.zip When you extract the zip file you get a folder "my_project-2022-09-10" with the files:

Step #2 - Before you start


Before you start, set up your own git repository; e.g., where you keep everything from your customer:

> mkdir my_customer_ecad
> cd my_customer_ecad
> git init

Now, you have a git repo called 'my_customer_ecad'


Step #3 - Your colleague or client uses white-spcaces


Note that the files names contains white-space, as users of some operating system are fond of. Before you start, set up your own git repository; e.g., where you keep everything from your customer: Then copy the unzipped file to the git location:


> cp zipfile_location/my_project-2022-09-10/* .

(This will omit the backup files in the folder: 'my-proj 2022-02-16-backups') First we need to handle the white-space problem, create a script file by:

> echo "for f in *\ *; do mv "$f" "${f// /_}"; done" >> remove_ws.sh

Change permissions, to run:

> chmod +x remove_ws.sh

Now, you have a script which replaces white-space with underscore. Run it:

> ./remove_ws.sh

And you have a nice clean folder.


Step #4 - Make in import script

Now, one of the most important steps; put the following in a script file and call in import.sh:

echo "Input file name: $1";
echo "Ouput file name: $2";

for f in $1.*; do
    echo "$f  $2.${f##*.}"
    mv -- "$f" "$2.${f##*.}"
done

echo "Done";

The above script will rename your colleague's date in the file name. Change permissions, to run:

> chmod +x import.sh

and the run it with:

> ./import.sh my-proj_2022-02-16 my-proj

This script command takes two arguments: 1) input file names "my-project_20220-02016"and 2) output file names "my-project", so you will get the files:

my-proj.kicad_prl
my-proj.kicad_sch
my-proj.kicad_pcb
my-proj.kicad_pro

Step #5 - Add it to git


Add these files to your git repository, in our example:

> git add my-proj.kicad_pro
> git add my-proj.kicad_sch
> git add my-proj.kicad_pcb

The kicad_prl you don't need. Next, commit it:

> git add -am"Add my project"

Now, as I wrote above we need to edit the commit date for two several reasons: 1) we do this organization in retrospect, 2) the dates in the folder doesn't match 3) the filenames.

> git commit --amend --no-edit --date "2022-09-10"

Assuming that 2022-09-10 was actually the correct date. Last, we also add the author and email by:

> git commit --amend --no-edit --author "Joe Customer" --email joe.cutomer@oldies.net

So, we know who was responsible for this change. Now you have a git repo with the first version of the files.


Step #6 - Automatize it!


Going one step further, we will automate the process a bit more. Modify the import script from before:

echo "Input file name: $1";

for f in $1.*; do
    echo "$f  my-proj.${f##*.}"
    mv -- "$f" "my-proj.${f##*.}"
done

git commit -am$2
git commit --amend --no-edit --date "$3" --author "Joe Customer <joe.cutomer@oldies.net>"

echo "Done";

Note that this will become a bit different than the first; so re-name it: import_my-proj.sh Change permissions, to run:

> chmod +x import_my-proj.sh

The next time you receive an email from your client with my_project-2022-12-30.zip, you unzipped it and see a folder called "my_project-2022-12-30" with the files:

'my-proj 2022-11-16-backups'
'my-proj 2022-11-16.kicad_prl'
'my-proj 2022-11-16.kicad_sch'
'my-proj 2022-11-16.kicad_pcb'
'my-proj 2022-11-16.kicad_pro'
fp-info-cache

Then you do the following "dance":

Then copy the unzipped file to the git location:

> cp zipfile_location/my_project-2022-12-30/* .

Replace white-spaces with underscores:

> ./remove_ws.sh

And last "import":

> ./import_my-proj.sh my-proj_2022-11-16 "Git commit message" 2022-12-30

and you are done!



18 views0 comments

Recent Posts

See All

Comentarios


Post: Blog2_Post
bottom of page