Tuesday, December 10, 2013

Syncing a forked git repository with changes in the original repository

Using the built-in support for Git in Visual Studio 2013 is great... to a certain extent. Because eventually it will happen that you need to do some Git operation that is simply not supported. Having used Git on only one project so far it happened two times already that the built-in functionality wasn't enough.

The first situation was when I needed to revert a pushed commit. So I looked and looked in VS to locate such an action, but to no avail. Searching the Internet turned out people recommend using the command prompt. I opened a standard command prompt from Windows start menu and tried out the recommended Git commands, only to find out that it didn't work because it wasn't in a context of a repository (or something like that), and as I remembered it this was the case even if I navigated to the correct 'workspace' folder. After some more research it turns out that it is possible to open a Git-ish command prompt from VS (it is in the 'action' menu, available many places in the built-in Git client). Opening the command prompt this way places it in the correct context (not entirely sure how - maybe some environment variable is set). Anyway I was able to do the revert from there.

But this is really not what this article is about :-) No, what I want to describe here is how to synchronize a forked Git repository with changes in the original repository. So again I start a Git-ish command prompt, e.g. from 'Unsynched Commits' page in the Git client in VS. From there I execute the following commands:

First, link our repository with the remote (the original):
git remote add upstream [full-git-url-to-remote-repo]
Now, fetch changes:
git fetch upstream
Finally, do a merge, where [branch] can be master or some other branch:
git merge upstream/[branch]
That should do the trick. If there are any conflicts, they will now show up in VS and you can resolve them from there.

Thursday, October 24, 2013

Installing Solr 4.5 as a Windows service

I've recently had the good fortune to use the Solr search platform for a project. One thing, though, that is not straight forward is how to install Solr as a Windows service. There are several articles on the internet, but I couldn't find any that worked with Solr 4.5. So I gathered information from a number of out-dated articles and came up with the following approach, which has worked fine for me:

  1. Download Solr 4.5 (http://lucene.apache.org/solr/)
  2. Download the Non-Sucking Service Manager NSSM (http://nssm.cc/)
  3. Create a folder to be used for the Solr service (e.g. D:\solr). From now on this will be called <solrdir>
  4. From the example folder of the Solr package copy the following files and folders to <solrdir>:
    1. etc
    2. lib
    3. logs
    4. solr
    5. webapps
    6. start.jar
  5. In a command prompt go to <solrdir> and run the command java -jar start.jar to check that the Solr installation works. If it works then just stop it again.
  6. From the NSSM package copy nssm.exe to <solrdir>
  7. In a command prompt go to <solrdir> and run the command below. Note: it may be necessary to replace back-slashes in <solrdir> with forward-slashes.
    nssm.exe install Solr C:\Windows\System32\java.exe "-Dsolr.solr.home=<solrdir>/solr -Djetty.home=<solrdir>/ -Djetty.logs=<solrdir>/logs/ -cp <solrdir>/lib/*.jar;<solrdir>/start.jar -jar <solrdir>/start.jar"
To remove the service run the following command:
nssm.exe remove Solr

For convenience I've created the following batch script, which performs the nssm.exe install part. The script should be placed in <solrdir>.
@echo off
set currentdir=%~dp0
set parameters=-Dsolr.solr.home=""%currentdir%solr"" -Djetty.home=""%currentdir%"" -Djetty.logs=""%currentdir%logs/"" -cp ""%currentdir%lib/*.jar;%currentdir%start.jar"" -jar ""%currentdir%start.jar""

REM replace back-slashes with forward-slashes
set javaWeirdnessParameters=%parameters:\=/%

nssm.exe install Solr C:\Windows\System32\java.exe "%javaWeirdnessParameters%"