Sunday, November 19, 2017

Git clones git


Good morning folks,
And I hope that your morning as beautiful as mine, down there in Naples, Florida. I have found a plausible excuse to skip landscaping: share mine small findings with you.

I'm playing with the Bamboo server for another good story or rather few stories (main characters: SOA 12c, Bamboo, Maven, and Ant) and the very first built has failed with the error:

simple 18-Nov-2017 16:38:24 error: unknown switch 'c'
simple 18-Nov-2017 16:38:24 usage: git clone [options] [--] <repo> [<dir>]
simple 18-Nov-2017 16:38:24 
simple 18-Nov-2017 16:38:24     -v, --verbose         be more verbose
simple 18-Nov-2017 16:38:24     -q, --quiet           be more quiet
simple 18-Nov-2017 16:38:24     --progress            force progress reporting
simple 18-Nov-2017 16:38:24     -n, --no-checkout     don't create a checkout
simple 18-Nov-2017 16:38:24     --bare                create a bare repository
simple 18-Nov-2017 16:38:24     --mirror              create a mirror repository (implies bare)
simple 18-Nov-2017 16:38:24     -l, --local           to clone from a local repository
simple 18-Nov-2017 16:38:24     --no-hardlinks        don't use local hardlinks, always copy
simple 18-Nov-2017 16:38:24     -s, --shared          setup as shared repository
simple 18-Nov-2017 16:38:24     --recursive           initialize submodules in the clone
simple 18-Nov-2017 16:38:24     --template <path>     path the template repository
simple 18-Nov-2017 16:38:24     --reference <repo>    reference repository
simple 18-Nov-2017 16:38:24     -o, --origin <branch>
simple 18-Nov-2017 16:38:24                           use <branch> instead of 'origin' to track upstream
simple 18-Nov-2017 16:38:24     -b, --branch <branch>
simple 18-Nov-2017 16:38:24                           checkout <branch> instead of the remote's HEAD
simple 18-Nov-2017 16:38:24     -u, --upload-pack <path>
simple 18-Nov-2017 16:38:24                           path to git-upload-pack on the remote
simple 18-Nov-2017 16:38:24     --depth <depth>       create a shallow clone of that depth
simple 18-Nov-2017 16:38:24 
error 18-Nov-2017 16:38:24 Checkout to revision 1d00aad94cb91435c7099197965c3ef52828e80d has failed.

Obviously, Bamboo is not happy with the installed git command. So my the first thought was:
"Let's check what git command is in use". This information could be found or configured on Bamboo Server capabilities page. To find it:
  1. Click on the Bamboo Administration drop-down. It's a gear icon on the far right side of the main menu (you should have administrative privileges).
  2. Select Overview (Don't ask me why) and then 
  3. From the navigation pane on the left select Server capabilities
As you may see, Bamboo uses /usr/bin/git by default. Quick version check shows that for the OEL 6 the latest git available is 1.7.1, which is way below Bamboo requirements. The answer is obvious: we need the fresh git and we will build it ourselves. The question how has multiple answers. The one is - get a git tarball and build it from the sources, but we have git already, so we can clone git with git and make it. 
It's easy, especially with my little tips. after set trails and errors. Let's start with the system preparation.  You may need to install some tools, and you definitely need to install headers.


Make sure that  you have all necessary tools to make binaries and manuals:
 
 #yum install autoconf asciidoc xmlto


And necessary headers:
 #yum install openssl-devel curl-devel expat-devel

Now we can clone git source code. I've cloned the git repository into the  /usr/local/src folder.
      
 # cd /usr/local/src
 # git clone https://github.com/git/git
 Initialized empty Git repository in /usr/local/src/git/.git/
 remote: Counting objects: 234099, done. 
 remote: Total 234099 (delta 0), reused 0 (delta 0), pack-reused 234098
 Receiving objects: 100% (234099/234099), 96.34 MiB | 5.42 MiB/s, done.
 Resolving deltas: 100% (172451/172451), done.

The git repository is large so it may take a time to clone it. now let's go down to the new folder and build our latest greatest tool.
I strongly recommend not to replace the system command. By default, binaries will be placed into the ~/bin directory, but I prefer something more available for the others so let's install it into /usr/local/bin folder.

 # cd git
 # make prefix=/usr/local install install-doc
At the end of the really long and scary output, you should see something similar to:

 ..............
 ...............
 install -d -m 755 /root/share/man/man1
 install -d -m 755 /root/share/man/man5
 install -d -m 755 /root/share/man/man7
 install -m 644 git-add.1 git-am.1 git-annotate.1 git-apply.1 git-archimport.1
 install -m 644 gitattributes.5 githooks.5 gitignore.5 gitmodules.5 gitreposit
 install -m 644 gitcli.7 gitcore-tutorial.7 gitcredentials.7 gitcvs-migration.
 make[1]: Leaving directory `/usr/local/src/git/Documentation'
 #

Now I'm checking if my git command works and has the proper version

 # /usr/local/bin/git --version
git version 2.15.0.276.g89ea799
 # git --version
git version 1.7.1

Great we have old git command for the system and the new one for the Bamboo server. Now fix Bamboo server configuration:
  1. Open the Server capabilities page again and edit Git capability, replacing command /usr/bin/git with the /usr/local/bin/git.
  2. Save your changes
  3. Open your build plan and re-run manually. This time you should get your source from the GitHub

Enjoy your day and have all greens in your builds. 


Post a Comment