| Getting status of repository [message #1313288] |
Thu, 24 April 2014 16:22  |
Eclipse User |
|
|
|
Hello.
I'm desperately trying to find a simple working example of JGit.
I found an example in the "jgit-cookbook" and changed it a little:
import java.io.File;
import java.io.IOException;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.Status;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
public class Main {
public static void main(String[] args) throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder
.setGitDir(
new File(
"....git")) // I'm not allowed to post links here
.readEnvironment() // scan environment GIT_* variables
.findGitDir() // scan up the file system tree
.build();
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();
}
}
But unfortunately I get the following error: 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.<init>(FileTreeIterator.java:88)
at org.eclipse.jgit.api.StatusCommand.call(StatusCommand.java:126)
at Main.main(Main.java:23)
I just want to get some simple information like name, date, size, etc. of all files. So I think, I need an iterator.
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03919 seconds