jGit - how to add all files to staging area

前端 未结 3 1644
攒了一身酷
攒了一身酷 2021-01-01 16:47

I tried in a lot of ways to clone a repo with jGit (it works). Then, I write some archive in the repository, and tried to add all (a git add *, git add -A

3条回答
  •  一向
    一向 (楼主)
    2021-01-01 17:15

    One easy way to debug this is to look at the tests of the AddCommand in the JGit repo: AddCommandTest.java

    You will see that in order to add all files the pattern "*" is never used, but "." is.
    And it is used in the test function named... testAddWholeRepo()(!)

    git.add().addFilepattern(".").call();
    

    The Exception:

    Exception in thread "main" org.eclipse.jgit.errors.NoWorkTreeException: 
    Bare Repository has neither a working tree, nor an index
    

    is quite explicit: you need to add file in a non-bare repo.

    See test method testCloneRepository() to compare with your own clone, and see if there is any difference.

提交回复
热议问题