Reputation: 123
I am writing a scenario where I have to add a particular file present in a folder to the local git repository using add(). So I iterate in the folder all the files one by one and add them to local repository using add(). But somehow while checking on the console using git status these files are not added.
The code snippet is:
AddCommand cmd=git.add();
File[] fList = pathFolder.listFiles();
for (File file : fList){
if (file.isFile()){
try {
cmd.addFilepattern(file.getPath());
} catch (Exception e) {
e.printStackTrace();
}
}
}
try {
cmd.call();
} catch (GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Looking forward for some solution
Upvotes: 0
Views: 690
Reputation: 15872
I think you should not add the full path via file.getPath()
, but rather only the relative name, e.g. pathFolder.getName() + "/" + file.getName()
or something similar.
Another option would be to simply add the directory, this should add all files in that directory according to the JavaDoc
For a simple working example take a look at this snippet
Upvotes: 1