本文整理汇总了Java中org.eclipse.jgit.api.CommitCommand.call方法的典型用法代码示例。如果您正苦于以下问题:Java CommitCommand.call方法的具体用法?Java CommitCommand.call怎么用?Java CommitCommand.call使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.api.CommitCommand
的用法示例。
在下文中一共展示了CommitCommand.call方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFileAndCommitWithAuthor
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
private RevCommit writeFileAndCommitWithAuthor(Git git, String authorName, String email, String fileName, String commitMessage,
String... lines) throws IOException, GitAPIException {
StringBuilder sb = new StringBuilder();
for (String line : lines) {
sb.append(line);
sb.append('\n');
}
writeTrashFile(fileName, sb.toString());
git.add().addFilepattern(fileName).call();
CommitCommand commitCommand = git.commit().setMessage(commitMessage);
if (authorName != null && email != null) {
return commitCommand.setAuthor(authorName, email).call();
} else {
return commitCommand.call();
}
}
示例2: addAndCommitSelectedFiles
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
/**
* Adds the files that were selected and commits them. Note: the {@link AddCommand}
* and {@link CommitCommand} are used in this method. {@link AddCommand#setWorkingTreeIterator(WorkingTreeIterator)}
* can be configured fia {@link #setWorkingTreeIterator(WorkingTreeIterator)} before calling this method,
* and the {@code CommitCommand} can be configured via {@link #configureCommitCommand(CommitCommand)}.
* @return the result of {@link #createResult(DirCache, RevCommit, List)} or null if
* a {@link GitAPIException} is thrown.
*/
protected final R addAndCommitSelectedFiles() {
List<String> selectedFiles = getDialogPane().getSelectedFiles();
try {
AddCommand add = getGitOrThrow().add();
selectedFiles.forEach(add::addFilepattern);
workingTreeIterator.ifPresent(add::setWorkingTreeIterator);
DirCache cache = add.call();
CommitCommand commit = getGitOrThrow().commit();
configureCommitCommand(commit);
RevCommit revCommit = commit.call();
return createResult(cache, revCommit, selectedFiles);
} catch (GitAPIException e) {
handleGitAPIException(e);
return null;
}
}
示例3: doCommitAndPush
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
public static RevCommit doCommitAndPush(Git git, String message, UserDetails userDetails, PersonIdent author, String branch, String origin, boolean pushOnCommit) throws GitAPIException {
CommitCommand commit = git.commit().setAll(true).setMessage(message);
if (author != null) {
commit = commit.setAuthor(author);
}
RevCommit answer = commit.call();
if (LOG.isDebugEnabled()) {
LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage());
}
if (pushOnCommit) {
PushCommand push = git.push();
configureCommand(push, userDetails);
Iterable<PushResult> results = push.setRemote(origin).call();
for (PushResult result : results) {
if (LOG.isDebugEnabled()) {
LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates()));
}
}
}
return answer;
}
示例4: commit
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
@Override
public String commit(String author, String email, String message) {
RevCommit revCommit = null;
CommitCommand command = _git.commit();
command.setCommitter(author, email);
command.setMessage(message);
command.setAll(true);
try {
revCommit = command.call();
} catch (Throwable e) {
throw new RuntimeException("Failed to commit", e);
}
return revCommit.getId().getName();
}
示例5: commit
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
protected void commit(String comment) {
CommitCommand ci = git.commit();
ci.setMessage(comment);
ci.setAuthor(user);
ci.setCommitter(user);
try {
ci.call();
} catch (GitAPIException e) {
throw new RuntimeException(e);
}
}
示例6: commitThenPush
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
protected RevCommit commitThenPush(Git git, CommitCommand commit) throws Exception {
RevCommit answer = commit.call();
if (LOG.isDebugEnabled()) {
LOG.debug("Committed " + answer.getId() + " " + answer.getFullMessage());
}
if (isPushOnCommit()) {
Iterable<PushResult> results = doPush(git);
for (PushResult result : results) {
if (LOG.isDebugEnabled()) {
LOG.debug("Pushed " + result.getMessages() + " " + result.getURI() + " branch: " + branch + " updates: " + toString(result.getRemoteUpdates()));
}
}
}
return answer;
}
示例7: commit
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
RevCommit commit(String message) {
try {
CommitCommand commitCmd = git.commit().setAll(true).setMessage(message).setCommitter(getDefaultCommiter());
return commitCmd.call();
} catch (GitAPIException ex) {
throw new IllegalStateException("Cannot commit: " + message, ex);
}
}
示例8: commit
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
/** {@inheritDoc} */
public void commit(String message) throws GitException {
try (Repository repo = getRepository()) {
CommitCommand cmd = git(repo).commit().setMessage(message);
if (author!=null)
cmd.setAuthor(author);
if (committer!=null)
cmd.setCommitter(new PersonIdent(committer,new Date()));
cmd.call();
} catch (GitAPIException e) {
throw new GitException(e);
}
}
示例9: commitAll
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
/**
* Commit all.
*
* @param msg the msg
* @throws GitAPIException the git api exception
*/
public void commitAll(String msg) throws GitAPIException {
CommitCommand command = git.commit().setMessage(msg).setAll(true);
RevCommit result = command.call();
String message=result.getFullMessage();
if (message.length()>0){
Notification.show("Commit ok, message: " + message);
}else{
Notification.show("Commit ok, no commit message :( ?");
}
}
示例10: commit
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
public static void commit(Repo repo, boolean stageAll, boolean isAmend,
String msg, String authorName, String authorEmail) throws Exception, NoHeadException, NoMessageException,
UnmergedPathsException, ConcurrentRefUpdateException,
WrongRepositoryStateException, GitAPIException, StopTaskException {
Context context = SGitApplication.getContext();
StoredConfig config = repo.getGit().getRepository().getConfig();
String committerEmail = config.getString("user", null, "email");
String committerName = config.getString("user", null, "name");
if (committerName == null || committerName.equals("")) {
committerName = Profile.getUsername(context);
}
if (committerEmail == null || committerEmail.equals("")) {
committerEmail = Profile.getEmail(context);
}
if (committerName.isEmpty() || committerEmail.isEmpty()) {
throw new Exception("Please set your name and email");
}
if (msg.isEmpty()) {
throw new Exception("Please include a commit message");
}
CommitCommand cc = repo.getGit().commit()
.setCommitter(committerName, committerEmail).setAll(stageAll)
.setAmend(isAmend).setMessage(msg);
if (authorName != null && authorEmail != null) {
cc.setAuthor(authorName, authorEmail);
}
cc.call();
repo.updateLatestCommitInfo();
}
示例11: assertCodeChangeTriggersWorkingBuild
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
protected Build assertCodeChangeTriggersWorkingBuild(final String projectName, Build firstBuild) throws Exception {
File cloneDir = new File(getBasedir(), "target/projects/" + projectName);
String gitUrl = asserGetAppGitCloneURL(forgeClient, projectName);
Git git = ForgeClientAsserts.assertGitCloneRepo(gitUrl, cloneDir);
// lets make a dummy commit...
File readme = new File(cloneDir, "ReadMe.md");
boolean mustAdd = false;
String text = "";
if (readme.exists()) {
text = IOHelpers.readFully(readme);
} else {
mustAdd = true;
}
text += "\nupdated at: " + new Date();
Files.writeToFile(readme, text, Charset.defaultCharset());
if (mustAdd) {
AddCommand add = git.add().addFilepattern("*").addFilepattern(".");
add.call();
}
LOG.info("Committing change to " + readme);
CommitCommand commit = git.commit().setAll(true).setAuthor(forgeClient.getPersonIdent()).setMessage("dummy commit to trigger a rebuild");
commit.call();
PushCommand command = git.push();
command.setCredentialsProvider(forgeClient.createCredentialsProvider());
command.setRemote("origin").call();
LOG.info("Git pushed change to " + readme);
// now lets wait for the next build to start
int nextBuildNumber = firstBuild.getNumber() + 1;
Asserts.assertWaitFor(10 * 60 * 1000, new Block() {
@Override
public void invoke() throws Exception {
JobWithDetails job = assertJob(projectName);
Build lastBuild = job.getLastBuild();
assertThat(lastBuild.getNumber()).describedAs("Waiting for latest build for job " + projectName + " to start").isGreaterThanOrEqualTo(nextBuildNumber);
}
});
return ForgeClientAsserts.assertBuildCompletes(forgeClient, projectName);
}
示例12: build
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
/**
* Requires a bare repository. We clone to a random workspace
*
* @throws Exception
* @return The generator currently being worked on
*/
public UniqueBranchGenerator build() throws Exception {
Git git;
File workDirTarget = new File(repo.getDirectory().getAbsolutePath() + "/../../" + UUID.randomUUID().toString());
System.out.println(workDirTarget.getAbsolutePath());
Git.cloneRepository()
.setURI("file://" + repo.getDirectory().getAbsolutePath())
.setBare(false)
.setNoCheckout(false)
.setCloneAllBranches(true)
.setDirectory(workDirTarget).call().close();
File gitMetaDir = new File(workDirTarget.getAbsolutePath() + System.getProperty("file.separator") + ".git");
System.out.println("Setting .git metadata to work in directory: " + gitMetaDir.getAbsolutePath());
git = Git.open(gitMetaDir);
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(branchName);
createBranchCommand.call();
git.checkout().setName(branchName).call();
File repoRoot = git.getRepository().getWorkTree();
UUID rand = UUID.randomUUID();
File randomFile = new File(repoRoot, rand.toString() + ".log");
randomFile.createNewFile();
git.add().addFilepattern(".").call();
int cnt = 0;
for (String msg : commitMessages) {
FileUtils.writeStringToFile(randomFile, rand.toString() + "-" + cnt + "\n", true);
CommitCommand commitCommand = git.commit();
commitCommand.setMessage(msg);
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
cnt++;
}
git.push().setPushAll().call();
git.checkout().setName("master");
git.close();
FileUtils.deleteDirectory(workDirTarget);
return this;
}
示例13: createRepoWithoutBranches
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
/**
* Creates a bare git repository with initial commit and a 'readme.md' file
* containing one line. Author and email is set on commit.
*
* @param repoFolderName
* @return
* @throws IOException
* @throws GitAPIException
*/
public static Repository createRepoWithoutBranches(String repoFolderName) throws IOException, GitAPIException {
//'git init --bare test.git' :
//Initialized empty Git repository in /home/bue/gitlab-repos/pretested-integration-plugin/test.git/
//'ls -al test.git/' :
//total 40
//drwxrwxr-x 7 doe usr 4096 dec 11 00:23 .
//drwxrwxr-x 12 doe usr 4096 dec 11 00:23 ..
//drwxrwxr-x 2 doe usr 4096 dec 11 00:23 branches
//-rw-rw-r-- 1 doe usr 66 dec 11 00:23 config
//-rw-rw-r-- 1 doe usr 73 dec 11 00:23 description
//-rw-rw-r-- 1 doe usr 23 dec 11 00:23 HEAD
//drwxrwxr-x 2 doe usr 4096 dec 11 00:23 hooks
//drwxrwxr-x 2 doe usr 4096 dec 11 00:23 info
//drwxrwxr-x 4 doe usr 4096 dec 11 00:23 objects
//drwxrwxr-x 4 doe usr 4096 dec 11 00:23 refs
File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
File workDirForRepo = new File(WORKDIR, repoFolderName);
System.out.format(workDirForRepo.getAbsolutePath());
if (repo.exists()) {
System.out.format("EXIST:" + repo.getAbsolutePath());
try {
TestUtilsFactory.destroyDirectory(repo);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
Repository repository = new FileRepository(repo);
repository.create(true);
Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();
Git git = Git.open(workDirForRepo);
File readme = new File(workDirForRepo, "readme.md");
if (!readme.exists()) {
FileUtils.writeStringToFile(readme, "#My first repository");
}
git.add().addFilepattern(".");
CommitCommand commit = git.commit();
commit.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, repository.getBranch(), "Initial commit"));
commit.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commit.call();
git.push().setPushAll().setRemote("origin").call();
git.close();
FileUtils.deleteDirectory(workDirForRepo);
return repository;
}
示例14: createValidRepository
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
public static Repository createValidRepository(String repoFolderName) throws IOException, GitAPIException {
File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
if (repo.exists()) {
System.out.format("EXIST:" + repo.getAbsolutePath());
try {
TestUtilsFactory.destroyDirectory(repo);
} catch (InterruptedException e) {
throw new IOException(e);
}
}
File workDirForRepo = new File(WORKDIR, repoFolderName);
Repository repository = new FileRepository(repo);
repository.create(true);
Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();
Git git = Git.open(workDirForRepo);
String FEATURE_BRANCH_NAME = "ready/feature_1";
File readme = new File(workDirForRepo + "/readme");
if (!readme.exists()) {
FileUtils.writeStringToFile(readme, "sample text\n");
}
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 1")).call();
FileUtils.writeStringToFile(readme, "changed sample text\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "commit message 2")).call();
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(FEATURE_BRANCH_NAME);
createBranchCommand.call();
git.checkout().setName(FEATURE_BRANCH_NAME).call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n", true);
git.add().addFilepattern(readme.getName()).call();
CommitCommand commitCommand = git.commit();
commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 1"));
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n", true);
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage(TestUtilsFactory.createCommitMessageForRepo(repoFolderName, git.getRepository().getBranch(), "feature 1 commit 2"));
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.push().setPushAll().call();
git.checkout().setName("master").call();
FileUtils.deleteDirectory(workDirForRepo);
return repository;
}
示例15: createRepositoryWithMergeConflict
import org.eclipse.jgit.api.CommitCommand; //导入方法依赖的package包/类
public static Repository createRepositoryWithMergeConflict(String repoFolderName) throws IOException, GitAPIException {
String FEATURE_BRANCH_NAME = "ready/feature_1";
File repo = new File(WORKDIR,repoFolderName + ".git"); // bare repo should have suffix .git, and contain what normally in .git
File workDirForRepo = new File(WORKDIR, repoFolderName);
Repository repository = new FileRepository(repo);
repository.create(true);
Git.cloneRepository().setURI("file:///" + repo.getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();
Git git = Git.open(workDirForRepo);
File readme = new File(workDirForRepo + "/readme");
if (!readme.exists()) {
FileUtils.writeStringToFile(readme, "sample text\n");
}
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 1").call();
FileUtils.writeStringToFile(readme, "changed sample text\n");
git.add().addFilepattern(readme.getName()).call();
git.commit().setMessage("commit message 2").call();
CreateBranchCommand createBranchCommand = git.branchCreate();
createBranchCommand.setName(FEATURE_BRANCH_NAME);
createBranchCommand.call();
git.checkout().setName(FEATURE_BRANCH_NAME).call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 1\n");
git.add().addFilepattern(readme.getName()).call();
CommitCommand commitCommand = git.commit();
commitCommand.setMessage("feature 1 commit 1");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
FileUtils.writeStringToFile(readme, "FEATURE_1 branch commit 2\n");
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage("feature 1 commit 2");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.checkout().setName("master").call();
FileUtils.writeStringToFile(readme, "Merge conflict branch commit 2\n");
git.add().addFilepattern(readme.getName()).call();
commitCommand = git.commit();
commitCommand.setMessage("merge conflict message 1");
commitCommand.setAuthor(AUTHOR_NAME, AUTHOR_EMAIL);
commitCommand.call();
git.push().setPushAll().call();
FileUtils.deleteDirectory(workDirForRepo);
return repository;
}