code: public synchronized void switchRepository(String uri) throws Exception {
      File oldRepo = null;
      File gitDir = null;
      try {
        writeLock.lock();
        latch.await();
        if(!git.getRemoteRepository().equalsIgnoreCase(uri)) {
          logger.debug("Switching repo from {} to {}", git.getRemoteRepository(), uri);
          gitDir = new File(git.getBaseDirectory());
          IOUtils.closeQuietly(git);
          git = null;
          oldRepo = new File(gitDir.getParentFile(), "old-git-checkout");
          FileUtils.deleteQuietly(oldRepo);
          FileUtils.copyDirectory(gitDir, oldRepo);
          FileUtils.deleteDirectory(gitDir);
          git = GitService.cloneRepo(uri, gitDir.getAbsolutePath());
        }
      } catch(InterruptedException ie){
        logger.warn("Thread interrupted, must be shutting down!", ie);
        throw ie;
      } catch(Exception e) {
        logger.warn("Failed to switch repository. Rolling back!");
        if(git != null) {
          IOUtils.closeQuietly(git);
          git = null;
        }
        FileUtils.deleteQuietly(gitDir);
        FileUtils.copyDirectory(oldRepo, gitDir);
        git = GitService.createGitService(gitDir.getAbsolutePath());
        throw e;
      } finally {
        FileUtils.deleteQuietly(oldRepo);
        writeLock.unlock();
      }
    }
docs: <p>Switches the current reference to point to a new remote git repository.</p>
  <p>This method will block if the common reference has not been set or there are any threads currently using the referenced git service.</p>
  
  @param uri The uri to the remote repository.
  @throws Exception