Reputation: 445
I would like to add all the files from a specified directory using addFilepattern
to the git repository and commit the change after that. I am expecting to see the files in the commit when I do git show
but instead the commits exists but are empty.
This is the code:
//create target directory for jGit
File targetDirectory = new File("/Users/asusti/jGit/");
if (!targetDirectory.exists()) {
if (targetDirectory.mkdir()) {
System.out.println("jGit directory is created!");
} else {
System.out.println("jGit Directory exists!");
}
}
//create a new Git repository instance
// The Git-object has a static method to initialize a new repository
try (Git git = Git.init()
.setDirectory(targetDirectory)
.call()) {
System.out.println("Created a new repository at " + git.getRepository().getDirectory());
git.add().addFilepattern("/Users/asusti/Downloads").call();
git.commit().setMessage("Added yaml files to the repository.").setAuthor("anas", "[email protected]")
.call();
} catch (IllegalStateException | GitAPIException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Upvotes: 1
Views: 537
Reputation: 306
Try it
git.add().addFilepattern(".").call();
CommitCommand commit = git.commit();
commit.setMessage("Added yaml files to the repository.").call();
git.push().call();
Upvotes: 3