<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Posts on Smittie</title>
		<link>https://smittie.de/posts/</link>
		<description>Recent content in Posts on Smittie</description>
		<generator>Hugo -- gohugo.io</generator>
		<language>en-us</language>
		<copyright>This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.</copyright>
		<lastBuildDate>Sun, 19 Dec 2021 21:34:10 +0100</lastBuildDate>
		<atom:link href="https://smittie.de/posts/index.xml" rel="self" type="application/rss+xml" />
		
		<item>
			<title>Neovim As Git Mergetool</title>
			<link>https://smittie.de/posts/git-mergetool/</link>
			<pubDate>Sun, 19 Dec 2021 21:34:10 +0100</pubDate>
			
			<guid>https://smittie.de/posts/git-mergetool/</guid>
			<description>I like neovim and using git via the cli. Git has some options to customize specific tasks, for instance solving merge conflicts using git mergetool. In this blog post I&amp;rsquo;m going to demonstrate how to setup git and neovim to solve git merge conflicts without the need of an additional GUI tool.
Setup To achieve this there are a few prerequisites:
neovim and git are installed a merge conflict to test the config against Next Git&amp;rsquo;s config has to be updated in one of the following places:</description>
			<content type="html"><![CDATA[<p>I like neovim and using git via the cli.
Git has some options to customize specific tasks, for instance solving merge conflicts using <a href="https://git-scm.com/docs/git-mergetool">git mergetool</a>.
In this blog post I&rsquo;m going to demonstrate how to setup git and neovim to solve git merge conflicts without the need of an additional GUI tool.</p>
<h2 id="setup">Setup</h2>
<p>To achieve this there are a few prerequisites:</p>
<ul>
<li><a href="https://github.com/neovim/neovim">neovim</a> and git are installed</li>
<li>a merge conflict to test the config against</li>
</ul>
<p>Next Git&rsquo;s config has to be updated in one of the following places:</p>
<ol>
<li>$HOME/.gitconfig</li>
<li>$XDG_CONFIG_HOME/git/config</li>
<li>Inside the git repository under .git/config (for repo specific configuration)</li>
</ol>
<p>All of these are parsed and concatenated by git before command execution takes place.
NOTE: Local configuration overrules global configuration options if present.</p>
<p>To update such files different approaches can be considered.</p>
<p>For instance, using the git cli:
<code>git config mergetool nvim</code></p>
<p>This only registers a variable which still needs a command to be executed.</p>
<p><code>git config mergetool.nvim.cmd 'nvim -d -c &quot;wincmd l&quot; -c &quot;norm ]c&quot; &quot;$LOCAL&quot; &quot;$MERGED&quot; &quot;$REMOTE&quot;'</code></p>
<p>A short notice what is actually being executed here:</p>
<ul>
<li>
<p><code>nvim -d</code> opens neovim in diffmode.</p>
</li>
<li>
<p><code>-c &quot;wincmd l&quot;</code> executes <code>&lt;C-w&gt;l</code> to move the focus to the next split to the right.</p>
</li>
<li>
<p><code>-c &quot;norm ]c&quot;</code> puts the cursor inside the split to the first change.
It is the equivalent of hitting <code>]c</code> in command mode which is indicated by <code>norm</code>.
Command mode is also known as normal mode in vim.</p>
</li>
<li>
<p><code>&quot;$LOCAL&quot; &quot;$MERGED&quot; &quot;$REMOTE&quot;</code> defines the arrangement of the displayed diffs.</p>
</li>
</ul>
<p>After inserting the new options <code>git config -l | grep 'merge'</code> should reveal the following:</p>
<pre tabindex="0"><code class="language-git" data-lang="git">merge.tool=nvim
mergetool.nvim.cmd=nvim -d -c &#34;wincmd l&#34; -c &#34;norm ]c&#34; &#34;$LOCAL&#34; &#34;$MERGED&#34; &#34;$REMOTE&#34;
</code></pre><p>Inside the git config file it should look similar to this:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-toml" data-lang="toml"><span class="line"><span class="cl"><span class="p">[</span><span class="nx">merge</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">	<span class="nx">tool</span> <span class="p">=</span> <span class="s2">&#34;nvim&#34;</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">mergetool</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">	<span class="nx">keepBackup</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl">	<span class="nx">prompt</span> <span class="p">=</span> <span class="kc">false</span>
</span></span><span class="line"><span class="cl">
</span></span><span class="line"><span class="cl"><span class="p">[</span><span class="nx">mergetool</span> <span class="s2">&#34;nvim&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">	<span class="nx">cmd</span> <span class="p">=</span> <span class="s2">&#34;nvim -d -c \&#34;wincmd l\&#34; -c \&#34;norm ]c\&#34; \&#34;$LOCAL\&#34; \&#34;$MERGED\&#34; \&#34;$REMOTE\&#34;&#34;</span>
</span></span></code></pre></div><h2 id="run">Run</h2>
<p>Entering <code>git mergetool</code> will then parse all merge conflicted files and populate them iteratively to the mergetool command.</p>
<p><img src="/images/git-mergetool-1.png" alt="image alt git-mergetool-cli"></p>
<h2 id="resolve">Resolve</h2>
<p><img src="/images/git-mergetool-2.png" alt="image alt 3way-diff" title="3way-Diff using neovim"></p>
<p><code>:diffget local</code> will use the left diff from the local changes and <code>:diffget remote</code> vice versa.</p>
<p>To jump to the next change use <code>[c</code>.</p>
<p>After resolving all conflicts for a given file <code>:wqa</code> finishes the process and populates the next merge conflicted file into a new diffview.</p>
<p>Furthermore git will also place backup files of the originals inside the git repository, unless git config contains <code>keepBackup = false</code>.
Git will also ask before any merge conflicted file is opened in a diff, unless <code>prompt</code> is set to <code>false</code>.</p>
<p>This is just one approach among many, but it works quite well for me.</p>
<p>Further reading:</p>
<ol>
<li><a href="https://git-scm.com/docs/git-mergetool">git manual</a> for even more configuration options.</li>
<li><a href="https://github.com/neovim/neovim/blob/master/src/nvim/testdir/test_diffmode.vim#L607">neovim source</a> for more cli examples.</li>
</ol>
]]></content>
		</item>
		
		<item>
			<title>Introduction</title>
			<link>https://smittie.de/posts/introduction/</link>
			<pubDate>Thu, 02 Jul 2020 13:16:02 +0200</pubDate>
			
			<guid>https://smittie.de/posts/introduction/</guid>
			<description>&amp;ldquo;Success is not final, failure is not fatal: it is the courage to continue that counts.&amp;rdquo;
