I have written a java program to push to a git repository where I am pushing specific files at a time instead of pushing all files.
try {
git.add().addFilePattern("files\\file1.txt").call();
} catch (Exception e) {
e.printStackTrace();
}
But if file1.txt is not present, the catch block is not entered.
If I do the same thing with CLI Git, it gives exception as
fatal: pathspec 'D:\mygit\files\\file1.txt' did not match any files
I want to catch this exception in Java using JGit.
JGit version 4.6.0, Java 1.8, Windows 10
JGit does not consider it as an error to pass a non-existing path
addFilepatern(). The reason, therefore, could be that the method also accepts a file name pattern. And such a pattern may or may not match files.You will have to check the existence of the file yourself. Either with the Java file API, for example
Or through the
DirCachereturned fromAddCommand::call(), for example