<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="../assets/xml/rss.xsl" media="all"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Just for Fun (Posts about Git)</title><link>https://devel.grys.it/</link><description></description><atom:link href="https://devel.grys.it/categories/git.xml" rel="self" type="application/rss+xml"></atom:link><language>en</language><copyright>Contents © 2024 &lt;a href="mailto:gian@grys.it"&gt;mgian&lt;/a&gt; </copyright><lastBuildDate>Fri, 11 Oct 2024 22:07:01 GMT</lastBuildDate><generator>Nikola (getnikola.com)</generator><docs>http://blogs.law.harvard.edu/tech/rss</docs><item><title>Some util git script</title><link>https://devel.grys.it/posts/some-util-git-script/</link><dc:creator>mgian</dc:creator><description>&lt;p&gt;So, at work we use a log Git, with many interdependant projects that (often) have some submodules. One of the problems we encounter sometimes is that we need
to create a new branch of a project but only of some of the submodules, or we need to branch a couple of projects to do the work. &lt;br&gt;
If the work is long enough, sometime you can lose track of which branch is which project. So in times I wrote some scripts to help myself. They are simple 
Bash script, probabily adaptable to other shells (Tcsh in in the work), and are something a little more advanced of an command alias.&lt;/p&gt;
&lt;p&gt;The main repository is on &lt;a href="https://codeberg.org/mgian/Git_utils_script"&gt;Codeberg&lt;/a&gt; and for now it has only the Bash version (since it what I currently use a work) but 
they should be easy enough to port them to other shells (Tcsh is planned).&lt;/p&gt;</description><category>Git</category><guid>https://devel.grys.it/posts/some-util-git-script/</guid><pubDate>Tue, 02 Jul 2024 12:40:06 GMT</pubDate></item><item><title>Merging git repositories</title><link>https://devel.grys.it/posts/merging-git-repositories/</link><dc:creator>mgian</dc:creator><description>&lt;p&gt;For a project, I decided that can be a good idea to merge a couple of repositories to have a single point where to put all the code, issues, wiki and so on.&lt;/p&gt;
&lt;p&gt;I later abandoned the idea, since it not came out as good as I was thinking, but in the end I have done it, so why not to share how to do it ?&lt;/p&gt;
&lt;p&gt;The main point was that I'd liked to not lose the commit history of the repos I was merging, so I should find some way to merge even these.&lt;/p&gt;
&lt;p&gt;Of course a simple copy of the code does not work, since you loose the commit history.&lt;br&gt;
Luckily git offer a way to do it anyway.&lt;/p&gt;
&lt;p&gt;The method I used, and later found in a lot of places so nothing new, is to decide which is the main repository where to add the others and then use the merge command.&lt;/p&gt;
&lt;p&gt;Assuming that &lt;code&gt;repoA&lt;/code&gt; is the main repository with a project caller &lt;code&gt;ProjectA&lt;/code&gt; and &lt;code&gt;repoB&lt;/code&gt; is the one I want to add with a project called &lt;code&gt;ProjectB&lt;/code&gt;, here is the command to use:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;git&lt;span class="w"&gt; &lt;/span&gt;remote&lt;span class="w"&gt; &lt;/span&gt;add&lt;span class="w"&gt; &lt;/span&gt;repoBRemote&lt;span class="w"&gt; &lt;/span&gt;repoBPath
git&lt;span class="w"&gt; &lt;/span&gt;fetch&lt;span class="w"&gt; &lt;/span&gt;repoBRemote
git&lt;span class="w"&gt; &lt;/span&gt;checkout&lt;span class="w"&gt; &lt;/span&gt;-b&lt;span class="w"&gt; &lt;/span&gt;ProjectB&lt;span class="w"&gt; &lt;/span&gt;repoB/master
mkdir&lt;span class="w"&gt; &lt;/span&gt;ProjectB
git&lt;span class="w"&gt; &lt;/span&gt;mv&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;everything&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;the&lt;span class="w"&gt; &lt;/span&gt;procject&lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;ProjectB
git&lt;span class="w"&gt; &lt;/span&gt;commit&lt;span class="w"&gt; &lt;/span&gt;-m&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;commit&lt;span class="w"&gt; &lt;/span&gt;message&lt;span class="o"&gt;]&lt;/span&gt;
git&lt;span class="w"&gt; &lt;/span&gt;checkout&lt;span class="w"&gt; &lt;/span&gt;master
git&lt;span class="w"&gt; &lt;/span&gt;merge&lt;span class="w"&gt; &lt;/span&gt;ProjectB
git&lt;span class="w"&gt; &lt;/span&gt;commit
git&lt;span class="w"&gt; &lt;/span&gt;push
git&lt;span class="w"&gt; &lt;/span&gt;remote&lt;span class="w"&gt; &lt;/span&gt;rm&lt;span class="w"&gt; &lt;/span&gt;repoBRemote
git&lt;span class="w"&gt; &lt;/span&gt;branch&lt;span class="w"&gt; &lt;/span&gt;-d&lt;span class="w"&gt; &lt;/span&gt;ProjectB
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The end result is a repository with this structure&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;|
|--- ProjectA
|       |...
|
|--- ProjectB
|       |...
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;and the commit history of both of them.&lt;/p&gt;</description><category>Git</category><guid>https://devel.grys.it/posts/merging-git-repositories/</guid><pubDate>Tue, 02 Feb 2021 21:47:42 GMT</pubDate></item><item><title>Making the MiniBookDB database public take 2</title><link>https://devel.grys.it/posts/making-the-minibookdb-database-public-take-2/</link><dc:creator>mgian</dc:creator><description>&lt;p&gt;In the quest to make the MiniBookDb database readable from outside my home network, I tried to use a microservice in Pythn/Flask.&lt;br&gt;
While the approach work, I had the problem that the same site name is resolved with different IP depending on where I am: on my private network the site name is resolved with an private IP, on the outside it is solved as a public IP.  &lt;/p&gt;
&lt;p&gt;&lt;em&gt;The probem&lt;/em&gt;&lt;br&gt;
On my private network, I also run the DNS, so that I can assign a specific IP to MiniBookDB on the Raspberry, so since the site is accessible with the same name both from outside and inside the private network, when the Raspberry call the microservice on the public server, in the end it call itself and fail.&lt;/p&gt;
&lt;p&gt;Since I don't want to use different site name, I had to let go the microservice and use another way.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The solution&lt;/em&gt;&lt;br&gt;
Remembering how I deploy this site (and the other one) I decide to use git and the old good cron, with some python magic.&lt;/p&gt;
&lt;p&gt;The pyhton magic is just a script that execute some simple actions:
- extract all the books from the MongoDB, selecting only the needed fields
- store them in a SQLite file
- generate the HTML files from the SQLite db
- commit them to a git repository&lt;/p&gt;
&lt;p&gt;Once the file are pushed to the git repository which is on the public server, an hook extract the HTML files and copy them in the correct directory where the site live.&lt;/p&gt;
&lt;p&gt;The operation is executed every day at midnight using a cron job on the Raspberry.&lt;/p&gt;
&lt;p&gt;All the sensible operations are done on the Raspberry, so inside my private network and I ditched also the need for authentication when calling the microservice, since it is handled by git using the usual ssh key.&lt;/p&gt;
&lt;p&gt;The hook on the server is pretty simple, copied and adapted from the one I use for this site.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The result&lt;/em&gt;&lt;br&gt;
After the initial problems in the tests, the system work very well. The only downside is that the public pages are update once a day, but that is acceptable.&lt;/p&gt;</description><category>Git</category><category>Python</category><guid>https://devel.grys.it/posts/making-the-minibookdb-database-public-take-2/</guid><pubDate>Wed, 20 Jan 2021 21:48:58 GMT</pubDate></item><item><title>Deploy Pelican blog with git on Linode</title><link>https://devel.grys.it/posts/deploy-pelican-blog-with-git-on-linode/</link><dc:creator>mgian</dc:creator><description>&lt;p&gt;Ok, now I have a new blog with Pelican on my pc, but how I can deploy it to my remote server on Linode ?&lt;/p&gt;
&lt;p&gt;Aside from the two ways already usable from the Makefile you have by default (ssh and rsync), it is possible to deploy also with Git.&lt;/p&gt;
&lt;h4&gt;Disclaimer&lt;/h4&gt;
&lt;p&gt;This mini-tutorial is not all mine, I got the informations from various sites and pages, and adapted it to my need. You can find a lot of similar solutions on the Web, many way older than mine. Additionally, I got inspired from the deployment of Hexo.io, another blog generator written in nodejs that I used some time ago, done with a git's hook.&lt;/p&gt;
&lt;h4&gt;Prerequisites&lt;/h4&gt;
&lt;p&gt;All you need is a working local Pelican blog, to install it you can follow the &lt;a href="https://docs.getpelican.com/en/stable/index.html"&gt;Pelican Documentation&lt;/a&gt; which explain really well how to do it.&lt;/p&gt;
&lt;p&gt;Another thing you need to have is a working Linode's linode with shell access and a working git installation. It is not really important how big.&lt;/p&gt;
&lt;h4&gt;Step 1&lt;/h4&gt;
&lt;p&gt;Access your server and create a git repository for your blog&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;mkdir -p /path/to/your/repo
cd /path/to/your/repo
git init --bare
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This create a bare Git repository that will not host any files but only the version control (see the git documentation for more info)&lt;/p&gt;
&lt;h4&gt;Step 2&lt;/h4&gt;
&lt;p&gt;In your repository create a hook caller &lt;code&gt;post-receive&lt;/code&gt; in the hooks directory of your repository&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="ch"&gt;#!/bin/bash -l&lt;/span&gt;
&lt;span class="nv"&gt;PATH&lt;/span&gt;&lt;span class="o"&gt;=[&lt;/span&gt;your_user_path&lt;span class="o"&gt;]&lt;/span&gt;
&lt;span class="nv"&gt;GIT_REPO&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/your/repo
&lt;span class="nv"&gt;TMP_GIT_CLONE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/tmp/git/your_repo_name
&lt;span class="nv"&gt;PUBLIC_WWW&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/path/to/your/web_root
git&lt;span class="w"&gt; &lt;/span&gt;clone&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$GIT_REPO&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$TMP_GIT_CLONE&lt;/span&gt;
cp&lt;span class="w"&gt; &lt;/span&gt;-a&lt;span class="w"&gt; &lt;/span&gt;TMP_GIT_CLONE/*&lt;span class="w"&gt; &lt;/span&gt;PUBLIC_WWW
rm&lt;span class="w"&gt; &lt;/span&gt;-Rf&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$TMP_GIT_CLONE&lt;/span&gt;
&lt;span class="nb"&gt;exit&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;h4&gt;Step 3&lt;/h4&gt;
&lt;p&gt;In your local Pelican directory, clone your git repository of your blog, with the usual git command &lt;code&gt;git clone [your_user]@your_serve:/path/to/your/repo output&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The output at the end is important since it is the directory where Pelican generate your site.&lt;/p&gt;
&lt;p&gt;At this point your are ready to deploy your site. You simply need to generate it using one of this ways:
* &lt;code&gt;pelican -lr&lt;/code&gt;
* &lt;code&gt;make html&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;I use the first option since it start a local server &lt;code&gt;http://localhost:8000&lt;/code&gt; which allow you to see your blog locally with a browser, but also the latest can be used.&lt;/p&gt;
&lt;p&gt;Once you have generated the html files for your articles, pages and everything else, you just need to add, commit and push your repo t deploy your site&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;git add .
git commit -am "First article"
git push
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;at this point you should see something like this:&lt;/p&gt;
&lt;div class="code"&gt;&lt;pre class="code literal-block"&gt;&lt;span class="n"&gt;Enumerating&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Counting&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Delta&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;compression&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;using&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;up&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;threads&lt;/span&gt;
&lt;span class="n"&gt;Compressing&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Writing&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;objects&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;338&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;bytes&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;338.00&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;KiB&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;Total&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;reused&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;delta&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Cloning&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;into&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;'/tmp/git/devel.grys.it'&lt;/span&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;done&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="n"&gt;To&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;grys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;&lt;span class="o"&gt;:/&lt;/span&gt;&lt;span class="n"&gt;home&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;git&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;devel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;grys&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;it&lt;/span&gt;
&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="n"&gt;e6f9934&lt;/span&gt;&lt;span class="p"&gt;..&lt;/span&gt;&lt;span class="n"&gt;ec16614&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="n"&gt;master&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;master&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;which is the message I got for this site.
If you get an error, it will be displayed in the message to allow you to solve the problem (permission problem, missing directory, wrong path, whatever)&lt;/p&gt;
&lt;p&gt;If no error is reported, congratulation, you just deployed your blog on your server, just open a browser and navigate to it to do a final check.&lt;/p&gt;</description><category>Git</category><category>Pelican</category><guid>https://devel.grys.it/posts/deploy-pelican-blog-with-git-on-linode/</guid><pubDate>Sat, 28 Dec 2019 22:02:46 GMT</pubDate></item></channel></rss>