I am trying to push a project into gitlab from java. I cloned it successfully but I am not able to push with changes(adding some more files or adding more information to existing file.). The code does not contain any error but it is not updated in gitlab.
Here is my code
File localPath = File.createTempFile("TestGitRepository", "");
if(!localPath.delete()) {
throw new IOException("Could not delete temporary file " +
localPath);
}
Git git = Git.cloneRepository()
.setURI( REMOTE_URL )
.setDirectory(localPath)
.setCredentialsProvider( cp )
.call();
System.out.println("Cloning from " + REMOTE_URL + " to " + localPath);
// Git git=Git.open(dir);
File file = new File( git.getRepository().getWorkTree(), "file" + new Object().hashCode() );
System.out.println("hi");
file.createNewFile();
git.add().addFilepattern( file.getName() ).call();
git.commit().setMessage( "Add file " + file.getName() ).call();
git.push() .setCredentialsProvider( cp ) .call();
System.out.println("Pushed from repository: " + localPath + " to remote repository at " + REMOTE_URL);