本文整理了Java中org.eclipse.jgit.api.Git.push()
方法的一些代码示例,展示了Git.push()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.push()
方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:push
[英]Return a command object to execute a Push command
[中]返回命令对象以执行推送命令
代码示例来源:origin: apache/incubator-gobblin
@Test (dependsOnMethods = "testDelete")
public void testGitCreate() throws Exception {
// push a new config file
File testFlowFile = new File(GIT_CLONE_DIR + "/gobblin-config/testGroup/testFlow.pull");
testFlowFile.getParentFile().mkdirs();
Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value20\n", testFlowFile, Charsets.UTF_8);
Collection<Spec> specs = this.gobblinServiceManager.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 0);
// add, commit, push
this.gitForPush.add().addFilepattern("gobblin-config/testGroup/testFlow.pull").call();
this.gitForPush.commit().setMessage("second commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
// polling is every 5 seconds, so wait twice as long and check
TimeUnit.SECONDS.sleep(10);
specs = this.gobblinServiceManager.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 1);
FlowSpec spec = (FlowSpec) (specs.iterator().next());
Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
Assert.assertEquals(spec.getConfig().getString("param1"), "value20");
}
代码示例来源:origin: apache/incubator-gobblin
@Test(dependsOnMethods = "testAddConfig")
public void testUpdateConfig() throws IOException, GitAPIException, URISyntaxException {
// push an updated config file
Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value2\n", testFlowFile, Charsets.UTF_8);
// add, commit, push
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
.call();
this.gitForPush.commit().setMessage("Third commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitConfigMonitor.processGitConfigChanges();
Collection<Spec> specs = this.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 1);
FlowSpec spec = (FlowSpec) (specs.iterator().next());
Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
Assert.assertEquals(spec.getConfig().getString("param1"), "value2");
}
代码示例来源:origin: apache/incubator-gobblin
@Test
public void testAddConfig() throws IOException, GitAPIException, URISyntaxException {
// push a new config file
this.testGroupDir.mkdirs();
this.testFlowFile.createNewFile();
Files.write("flow.name=testFlow\nflow.group=testGroup\nparam1=value1\n", testFlowFile, Charsets.UTF_8);
// add, commit, push
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
.call();
this.gitForPush.commit().setMessage("Second commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitConfigMonitor.processGitConfigChanges();
Collection<Spec> specs = this.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 1);
FlowSpec spec = (FlowSpec) (specs.iterator().next());
Assert.assertEquals(spec.getUri(), new URI("gobblin-flow:/testGroup/testFlow"));
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_NAME_KEY), "testFlow");
Assert.assertEquals(spec.getConfig().getString(ConfigurationKeys.FLOW_GROUP_KEY), "testGroup");
Assert.assertEquals(spec.getConfig().getString("param1"), "value1");
}
代码示例来源:origin: apache/incubator-gobblin
@Test (dependsOnMethods = "testUpdateNode")
public void testRemoveEdge() throws GitAPIException, IOException {
// delete a config file
edge1File.delete();
//Node1 has 1 edge before delete
Set<FlowEdge> edgeSet = this.flowGraph.getEdges("node1");
Assert.assertEquals(edgeSet.size(), 1);
// delete, commit, push
DirCache ac = this.gitForPush.rm().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(),
this.edge1Dir.getName(), this.edge1File.getName())).call();
RevCommit cc = this.gitForPush.commit().setMessage("Edge remove commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitFlowGraphMonitor.processGitConfigChanges();
//Check if edge1 has been deleted from the graph
edgeSet = this.flowGraph.getEdges("node1");
Assert.assertTrue(edgeSet.size() == 0);
}
代码示例来源:origin: apache/incubator-gobblin
.call();
this.gitForPush.commit().setMessage("Seventh commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
@Test(dependsOnMethods = "testUpdateConfig")
public void testDeleteConfig() throws IOException, GitAPIException, URISyntaxException {
// delete a config file
testFlowFile.delete();
// flow catalog has 1 entry before the config is deleted
Collection<Spec> specs = this.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 1);
// add, commit, push
DirCache ac = this.gitForPush.rm().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile.getName()))
.call();
RevCommit cc = this.gitForPush.commit().setMessage("Fourth commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitConfigMonitor.processGitConfigChanges();
specs = this.flowCatalog.getSpecs();
Assert.assertTrue(specs.size() == 0);
}
代码示例来源:origin: apache/incubator-gobblin
private void addEdge(File edgeDir, File edgeFile, String fileContents) throws IOException, GitAPIException {
createNewFile(edgeDir, edgeFile, fileContents);
// add, commit, push edge
this.gitForPush.add().addFilepattern(formEdgeFilePath(edgeDir.getParentFile().getName(), edgeDir.getName(), edgeFile.getName())).call();
this.gitForPush.commit().setMessage("Edge commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
}
代码示例来源:origin: apache/incubator-gobblin
this.gitForPush.push().setRemote("origin").setRefSpecs(new RefSpec("master")).call();
代码示例来源:origin: apache/incubator-gobblin
@Test (dependsOnMethods = "testAddNode")
public void testUpdateEdge()
throws IOException, GitAPIException, URISyntaxException, ExecutionException, InterruptedException {
//Update edge1 file
String fileContents = buildEdgeFileContents("node1", "node2", "edge1", "value2");
addEdge(this.edge1Dir, this.edge1File, fileContents);
// add, commit, push
this.gitForPush.add().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call();
this.gitForPush.commit().setMessage("Edge commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitFlowGraphMonitor.processGitConfigChanges();
//Check if new edge1 has been added to the FlowGraph
testIfEdgeSuccessfullyAdded("node1", "node2", "edge1", "value2");
}
代码示例来源:origin: apache/incubator-gobblin
@Test (dependsOnMethods = "testRemoveEdge")
public void testRemoveNode() throws GitAPIException, IOException {
//delete node files
node1File.delete();
node2File.delete();
//Ensure node1 and node2 are present in the graph before delete
DataNode node1 = this.flowGraph.getNode("node1");
Assert.assertNotNull(node1);
DataNode node2 = this.flowGraph.getNode("node2");
Assert.assertNotNull(node2);
// delete, commit, push
this.gitForPush.rm().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call();
this.gitForPush.rm().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call();
this.gitForPush.commit().setMessage("Node remove commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitFlowGraphMonitor.processGitConfigChanges();
//Check if node1 and node 2 have been deleted from the graph
node1 = this.flowGraph.getNode("node1");
Assert.assertNull(node1);
node2 = this.flowGraph.getNode("node2");
Assert.assertNull(node2);
}
代码示例来源:origin: apache/incubator-gobblin
.call();
this.gitForPush.commit().setMessage("Fifth commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
.call();
this.gitForPush.commit().setMessage("Sixth commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.push().setForce(true).setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
private void addNode(File nodeDir, File nodeFile, String fileContents) throws IOException, GitAPIException {
createNewFile(nodeDir, nodeFile, fileContents);
// add, commit, push node
this.gitForPush.add().addFilepattern(formNodeFilePath(nodeDir.getName(), nodeFile.getName())).call();
this.gitForPush.commit().setMessage("Node commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
}
代码示例来源:origin: apache/incubator-gobblin
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node2Dir.getName(), this.node2File.getName())).call();
this.gitForPush.commit().setMessage("Add nodes commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.rm().addFilepattern(formEdgeFilePath(this.edge1Dir.getParentFile().getName(), this.edge1Dir.getName(), this.edge1File.getName())).call();
this.gitForPush.commit().setMessage("Delete node1 and edge1 commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.add().addFilepattern(formNodeFilePath(this.node1Dir.getName(), this.node1File.getName())).call();
this.gitForPush.commit().setMessage("Add node1 commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
@BeforeClass
public void setup() throws Exception {
cleanUpDir(TEST_DIR);
// Create a bare repository
RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED);
this.remoteRepo = fileKey.open(false);
this.remoteRepo.create(true);
this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();
// push an empty commit as a base for detecting changes
this.gitForPush.commit().setMessage("First commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.config = ConfigBuilder.create()
.addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI,
this.remoteRepo.getDirectory().getAbsolutePath())
.addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig")
.addPrimitive(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog")
.addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5)
.build();
this.flowCatalog = new FlowCatalog(config);
this.flowCatalog.startAsync().awaitRunning();
this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog);
this.gitConfigMonitor.setActive(true);
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory push(String remote, ArrayMemory settings) throws GitAPIException {
PushCommand push = getWrappedObject().push();
代码示例来源:origin: centic9/jgit-cookbook
git.push()
.call();
代码示例来源:origin: FlowCI/flow-platform
/**
* Push code to remote repo
*
* @param path
* @param remote
* @param branchOrTag
* @return
* @throws GitException
*/
public static Path push(Path path, String remote, String branchOrTag) throws GitException {
try (Git git = Git.open(path.toFile())) {
git.push()
.setRemote(remote)
.setRefSpecs(new RefSpec(branchOrTag))
.call();
} catch (Throwable throwable) {
throw new GitException("Fail to Push ", throwable);
}
return path;
}
代码示例来源:origin: e-biz/androidkickstartr
public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException {
Repository repository = repositoryService.createRepository(new Repository().setName(applicationName));
String cloneUrl = repository.getCloneUrl();
InitCommand init = new InitCommand();
init.setDirectory(srcFolder);
init.setBare(false);
Git git = init.call();
StoredConfig config = git.getRepository().getConfig();
config.setString("remote", "origin", "url", cloneUrl);
config.save();
UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, "");
git.add().addFilepattern(".").call();
git.commit().setMessage(COMMIT_MESSAGE).call();
git.push().setCredentialsProvider(user).call();
return repository;
}
}
内容来源于网络,如有侵权,请联系作者删除!