<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>VersionControl | Jacob Aloysious</title><link>https://jacobaloysious.in/category/versioncontrol/</link><atom:link href="https://jacobaloysious.in/category/versioncontrol/index.xml" rel="self" type="application/rss+xml"/><description>VersionControl</description><generator>Source Themes Academic (https://sourcethemes.com/academic/)</generator><language>en-us</language><lastBuildDate>Sun, 05 Jul 2020 00:00:00 +0000</lastBuildDate><image><url>https://jacobaloysious.in/images/icon_hu4591c05f594249c11c1e99a3a8f1f246_3759739_512x512_fill_lanczos_center_2.png</url><title>VersionControl</title><link>https://jacobaloysious.in/category/versioncontrol/</link></image><item><title>Version control your install directory - GIT</title><link>https://jacobaloysious.in/post/tech_version_install_dir_git/</link><pubDate>Sun, 05 Jul 2020 00:00:00 +0000</pubDate><guid>https://jacobaloysious.in/post/tech_version_install_dir_git/</guid><description>&lt;h3 id="what-problem-are-we-trying-to-solve">What problem are we trying to Solve?&lt;/h3>
&lt;p>Context: Desktop software installed on client computer, inside a private network and no access to internet.&lt;/p>
&lt;h4 id="use-cases">Use Cases:&lt;/h4>
&lt;ul>
&lt;li>Shipping and applying multiple patches for a given version of the software.&lt;/li>
&lt;li>Reverting a patch&lt;/li>
&lt;li>Keeping track of patches installed&lt;/li>
&lt;li>Check for sanity of the installation and tack &lt;strong>manual&lt;/strong> edits (configuration files etc..)&lt;/li>
&lt;li>User can apply a temporary patch on a server (i.e. common machine) and test, once done revert&lt;/li>
&lt;/ul>
&lt;h3 id="how-are-we-trying-to-solve">How are we trying to solve?&lt;/h3>
&lt;p>Bring the content of the install directory under version control. We will be using GIT version control, to explain how it could be achived.&lt;/p>
&lt;blockquote>
&lt;p>PreRequisite &amp;ldquo;git&amp;rdquo; should be installed and available in the path&lt;/p>
&lt;/blockquote>
&lt;h3 id="why-use-git">Why use GIT?&lt;/h3>
&lt;p>
&lt;a href="https://git-scm.com/" target="_blank" rel="noopener">Git&lt;/a> is a distributed version control system designed to handle everything from small to very large projects with speed and efficiency.&lt;/p>
&lt;p>So, with Git any &lt;strong>local folder&lt;/strong> can be converted into a &lt;strong>git repository&lt;/strong> by just running the &lt;strong>init&lt;/strong> command.&lt;/p>
&lt;pre>&lt;code>D:\Foo\1.0.0&amp;gt;git init
Initialized empty Git repository in D:/Foo/1.0.0/.git/
&lt;/code>&lt;/pre>
&lt;p>Now your installed directory is version controlled. You can add files, commit, create branch(s), switch branches etc&amp;hellip; Since Git is distributed - &lt;strong>N0 Server nor Internet required&lt;/strong> 😄&lt;/p>
&lt;p>At any point of time, you could use &lt;strong>status&lt;/strong> to check if the install directory has any &lt;strong>modified&lt;/strong>, &lt;strong>new&lt;/strong> or &lt;strong>deleted&lt;/strong> files.&lt;/p>
&lt;pre>&lt;code>D:\Foo\1.0.0&amp;gt;git status
On branch base_install
Changes not staged for commit:
(use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)
(use &amp;quot;git checkout -- &amp;lt;file&amp;gt;...&amp;quot; to discard changes in working directory)
modified: config/params.toml
Untracked files:
(use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to include in what will be committed)
config/menus.toml
config/languages.toml
&lt;/code>&lt;/pre>
&lt;p>You could use &lt;strong>git diff&lt;/strong> command to compare changes across two branches like &lt;strong>base_install&lt;/strong> vs &lt;strong>patch_1&lt;/strong>&lt;/p>
&lt;pre>&lt;code>D:\Foo\1.0.0&amp;gt;git diff base_install patch_1
diff --git a/Config/params.toml
index b32de60..e8e1694 100644
--- a/Config/params.toml
+++ b/Config/params.toml
@@ -29,7 +29,7 @@
- main_menu = {align = &amp;quot;l&amp;quot;, show_logo = true}
+ main_menu = {align = &amp;quot;l&amp;quot;, show_logo = false}
&lt;/code>&lt;/pre>
&lt;p>Creating a branch is a trivial operation. As a user you could&lt;/p>
&lt;ul>
&lt;li>Create a new (personal) branch from current (master) branch&lt;/li>
&lt;li>Apply the patch files (edit or new) -&amp;gt; Commit your changes to your &lt;em>personal&lt;/em> branch&lt;/li>
&lt;li>Run your tests&lt;/li>
&lt;li>Once you are done, switch to the original (master) branch&lt;/li>
&lt;/ul>
&lt;p>If you observe - &lt;strong>you don&amp;rsquo;t have to delete your patch&lt;/strong> - at any point of time when you have server time you could come back and switch to your branch&amp;hellip;&lt;/p>
&lt;pre>&lt;code>D:\Foo\1.0.0&amp;gt;git checkout jac_logo_patch
Switched to branch 'jac_logo_patch'
&lt;/code>&lt;/pre>
&lt;h2 id="installer-workflow-and-scripts-sequence">Installer workflow and Scripts sequence&amp;hellip;&lt;/h2>
&lt;h3 id="post-install">POST INSTALL&lt;/h3>
&lt;ol>
&lt;li>Installer should copy this file into the root of destination directory and execute&lt;/li>
&lt;li>Example: &amp;ldquo;D:\Foo\&amp;laquo;_Build_Number_&amp;raquo;&amp;rdquo;&lt;/li>
&lt;li>Run this file post installation&lt;/li>
&lt;/ol>
&lt;h4 id="steps">Steps:&lt;/h4>
&lt;ol>
&lt;li>Initialize git.&lt;/li>
&lt;li>Create a .gitignore file.&lt;/li>
&lt;li>Add contents into .gitignore.&lt;/li>
&lt;li>Create a branch &lt;strong>base_Install&lt;/strong>.&lt;/li>
&lt;li>Commit all contents into git repo with msg &lt;em>Base Install Commit&lt;/em>.&lt;/li>
&lt;/ol>
&lt;pre>&lt;code class="language-bash">@echo off
echo Initializing Git
call git init
echo Add git ignore files
call touch .gitignore
echo Add files to .git ignore for installer cmd files
call PostInstall.cmd &amp;gt;&amp;gt; .gitignore
echo Add all the files and create a initial commit named Base Install. This would take a while!!
call git add -A &amp;amp;&amp;amp; git commit -m &amp;quot;Base Install Commit&amp;quot;
echo Creating a new branch base_install
call git branch base_install
&lt;/code>&lt;/pre>
&lt;h3 id="patch-installer">PATCH INSTALLER&lt;/h3>
&lt;h4 id="pre-install">PRE INSTALL&lt;/h4>
&lt;p>Copy this file into the root of destination directory - D:\Foo\&amp;laquo;Build_Number&amp;raquo;&amp;rdquo;&lt;/p>
&lt;ol>
&lt;li>Check if branch exists&lt;/li>
&lt;li>Add all existing UNTRACKED FILES into the current branch&lt;/li>
&lt;li>Add add a commit message &lt;strong>PrePatch_&amp;lt;PATCH_NAME&amp;gt;&lt;/strong>&lt;/li>
&lt;li>Add the current branch to a known file &lt;strong>LastKnownWorkingBranch&lt;/strong>; useful for un-installation&lt;/li>
&lt;li>Create a &lt;em>new branch&lt;/em> &lt;strong>PATCH_&amp;lt;PATCH_NAME&amp;gt;&lt;/strong>&lt;/li>
&lt;li>Switch to new branch with PATCH_&amp;lt;PATCH_NAME&amp;gt;&lt;/li>
&lt;li>Apply the patch using &lt;strong>git am&lt;/strong>. Note: &lt;strong>am&lt;/strong> would allow you to sign off an applied patch. This maybe useful for future reference.&lt;/li>
&lt;li>Add all existing UNTRACKED FILES into new/current branch i.e. PATCH_&amp;lt;PATCH_NAME&amp;gt;&lt;/li>
&lt;li>Done - we have a new branch with all patches&lt;/li>
&lt;/ol>
&lt;pre>&lt;code class="language-bash">REM TODO: This could be an enviornment variable
set patchName=Patch_1
set branchName=Patch_%patchName%
echo Check if git installed
call git --version
if ERRORLEVEL 1 (
echo Git not installed!!!
goto :Cleanup
)
echo Check if valid git repository
call git rev-parse --is-inside-work-tree
if ERRORLEVEL 1 (
echo Not a valid git repo : %cd%
REM TODO - Should we create a new git repo? or fall back scripts to use .keep solution
goto :Cleanup
)
set commitMsg=&amp;quot;PrePatch_%patchName%&amp;quot;
echo Add all un-tracked files and create a
call git add -A &amp;amp;&amp;amp; git commit -m %commitMsg%
echo Add the current branch name into a temporary file - LastKnownWorkingBranch
call git symbolic-ref --short HEAD &amp;gt; LastKnownWorkingBranch
echo Check if branch exits
git rev-parse --verify %branchName%
if ERRORLEVEL 0 (
echo Branch exists : %branchName%
)
echo Create a new branch
git branch %branchName%
echo Checkout the new branch
git checkout %branchName%
echo Apply the .git patch
git am --signoff &amp;lt; %patchName%.patch
:Cleanup
echo exit
&lt;/code>&lt;/pre>
&lt;p>User can always go back to the base install by switching branches.&lt;/p>
&lt;h3 id="post-install-1">POST INSTALL&lt;/h3>
&lt;h4 id="steps-1">Steps&lt;/h4>
&lt;ol>
&lt;li>Now we are in the new branch for the Patch&lt;/li>
&lt;li>And install script has already installed all the patch files&lt;/li>
&lt;li>Just commit all the changes and we are good to go!!&lt;/li>
&lt;li>Patch installation done!!&lt;/li>
&lt;/ol>
&lt;pre>&lt;code class="language-bash">REM TODO: This should be an enviornment variable
set patchName=Patch_1
set branchName=Patch_%patchName%
set commitMsg=&amp;quot;Patch_%patchName%&amp;quot;
echo Add all un-tracked files and create a
call git add -A &amp;amp;&amp;amp; git commit -m %commitMsg%
echo Patch installed and avaialble in branch %branchName%
&lt;/code>&lt;/pre>
&lt;h3 id="patch-un-installer">PATCH UN-INSTALLER&lt;/h3>
&lt;h4 id="steps-2">Steps&lt;/h4>
&lt;ol>
&lt;li>Read the &lt;strong>lastKnownWorkingBranch&lt;/strong> from a file&lt;/li>
&lt;li>git checkout lastKnownWorkingBranch&lt;/li>
&lt;li>Voila thats it!!&lt;/li>
&lt;/ol>
&lt;blockquote>
&lt;p>&lt;strong>Note:&lt;/strong> File &amp;ldquo;lastKnownWorkingBranch&amp;rdquo; file should be under .gitignore (?) so that its shared across branches and its updated only by the patch installer.&lt;/p>
&lt;/blockquote>
&lt;pre>&lt;code class="language-bash">for /f &amp;quot;delims=&amp;quot; %%a in ('type LastKnownWorkingBranch') do (
set lastKnownWorkingBranch=%%a
break
)
echo lastKnownWorkingBranch: %lastKnownWorkingBranch%
echo Checkout the lastKnownWorkingBranch: %lastKnownWorkingBranch%
git checkout %lastKnownWorkingBranch%
echo Voila we have reverted the previous install
&lt;/code>&lt;/pre>
&lt;h2 id="advantages">ADVANTAGES&lt;/h2>
&lt;ul>
&lt;li>User could compare what has changed across branches aka patches&lt;/li>
&lt;li>User could always go back to base_install at any point of time&lt;/li>
&lt;li>Files are never deleted&lt;/li>
&lt;li>Uninstall is just switching a branch - no file deletes.&lt;/li>
&lt;li>Any number of branches can be created for &lt;strong>personal&lt;/strong> testing.&lt;/li>
&lt;/ul></description></item></channel></rss>