public void pushRepo (String repoUrl, String gitdirectory, String username, String password) throws GitAPIException { Git git = null; try { git = Git.open(new File(gitdirectory)); } catch (IOException e1) { System.out.println("it is not git directory"); } RemoteAddCommand remoteAddCommand = git.remoteAdd(); remoteAddCommand.setName("origin"); try { remoteAddCommand.setUri(new URIish(repoUrl)); System.out.println("file added"); }catch (Exception e) { System.out.println("Invalid RemoteUrl"); } remoteAddCommand.call(); git.add().addFilepattern(".").call(); git.commit().setMessage("commited").call(); PushCommand pushCommand = git.push(); try { pushCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)); pushCommand.setRemote("origin").add("master").call(); System.out.println("push file"); }catch(Exception e) { System.out.println("Invalid username and password"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)