title: JGit: Status of remote repository
body: <p>I'm trying to get the status of a Git repository using JGit in Eclipse.<br>
  I found some examples here: <a href="https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java" rel="nofollow">1</a>, <a href="https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowStatus.java" rel="nofollow">2</a> and merged them:</p>
  
  <pre><code>import java.io.File;
  import java.io.IOException;
  
  import org.eclipse.jgit.api.Git;
  import org.eclipse.jgit.api.errors.GitAPIException;
  import org.eclipse.jgit.api.errors.InvalidRemoteException;
  import org.eclipse.jgit.api.errors.TransportException;
  import org.eclipse.jgit.lib.Repository;
  import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
  import org.eclipse.jgit.api.Status;
  
  public class Main {
  
       private static final String REMOTE_URL = "https://github.com/github/testrepo.git";
  
          public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
              // prepare a new folder for the cloned repository
              File localPath = File.createTempFile("TestGitRepository", "");
              localPath.delete();
  
              // then clone
              System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
              Git.cloneRepository()
                      .setURI(REMOTE_URL)
                      .setDirectory(localPath)
                      .call();
  
              // now open the created repository
              FileRepositoryBuilder builder = new FileRepositoryBuilder();
              Repository repository = builder.setGitDir(localPath)
                      .readEnvironment() // scan environment GIT_* variables
                      .findGitDir() // scan up the file system tree
                      .build();
  
              System.out.println("Having repository: " + repository.getDirectory());
  
              Status status = new Git(repository).status().call();
              System.out.println("Added: " + status.getAdded());
              System.out.println("Changed: " + status.getChanged());
              System.out.println("Conflicting: " + status.getConflicting());
              System.out.println("ConflictingStageState: " + status.getConflictingStageState());
              System.out.println("IgnoredNotInIndex: " + status.getIgnoredNotInIndex());
              System.out.println("Missing: " + status.getMissing());
              System.out.println("Modified: " + status.getModified());
              System.out.println("Removed: " + status.getRemoved());
              System.out.println("Untracked: " + status.getUntracked());
              System.out.println("UntrackedFolders: " + status.getUntrackedFolders());
  
              repository.close();
          }
  }
  </code></pre>
  
  <p>But I get the following error: </p>
  
  <pre><code>Exception in thread "main" org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index
      at org.eclipse.jgit.lib.Repository.getWorkTree(Repository.java:1245)
      at org.eclipse.jgit.treewalk.FileTreeIterator.&lt;init&gt;(FileTreeIterator.java:88)
      at org.eclipse.jgit.api.StatusCommand.call(StatusCommand.java:126)
      at Main.main(Main.java:38)
  </code></pre>