I am using Jgit api. I am able to create files in git remote location using the cloneRepository method.
Similarly I can add files using the addCommand. The requirement now is to create folders or update an existing folder with files in local and to push, commit the same to remote repository - https://github.com. I tried modifying the same code that we use for creating a file, but it is not working.
How can I achieve this? Code used for adding a file:
File file = new File(Trial.localPath + "\\" + fileName);
file.createNewFile();
UsernamePasswordCredentialsProvider upc = new UsernamePasswordCredentialsProvider(
userName, password);
git = Git.cloneRepository().setURI(remotePath).setDirectory(puppetDirFile).setCredentialsProvider(upc).call();
git.add().addFilepattern(fileName).call();
git.commit().setMessage("Added "+ fileName).call();
PushCommand pc = git.push();
pc.setCredentialsProvider(upc).setForce(true).setPushAll();
pc.call();
git.getRepository().close();
modified for adding folder :
File file = new File(Trial.localPath+"\\ProjectA");
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
}
}
git.add().addFilepattern("projectA").call();
git.commit().setMessage("Added "+ "ProjectA").call();
then rest pushed as the same above code.