title: Jgit:Bare Repository has neither a working tree, nor an index with existing repository
body: <p>I have an existing repository and trying to point to the existing repository and getting an exception as</p>
  <pre><code>Jgit:Bare Repository has neither a working tree, nor an index
  </code></pre>
  <p>Using the existing repository</p>
  <pre><code>public static Repository GetRepository(String destinationDirectory) throws IOException {
      Repository existingRepo = new FileRepositoryBuilder().setGitDir(new File(destinationDirectory))
              .readEnvironment() // scan environment GIT_* variables
              .findGitDir() // scan up the file system tree
              .build();
      return existingRepo;
  }
  </code></pre>
  <p>trying to get the status of the repository</p>
  <pre><code>public static void GitStatus(Repository repository) throws GitAPIException {
      
      try (Git git = new Git(repository)) {
          Status status = git.status().call();
          System.out.println(&quot;Added: &quot; + status.getAdded());
          System.out.println(&quot;Changed: &quot; + status.getChanged());
          System.out.println(&quot;Conflicting: &quot; + status.getConflicting());
          System.out.println(&quot;ConflictingStageState: &quot; + status.getConflictingStageState());
          System.out.println(&quot;IgnoredNotInIndex: &quot; + status.getIgnoredNotInIndex());
          System.out.println(&quot;Missing: &quot; + status.getMissing());
          System.out.println(&quot;Modified: &quot; + status.getModified());
          System.out.println(&quot;Removed: &quot; + status.getRemoved());
          System.out.println(&quot;Untracked: &quot; + status.getUntracked());
          System.out.println(&quot;UntrackedFolders: &quot; + status.getUntrackedFolders());
      }
  }
  </code></pre>
  <p><strong>Exception</strong></p>
  <pre><code>Exception in thread &quot;main&quot; org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
      at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:1147)
  </code></pre>
  <p><strong>File directory</strong>
  <a href="https://i.stack.imgur.com/taHLh.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/taHLh.png" alt="enter image description here" /></a></p>