: 1, 2하고 합병 :
나는 여기에 몇 가지 예를 발견
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();
}
}
을하지만, 나는 다음과 같은 오류가 발생합니다 스 니펫이 작동합니다. 당신의 조각이 localPath
에 빌더의 GitDir을 설정하지만 로컬 경로는 단지 복제 저장소의 작업 디렉토리를 표시
Git git = Git.open(localPath);
Repository repository = git.getRepository();
참고.
감사합니다. 오류가 발생하지 않습니다. 'Added : [] 변경 : [] 충돌 : [] ... ' – user1170330
당신은 무엇을 기대합니까? 갓 복제 된 저장소에서는 작업 디렉토리, 색인 및 HEAD 커미트간에 차이가 없기 때문에 결과는 비어 있습니다. [git status] (https://www.kernel.org/pub/software/scm/git/docs/git-status.html)를 이해했는지 확인하십시오. –
그러면 어떻게 복제 된 것이 아닌 실제 디렉토리에서 결과를 얻을 수 있습니까? 나는 "이름, 크기, 날짜 등"과 같은 것을 필요로합니다. 파일의. – user1170330