diff --git a/versioncontrol_git.log.inc b/versioncontrol_git.log.inc
index 79ab4e3..f525620 100755
--- a/versioncontrol_git.log.inc
+++ b/versioncontrol_git.log.inc
@@ -25,11 +25,6 @@ include_once(drupal_get_path('module', 'versioncontrol') .'/includes/Versioncont
  *   failed for whatever reason.
  */
 function _versioncontrol_git_log_update_repository(&$repository) {
-  $root = escapeshellcmd($repository->root);
-  $chdir_ok = @chdir($root); // Set working directory to root.
-  if ($chdir_ok === FALSE) {
-    return FALSE;
-  }
   if ($repository->data['versioncontrol_git']['locked'] == TRUE) {
     drupal_set_message(t('This repository is locked, there is already a fetch in progress. If this is not the case, press the clear lock button.'), 'error');
     return FALSE;
@@ -37,7 +32,7 @@ function _versioncontrol_git_log_update_repository(&$repository) {
   $repository->data['versioncontrol_git']['locked'] = 1;
   $repository->update();
   
-  $branches_in_repo = _versioncontrol_git_log_get_branches_in_repo();
+  $branches_in_repo = _versioncontrol_git_log_get_branches_in_repo($repository->root);
   $branches_in_db = _versioncontrol_git_log_get_branches_in_db($repository);
   $branches_new = array_diff($branches_in_repo, $branches_in_db);
   $branches_deleted = array_diff($branches_in_db, $branches_in_repo);
@@ -79,18 +74,18 @@ function _versioncontrol_git_log_update_repository(&$repository) {
 
   // Insert new commits in the database.
   foreach($commits_new as $new_commit) {
-    $new_commit_data = _versioncontrol_git_log_get_raw_commit_data($new_commit);
+    $new_commit_data = _versioncontrol_git_log_get_raw_commit_data($repository->root, $new_commit);
     _versioncontrol_git_log_parse_and_insert_commit($repository, $new_commit_data, $commits_in_db, $branch_label_list);
   }
 
   // Add a new branch to all commits contained in that branch.
   foreach($branches_new as $branch_new) {
-  	$commits = _versioncontrol_git_log_get_commits_in_branch($branch_new);
+    $commits = _versioncontrol_git_log_get_commits_in_branch($repository->root, $branch_new);
   	_versioncontrol_git_log_attach_branch_to_commits($branch_label_list[$branch_new], $commits);
   }
 
   // Insert new tags in the database.
-  $tags_in_repo = _versioncontrol_git_log_get_tags_in_repo();
+  $tags_in_repo = _versioncontrol_git_log_get_tags_in_repo($repository->root);
   $tags_in_db = _versioncontrol_git_log_get_tags_in_db($repository);
   // Deleting tags is *not* supported. Read the manual if you want to know why...
   // Check for new tags.
@@ -110,12 +105,14 @@ function _versioncontrol_git_log_update_repository(&$repository) {
 
 /**
  * Execute a Git command using the root context and the command to be executed.
- * @param string $command Command to execute.
+ * @param string $root Git repository location (actual repo dir, not working dir).
+ * @param string $command Git sub-command to execute.
  * @return mixed Logged output from the command in either array of file pointer form.
  */
-function _versioncontrol_git_log_exec($command) {
+function _versioncontrol_git_log_exec($root, $command) {
   $logs = array();
-  exec($command, $logs);
+  $root = escapeshellcmd($repository->root);
+  exec('git --git-dir='.$root.' '.$command, $logs);
   array_unshift($logs, '');
   reset($logs); // Reset the array pointer, so that we can use next().
   return $logs;
@@ -175,24 +172,26 @@ function _versioncontrol_git_log_get_commits_in_db($repository) {
 
 /**
  * Get the raw git output for $revision.
+ * @param string $root Repository location
  * @param string $revision
  * @return The raw git output which can be fed into the commit parser for a given commit.
  */
-function _versioncontrol_git_log_get_raw_commit_data($revision) {
+function _versioncontrol_git_log_get_raw_commit_data($root, $revision) {
   $revision = escapeshellarg($revision);
-  $command = "git log $revision --numstat --summary --pretty=format:\"%H%n%P%n%aN <%ae>%n%ct%n%s%n%b%nENDOFOUTPUTGITMESSAGEHERE\" -n 1 -c --";
-  return _versioncontrol_git_log_exec($command);
+  $command = "log $revision --numstat --summary --pretty=format:\"%H%n%P%n%aN <%ae>%n%ct%n%s%n%b%nENDOFOUTPUTGITMESSAGEHERE\" -n 1 -c --";
+  return _versioncontrol_git_log_exec($root, $command);
 }
 
 /**
  * Returns an array of all branches a given commit is in.
+ * @param string $root Repository location
  * @param string $revision
  * @param array $branch_label_list
  * @return VersioncontrolBranch
  */
-function _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label_list) {
-  $exec = 'git branch --contains ' . escapeshellarg($revision);
-  $logs = _versioncontrol_git_log_exec($exec);
+function _versioncontrol_git_log_get_branches_of_commit($root, $revision, $branch_label_list) {
+  $exec = 'branch --contains ' . escapeshellarg($revision);
+  $logs = _versioncontrol_git_log_exec($root, $exec);
   $branches = array();
   while (($line = next($logs)) !== FALSE) {
     $line = trim($line);
@@ -210,7 +209,7 @@ function _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label
  * @return array An array of strings with all commit id's in it
  */
 function _versioncontrol_git_log_get_commits_in_repo($repository) {
-  $logs = _versioncontrol_git_log_exec("git rev-list --all");
+  $logs = _versioncontrol_git_log_exec($repository->root, "rev-list --all");
   $commits = array();
   while (($line = next($logs)) !== FALSE) {
     $commits[] = trim($line);
@@ -220,11 +219,12 @@ function _versioncontrol_git_log_get_commits_in_repo($repository) {
 
 /**
  * This function returns all commits in the given branch.
+ * @param string $root Repository location
  * @param string $branch
  * @return array An array of strings with all commit id's in it
  */
-function _versioncontrol_git_log_get_commits_in_branch($branch) {
-  $logs = _versioncontrol_git_log_exec("git rev-list " . escapeshellarg($branch) . " --");
+function _versioncontrol_git_log_get_commits_in_branch($root, $branch) {
+  $logs = _versioncontrol_git_log_exec($root, "rev-list " . escapeshellarg($branch) . " --");
   $commits = array();
   while (($line = next($logs)) !== FALSE) {
     $commits[] = trim($line);
@@ -234,28 +234,30 @@ function _versioncontrol_git_log_get_commits_in_branch($branch) {
 
 /**
  * Returns the previous commits which touched a given file.
+ * @param string $root Repository location
  * @param string $path
  * @param string $revision_current
  * @param int $parent_count
  * @return string
  */
-function _versioncontrol_git_get_prev_commits_touching_file($path, $revision_current, $parent_count) {
+function _versioncontrol_git_get_prev_commits_touching_file($root, $path, $revision_current, $parent_count) {
   // We need one more revision to fulfill git rev-list's requirements.
   $parent_count += 1;
-  $exec = 'git rev-list -n ' . $parent_count . ' ' . escapeshellarg($revision_current) . ' -- ' . escapeshellarg($path);
-  return _versioncontrol_git_log_exec($exec);
+  $exec = 'rev-list -n ' . $parent_count . ' ' . escapeshellarg($revision_current) . ' -- ' . escapeshellarg($path);
+  return _versioncontrol_git_log_exec($root, $exec);
 }
 
 /**
  * A function to fill in the source_item for a specific VersioncontrolItem.
+ * @param string $root Repository location
  * @param VersioncontrolItem $item
  * @param array $parents The parent commit(s)
  * @return none
  */
-function _versioncontrol_git_fill_source_item($item, $parents) {
+function _versioncontrol_git_fill_source_item($root, $item, $parents) {
   $parent_count = count($parents);
   $path_stripped = substr($item->path, 1);
-  $prev_revisions = _versioncontrol_git_get_prev_commits_touching_file($path_stripped, $item->revision, $parent_count);
+  $prev_revisions = _versioncontrol_git_get_prev_commits_touching_file($root, $path_stripped, $item->revision, $parent_count);
 
   for($i = 0; $i < $parent_count; ++$i) {
     $revision = trim($prev_revisions[$i + 2]);
@@ -319,7 +321,7 @@ function _versioncontrol_git_parse_items($repository, &$logs, &$line, $revision,
   // Fill in the source_items for non-added items
   foreach ($op_items as $path => $item) {
     if ($item->action != VERSIONCONTROL_ACTION_ADDED) {
-      _versioncontrol_git_fill_source_item($item, $parents);
+      _versioncontrol_git_fill_source_item($repository->root, $item, $parents);
     }
   }
   return $op_items;
@@ -379,7 +381,7 @@ function _versioncontrol_git_log_parse_and_insert_commit($repository, $logs, &$c
     $parents, $merge);
 
   $op = new VersioncontrolGitOperation(VERSIONCONTROL_OPERATION_COMMIT, $username, $date, $revision, $message, $username, $repository);
-  $op->labels = _versioncontrol_git_log_get_branches_of_commit($revision, $branch_label_list);
+  $op->labels = _versioncontrol_git_log_get_branches_of_commit($repository->root, $revision, $branch_label_list);
   $op->insert($op_items);
   
   $commits_in_db[] = $revision;
@@ -400,10 +402,11 @@ function _versioncontrol_git_log_get_branches_in_db($repository) {
 
 /**
  * Get branches from Git using 'branch -l' command.
+ * @param string $root Repository location
  * @return array List of branches.
  */
-function _versioncontrol_git_log_get_branches_in_repo() {
-  $logs = _versioncontrol_git_log_exec('git show-ref --heads'); // Query branches.
+function _versioncontrol_git_log_get_branches_in_repo($root) {
+  $logs = _versioncontrol_git_log_exec($root, 'show-ref --heads'); // Query branches.
   $branches = array();
   while (($line = next($logs)) !== FALSE) {
   	// the output of git show-ref --heads looks like this
@@ -482,10 +485,11 @@ function _versioncontrol_git_log_get_tags_in_db($repository) {
 
 /**
  * Get all tags present in the repository.
+ * @param string $root Repository location
  * @return array
  */
-function _versioncontrol_git_log_get_tags_in_repo() {
-  $log = _versioncontrol_git_log_exec('git show-ref --tags'); // Query tags.
+function _versioncontrol_git_log_get_tags_in_repo($root) {
+  $log = _versioncontrol_git_log_exec($root, 'show-ref --tags'); // Query tags.
   $tags = array();
   while (($line = next($log)) !== FALSE) {
   	// the output of git show-ref --tags looks like this
@@ -514,16 +518,17 @@ function _versioncontrol_git_get_tag_string($tags) {
 /**
  * Returns a list of tag names with the tagged commits.
  * Handles annotated tags.
+ * @param string $root Repository location
  * @param array $tags An array of tag names
  * @return array A list of all tags with the respective tagged commit.
  */
-function _versioncontrol_git_log_get_tag_commit_list($tags) {
+function _versioncontrol_git_log_get_tag_commit_list($root, $tags) {
   if(empty($tags)) {
     return array();
   }
   $tag_string = _versioncontrol_git_get_tag_string($tags);
-  $exec = "git show-ref -d $tag_string";
-  $tag_commit_list_raw = _versioncontrol_git_log_exec($exec);
+  $exec = "show-ref -d $tag_string";
+  $tag_commit_list_raw = _versioncontrol_git_log_exec($root, $exec);
   $tag_commit_list = array();
   $tags_annotated = array();
   foreach($tag_commit_list_raw as $tag_commit_line) {
@@ -566,11 +571,11 @@ function _versioncontrol_git_log_process_tags($repository, $tags_new) {
   $tag_ops = array();
 
   // get a list of all tag names with the corresponding commit.
-  $tag_commit_list = _versioncontrol_git_log_get_tag_commit_list($tags_new);
+  $tag_commit_list = _versioncontrol_git_log_get_tag_commit_list($repository->root, $tags_new);
   $format = '%(objecttype)%0a%(objectname)%0a%(refname)%0a%(taggername) %(taggeremail)%0a%(taggerdate)%0a%(contents)ENDOFGITTAGOUTPUTMESAGEHERE';
   foreach($tag_commit_list as $tag_name => $tag_commit) {
-    $exec = "git for-each-ref --format=\"$format\" refs/tags/" . escapeshellarg($tag_name);
-  	$logs_tag_msg = _versioncontrol_git_log_exec($exec);
+    $exec = "for-each-ref --format=\"$format\" refs/tags/" . escapeshellarg($tag_name);
+    $logs_tag_msg = _versioncontrol_git_log_exec($repository->root, $exec);
     $tagged_commit_op = _versioncontrol_git_log_get_commit($repository, $tag_commit);
   	// Get the specific tag data for annotated vs not annotated tags.
     if($logs_tag_msg[1] == 'commit') {
diff --git a/xgit/xgit-config.php b/xgit/xgit-config.php
index 372d5d7..89e08ad 100755
--- a/xgit/xgit-config.php
+++ b/xgit/xgit-config.php
@@ -81,7 +81,7 @@ function xgit_bootstrap($xgit) {
   require_once './includes/bootstrap.inc';
   drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
 
-  chdir($current_directory);
+  return $current_directory;
 }
 
 function xgit_get_temp_directory($temp_path) {
diff --git a/xgit/xgit-loginfo.php b/xgit/xgit-loginfo.php
index f535afe..08391d3 100755
--- a/xgit/xgit-loginfo.php
+++ b/xgit/xgit-loginfo.php
@@ -37,7 +37,7 @@ function xgit_init($argc, $argv) {
   include_once $config_file;
 
   // Do a full Drupal bootstrap.
-  xgit_bootstrap($xgit);
+  $current_directory = xgit_bootstrap($xgit);
 
   // Execute update.
   $repository = versioncontrol_get_repository($xgit['repo_id']);
@@ -49,6 +49,8 @@ function xgit_init($argc, $argv) {
     set_time_limit(3600);
   }
   _versioncontrol_git_update_repository($repository);
+
+  chdir($current_directory);
   exit(0);
 }
 
