【发布时间】:2017-06-03 03:24:30
【问题描述】:
我正在尝试将项目从 java 推送到 gitlab。我成功克隆了它,但我无法推送更改(添加更多文件或向现有文件添加更多信息。)。代码不包含任何错误但在 gitlab 中没有更新。
这是我的代码
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);
【问题讨论】: