本文整理汇总了Java中org.eclipse.jgit.api.CommitCommand类的典型用法代码示例。如果您正苦于以下问题:Java CommitCommand类的具体用法?Java CommitCommand怎么用?Java CommitCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommitCommand类属于org.eclipse.jgit.api包,在下文中一共展示了CommitCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doRename
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
protected CommitInfo doRename(Git git, String oldPath, String newPath) throws Exception {
File file = getRelativeFile(oldPath);
File newFile = getRelativeFile(newPath);
if (file.exists()) {
File parentFile = newFile.getParentFile();
parentFile.mkdirs();
if (!parentFile.exists()) {
throw new IOException("Could not create directory " + parentFile + " when trying to move " + file + " to " + newFile + ". Maybe a file permission issue?");
}
file.renameTo(newFile);
String filePattern = getFilePattern(newPath);
git.add().addFilepattern(filePattern).call();
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(message);
return createCommitInfo(commitThenPush(git, commit));
} else {
return null;
}
}
示例2: doRemove
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
protected CommitInfo doRemove(Git git, List<String> paths) throws Exception {
if (paths != null && paths.size() > 0) {
int count = 0;
for (String path : paths) {
File file = getRelativeFile(path);
if (file.exists()) {
count++;
Files.recursiveDelete(file);
String filePattern = getFilePattern(path);
git.rm().addFilepattern(filePattern).call();
}
}
if (count > 0) {
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(message);
return createCommitInfo(commitThenPush(git, commit));
}
}
return null;
}
示例3: 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();
}
}
示例4: 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;
}
}
示例5: 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;
}
示例6: 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();
}
示例7: AccumuloConfigurations
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
public AccumuloConfigurations(Configuration config) throws Exception {
Preconditions.checkNotNull(config, "Configuration must be supplied");
gitDir = new File(config.getDataDir()+"/git");
LOG.debug("Creating Git repository at {}", gitDir);
if (!gitDir.exists()) {
if (!gitDir.mkdir()) {
throw new IOException("Error creating directory: "+gitDir.getAbsolutePath());
}
InitCommand initCommand = Git.init();
initCommand.setBare(false);
initCommand.setDirectory(gitDir);
git = initCommand.call();
CommitCommand commit = git.commit();
commit.setMessage("Initial commit").call();
repo = git.getRepository();
} else {
git = Git.open(gitDir);
repo = git.getRepository();
}
LOG.info("Accumulo configuration store initialized");
}
示例8: createGitRepoWithPom
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
public static String createGitRepoWithPom(final File path, final InputStream pom, final File... files) throws Exception {
File repo = new File(path, "repo");
if(repo.exists() == false) {
Files.createDirectory(repo.toPath());
}
Git git = Git.init().setDirectory(repo).call();
String gitUrl = "file://" + repo.getAbsolutePath();
FileUtils.copyInputStreamToFile(pom, new File(repo, "pom.xml"));
AddCommand add = git.add();
add.addFilepattern("pom.xml");
for (File f : files) {
add.addFilepattern(f.getName());
}
add.call();
CommitCommand commit = git.commit();
commit.setMessage("initial commit").call();
return gitUrl;
}
示例9: addAllAndCommit
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
static void addAllAndCommit(Git git, UserProfile user, String commitMsg) throws GitAPIException {
AddCommand addCommand = git.add()
.addFilepattern(".")
.addFilepattern("application.json");
CommitCommand commitCmd = git.commit();
if (user != null && user.name() != null && user.email() != null) {
commitCmd.setCommitter(user.name(), user.email());
}
if (commitMsg != null) {
commitCmd.setMessage(commitMsg);
}
GitHandler.commit(() -> {
addCommand.call();
return commitCmd.call();
});
}
示例10: 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);
}
}
示例11: doCreateDirectory
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
protected CommitInfo doCreateDirectory(Git git, String path) throws Exception {
File file = getRelativeFile(path);
if (file.exists()) {
return null;
}
file.mkdirs();
String filePattern = getFilePattern(path);
AddCommand add = git.add().addFilepattern(filePattern).addFilepattern(".");
add.call();
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(message);
RevCommit revCommit = commitThenPush(git, commit);
return createCommitInfo(revCommit);
}
示例12: doWrite
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
protected CommitInfo doWrite(Git git, String path, byte[] contents, PersonIdent personIdent, String commitMessage) throws Exception {
File file = getRelativeFile(path);
file.getParentFile().mkdirs();
Files.writeToFile(file, contents);
String filePattern = getFilePattern(path);
AddCommand add = git.add().addFilepattern(filePattern).addFilepattern(".");
add.call();
CommitCommand commit = git.commit().setAll(true).setAuthor(personIdent).setMessage(commitMessage);
RevCommit revCommit = commitThenPush(git, commit);
return createCommitInfo(revCommit);
}
示例13: 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;
}
示例14: dumpConfiguration
import org.eclipse.jgit.api.CommitCommand; //导入依赖的package包/类
public void dumpConfiguration(Configuration config, Entry e) throws Exception {
Preconditions.checkNotNull(config, "Configuration must be supplied.");
Preconditions.checkNotNull(e, "Entry must be supplied.");
AddCommand add = git.add();
CommitCommand commit = git.commit();
try {
//Dump Zookeeper
String instanceId = config.getConnector().getInstance().getInstanceID();
String zkPath = Constants.ZROOT + "/" + instanceId;
File zkDump = new File(gitDir, ZK_DUMP_FILE);
LOG.debug("Dump ZooKeeper configuration at {} to {}", zkPath, zkDump);
FileOutputStream out = new FileOutputStream(zkDump);
DumpZookeeper.run(out, zkPath);
out.close();
//Dump the configuration
LOG.debug("Dumping Accumulo configuration to {}", gitDir);
DumpConfigCommand command = new DumpConfigCommand();
command.allConfiguration = true;
command.directory = gitDir.getAbsolutePath();
Instance instance = config.getConnector().getInstance();
String principal = config.getUsername();
PasswordToken token = new PasswordToken(config.getPassword().getBytes());
Admin.printConfig(instance, principal, token, command);
//Add, commit, and tag
add.addFilepattern(".").call();
commit.setMessage("Backup " + e.getUUID().toString()).call();
git.tag().setName(e.getUUID().toString()).call();
LOG.debug("Git tag {} created.", e.getUUID());
//Should we remove all of the files from the existing git workspace?
} catch (Exception ex) {
LOG.error("Error saving configuration", ex);
git.reset().setMode(ResetType.HARD).setRef("HEAD").call();
throw ex;
}
}
示例15: 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);
}
}