I don&amp;rsquo;t know about you but working on and with software I often find myself in a constant search for information to tackle domain specific problems. Scraping together information from different sources can be tedious sometimes but usually helps me to understand a topic better. But what do I do the next time the same situation occurs?</description>
			<content type="html"><![CDATA[<blockquote>
<p>&ldquo;Success is not final, failure is not fatal: it is the courage to continue that counts.&rdquo;</p>
</blockquote>
<p>I don&rsquo;t know about you but working on and with software I often find myself in a constant search for information to tackle domain specific problems.
Scraping together information from different sources can be tedious sometimes but usually helps me to understand a topic better.
But what do I do the next time the same situation occurs?</p>
<p>The point is, it often feels like that I am revisiting sites or posts I&rsquo;ve already been to for a similar if not the same reason.
There is nothing wrong with that in the sense, that if you don&rsquo;t need it regularly you probably don&rsquo;t need to remember it by heart.
In alignment with that I wish I had shortcuts to the information I once found.</p>
<p>By writing things down I&rsquo;ve experienced and learned, I get a better sense for my skill.
It helps me to reflect on the topic but also on keeping things somewhat organized.
Hence the idea of this blog was born and the attempt to aggregate such findings at one place to keep them handy.
Furthermore this is also a chance to help others in their search for answers.</p>
<blockquote>
<p>Why don&rsquo;t you just use medium.com or dev.to for that?</p>
</blockquote>
<p>I can&rsquo;t stand paywalls, so medium is a big no-no for me.
<a href="https://dev.to/">dev.to</a> is nice and I might integrate <a href="https://dev.to/beeman/automate-your-dev-posts-using-github-actions-4hp3">cross-posting</a> into my pipeline someday but not now.</p>
<p>So the idea of starting a blog has been on my mind for quite some time.
Fortunately I finally managed to spin up a setup that I found simple and functional enough to achieve this.</p>
<p>I really like <a href="https://clojure.org/">clojure</a> and I am probably gonna switch to a clojure based solution in the future, but for now I found hugo to be the best quick solution.
<a href="https://gohugo.io/">Hugo</a> is a popular static site generator and you might want to use it too if you are planning on starting a blog.
There are a lot of good reasons to use static site generators in favour of a full-fleged web-framework.
It&rsquo;s pretty fast, good on security and you can host it everywhere to name just a <a href="https://www.strattic.com/jekyll-hugo-wordpress-pros-cons-static-site-generators/">few reasons</a>.</p>
<p>This site is hosted on <a href="https://gitlab.com/lockejan/blog">gitlab.com</a> via <a href="https://docs.gitlab.com/ee/user/project/pages/">gitlab pages</a>.
The template is still just as is and I did setup gitlabs CI/CD support to test my site on updates.
So each time I check in an update to gitlab the updated site runs through some tests and only gets online if
these pass.</p>
<p>You could easily use another service for that or even host it yourself, but gitlab pages is a pretty decent option in my opinion.</p>
<p>Furthermore other people are able to read this and maybe learn something through it as well.
Even if it&rsquo;s just a link to a better source to their question.</p>
<p>So if you are interested in programming, coffee or anything else of the things I&rsquo;ve mentioned in my about section you should come back from time to time.
If one of my posts helped you in understanding a topic or getting a setup done, please let me know.</p>
<p>The site also provides an <a href="https://en.wikipedia.org/wiki/RSS">RSS</a> feed you can <a href="https://www.smittie.de/posts/index.xml">subscribe</a> to if you like.
I&rsquo;m planning to put at least one post a month online.</p>
<p>It&rsquo;s a try so let&rsquo;s see where this is going.</p>
<p>Have a great day.</p>
<p>Ciao,
Jan</p>
<p><em>Update: I&rsquo;ve switched to a self hosted solution and moved the blog to <a href="https://github.com/lockejan/blog">github.com</a></em></p>
]]></content>
		</item>
		
	</channel>
</rss>
