JavaGit Api 无法在 Windows 上工作

JavaGit Api not Working on Windows

package modifiedlines;

import edu.nyu.cs.javagit.api.DotGit;
import edu.nyu.cs.javagit.api.JavaGitConfiguration;
import edu.nyu.cs.javagit.api.JavaGitException;
import edu.nyu.cs.javagit.api.WorkingTree;
import edu.nyu.cs.javagit.api.commands.GitLogResponse;
import edu.nyu.cs.javagit.api.commands.GitStatus;
import edu.nyu.cs.javagit.api.commands.GitStatusOptions;
import edu.nyu.cs.javagit.api.commands.GitStatusResponse;
import java.io.File;
import java.io.IOException;
import java.util.List;

/**
 *
 * @

    author aryan000
     */

public class UseGit {

    private static File repositoryDirectory;
    private static DotGit dotGit;

    public static void main(String s[]) throws JavaGitException, IOException
    {   

        File f = new File("C:\Program Files\Git\bin\git.exe");

        if(!f.exists())
        {
            System.out.println("does not exist");
        }
        else
            System.out.println("exists  at " + f.getPath());
        JavaGitConfiguration.setGitPath("C:\Program Files\Git\bin");
        System.out.println("Git version : " + JavaGitConfiguration.getGitVersion());
//        repositoryDirectory = new File("/home/aryan000/Desktop/retrofit");


        repositoryDirectory = new File("/home/aryan000/Desktop/changeprone/changeprone");

        System.out.println("Git Repository Location : " + repositoryDirectory.getAbsolutePath());

        //get the instance of the dotGit Object
        dotGit = DotGit.getInstance(repositoryDirectory);

//        System.out.println("checking what i have got ");
//        GitLogResponse.CommitFile com ;
//        com = (GitLogResponse.CommitFile) dotGit.getLog();
//        
//        System.out.println(com);

         WorkingTree wt = dotGit.getWorkingTree();
         File workingTreePath = wt.getPath();
         GitStatus gitStatus = new GitStatus();
         GitStatusResponse status = gitStatus.status(workingTreePath);

         System.out.println("status is : " + status);

         File anotherFileDir = new File("/home/aryan000/Desktop/retrofit/test.txt");
        GitStatusOptions options = new GitStatusOptions();
        options.setOptOnly(true);
        status = gitStatus.status(workingTreePath);

        System.out.println("status is : " + status);







        System.out.println("----- Print log to see our commit -----");
        for (GitLogResponse.Commit c : dotGit.getLog()) {
            System.out.println("commit id is : " + c.getSha());
            System.out.println(" commit message is : " + c.getMessage());
            System.out.println(" author of the commit is : " + c.getAuthor());
            System.out.println(" date modified is : " + c.getDateString());
            System.out.println(" number of files changed is : " + c.getFiles());
            List<GitLogResponse.CommitFile> store = c.getFiles();
            if(store!=null)
            System.out.println("the number of files changed is : " + store.size());
            System.out.println("list of files changed is : " + c.getFilesChanged());

            System.out.println("total number of additions : " + c.getLinesDeleted());
            System.out.println("total number of merger : " + c.getMergeDetails());


        }

//        for(GitLogResponse.CommitFile c : dotGit.getLog())

    }
}

输出显示为:

Exception in thread "main" edu.nyu.cs.javagit.api.JavaGitException: 100002: Invalid path to git specified. { path=[C:\Program Files\Git\bin] }
    at edu.nyu.cs.javagit.api.JavaGitConfiguration.setGitPath(JavaGitConfiguration.java:220)
    at edu.nyu.cs.javagit.api.JavaGitConfiguration.setGitPath(JavaGitConfiguration.java:247)
    at modifiedlines.UseGit.main(UseGit.java:40)
Caused by: edu.nyu.cs.javagit.api.JavaGitException: 100002: Invalid path to git specified.
    at edu.nyu.cs.javagit.api.JavaGitConfiguration.determineGitVersion(JavaGitConfiguration.java:81)
    at edu.nyu.cs.javagit.api.JavaGitConfiguration.setGitPath(JavaGitConfiguration.java:217)
    ... 2 more
Java Result: 1

我的查询是如何使用 Java 程序查找 git 日志和因特定提交而更改的文件。 任何一位都可以帮助我吗?

请参阅: 此代码在 Ubuntu 中工作正常,即没有路径问题我仍然无法在提交期间更改文件。它给我一个空列表。

此错误已解决a long time ago and just fixed it. Please give it a try,请使用 master 分支,如果它对您有用,请告诉我。