In several places a git repository was opened but not closed or not closed in case of exception. This commit fixes these places and ensures that the opened git repository is properly closed after use. Signed-off-by: Edwin Kempin <edwin.kempin@gmail.com>