I want to add to the index all the modifications made in a folder:
- files modified
- files added
- files removed
File gitDir = new File("/home/franck/Repositories/Git/Sandbox/.git");
try (Repository repo = new RepositoryBuilder().setGitDir(gitDir).build()){
try (Git git = new Git(repo)){
final Status status = git.status().addPath("testGit").call();
final AddCommand addCommand = git.add();
Set<String> removed = status.getRemoved();
for (final String s : removed) {
System.out.print("removed: "+s);
addCommand.addFilepattern(s);
}
Set<String> missing = status.getMissing();
for (final String s : missing) {
System.out.print("Missing: "+s);
addCommand.addFilepattern(s);
}
addCommand.call();
}
}
Output of this command:
Missing: testGit/test.txt
And output of git status
:
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add/rm <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
deleted: testGit/test.txt
no changes added to commit (use "git add" and/or "git commit -a")
Deleted file is not added to the index. How can I achieve this?
I checked testAddRemovedCommittedFile, it seems adding a deletion makes nothing.