0

I have list of path of new created/updated files that I want to add through JGit, but I have an issue while adding all those change file in the staging area.

With this syntax, I am not able to see these files in my commit:

final Git openedRepo = Git.open(gitFile);
 
for (String i : listOffile) {
    openedRepo.add().addFilepattern(i).call();
}

But when I use the below syntax, I am able to see all changes and created files in my commit:

final Git openedRepo = Git.open(gitFile);
openedRepo.add().addFilepattern(".").call();

Note: I am able to see files in my listOffile while logging.

Is there is any mistake with my first syntax/code?

Matt
  • 12,848
  • 2
  • 31
  • 53
  • You create the variable `openedRepo` but later use `openrepo`. I think `.call` is missing `()` at the end. Please [edit](https://stackoverflow.com/posts/68029134/edit) your answer to correct the code. Also, show us the contents of `listOffile`. – Matt Jun 18 '21 at 06:55
  • So if you are logging `listOffile` and it is empty, then the for-loop is skipped (no iteration). Hence, no files will get added as the command never executes. – Matt Jun 18 '21 at 07:07
  • This is the content of listOffile: /tmp/packageName/configuration/SomeRules/Workflow/SomeWorkflow/ActivityAutomation/SomeApp/ApproveApp.ion. **There are many path with some different files name* .I just show you one path above. – SATYAM MITTAL 17103094 Jun 18 '21 at 07:09
  • The path that you pass to `addFilepattern` must be relative to the root of the repository working directory. For example, to add the file `/path/to/repo/path/to/file` in repo `/path/to/repo` you need to call `addFilepattern("path/to/file")`. – Rüdiger Herrmann Jun 18 '21 at 07:42
  • Thanks Herrmann, It work now by adding relative-path instead of absolute path. – SATYAM MITTAL 17103094 Jun 18 '21 at 11:59

0 Answers0