I'm trying to perform a rename of a file from say "XXX.txt" to "YYY.txt" residing in a remote GIT repository.
I used the following code snippets using JGit API:
File file = new File( repository.getWorkTree(), "XXX.txt" );
File renameFile = new File( repository.getWorkTree(), "YYY.txt" );
file.renameTo(renameFile);
git.add().addFilepattern("YYY.txt").call();
git.rm().addFilepattern("XXX.txt").call();
CommitCommand commit = git.commit();
commit.setCommitter("Raguram", "raguramm@amius.co.in").setMessage("push command");
commit.call();
// Code for Pushing the commit to a remote repo
The above code doesn't work and still my index file is not getting updated with the new name [YYY.txt] rather it still contains the old name [XXX.txt].
I referred the link How do I rename a file in JGit which states a similar thing, but coudn't able to rename a file.
Anything I'm missing? Suggestions will be appreciated.