本文整理了Java中org.eclipse.jgit.api.Git.commit()
方法的一些代码示例,展示了Git.commit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Git.commit()
方法的具体详情如下:
包路径:org.eclipse.jgit.api.Git
类名称:Git
方法名:commit
[英]Return a command object to execute a Commit command
[中]返回命令对象以执行提交命令
代码示例来源:origin: gocd/gocd
public void run() throws Exception {
addCommand.addFilepattern(CRUISE_CONFIG_XML).call();
git.commit().setAuthor(rev.getUsername(), STUDIOS_PRODUCT).setMessage(rev.getComment()).call();
}
});
代码示例来源: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
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.commit().setMessage("First commit").call();
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
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.commit().setMessage("First commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile2.getName()))
.call();
this.gitForPush.commit().setMessage("Fifth commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.add().addFilepattern(formConfigFilePath(this.testGroupDir.getName(), this.testFlowFile3.getName()))
.call();
this.gitForPush.commit().setMessage("Sixth commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
gitForPush.commit().setMessage("First commit").call();
RefSpec masterRefSpec = new RefSpec("master");
gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
gitForPush.commit().setMessage("Node commit").call();
gitForPush.push().setRemote("origin").setRefSpecs(masterRefSpec).call();
代码示例来源:origin: apache/incubator-gobblin
this.gitForPush.commit().setMessage("Add nodes commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.commit().setMessage("Add nodes and edges commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call();
this.gitForPush.commit().setMessage("Delete node1 and edge1 commit").call();
this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).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: centic9/jgit-cookbook
private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException {
// create the file
File myFile = new File(repository.getDirectory().getParent(), fileName);
FileUtils.writeStringToFile(myFile, content, "UTF-8");
// run the add
git.add()
.addFilepattern(fileName)
.call();
// and then commit the changes
RevCommit revCommit = git.commit()
.setMessage("Added " + fileName)
.call();
System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory());
}
}
代码示例来源:origin: centic9/jgit-cookbook
private static void createCommit(Repository repository, Git git, String fileName, String content) throws IOException, GitAPIException {
// create the file
File myFile = new File(repository.getDirectory().getParent(), fileName);
FileUtils.writeStringToFile(myFile, content, "UTF-8");
// run the add
git.add()
.addFilepattern(fileName)
.call();
// and then commit the changes
RevCommit revCommit = git.commit()
.setMessage("Added " + fileName)
.call();
System.out.println("Committed file " + myFile + " as " + revCommit + " to repository at " + repository.getDirectory());
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public Memory commit(String message, ArrayMemory settings) throws GitAPIException {
CommitCommand commit = getWrappedObject().commit();
commit.setMessage(message);
if (settings != null && settings.isNotNull()) {
commit.setAll(settings.valueOfIndex("all").toBoolean());
commit.setAllowEmpty(settings.valueOfIndex("allowEmpty").toBoolean());
commit.setAmend(settings.valueOfIndex("amend").toBoolean());
commit.setInsertChangeId(settings.valueOfIndex("insertChangeId").toBoolean());
commit.setNoVerify(settings.valueOfIndex("noVerify").toBoolean());
Memory author = settings.valueOfIndex("author");
if (author.isArray()) {
commit.setAuthor(author.valueOfIndex("name").toString(), author.valueOfIndex("email").toString());
}
Memory committer = settings.valueOfIndex("committer");
if (committer.isArray()) {
commit.setCommitter(committer.valueOfIndex("name").toString(), committer.valueOfIndex("email").toString());
}
if (settings.containsKey("only")) {
commit.setOnly(settings.valueOfIndex("only").toString());
}
if (settings.containsKey("reflogComment")) {
commit.setReflogComment(settings.valueOfIndex("reflogComment").toString());
}
}
RevCommit call = commit.call();
return GitUtils.valueOf(call);
}
内容来源于网络,如有侵权,请联系作者删除!