本文整理汇总了Java中org.eclipse.jgit.transport.PushResult类的典型用法代码示例。如果您正苦于以下问题:Java PushResult类的具体用法?Java PushResult怎么用?Java PushResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PushResult类属于org.eclipse.jgit.transport包,在下文中一共展示了PushResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldShowSuccessWhenPushSucceeds
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
public void shouldShowSuccessWhenPushSucceeds() throws Exception {
XulMessageBox message = spy( new XulMessageBoxMock( XulDialogCallback.Status.ACCEPT ) );
when( document.createElement( MESSAGEBOX ) ).thenReturn( message );
doReturn( true ).when( uiGit ).hasRemote();
PushResult result = mock( PushResult.class );
doReturn( new URIish( "https://test.example.com" ) ).when( result ).getURI();
RemoteRefUpdate update = mock( RemoteRefUpdate.class );
when( update.getStatus() ).thenReturn( Status.OK );
when( result.getRemoteUpdates() ).thenReturn( Arrays.asList( update ) );
controller.push();
controller.push( IVCS.TYPE_BRANCH );
verify( uiGit ).push( "default" );
verify( uiGit ).push( IVCS.TYPE_BRANCH );
}
示例2: backup
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
public synchronized void backup() throws Exception {
repo.add().setUpdate(false).addFilepattern(".").call();
Status status = repo.status().setIgnoreSubmodules(SubmoduleWalk.IgnoreSubmoduleMode.ALL).call();
log.debug("status.getUncommittedChanges() = " + status.getUncommittedChanges());
if (!status.getUncommittedChanges().isEmpty()) {
for (String missingPath : status.getMissing()) {
repo.rm().addFilepattern(missingPath).call();
}
log.info("Changes detected in the following files: " + status.getUncommittedChanges());
repo.commit()
.setMessage("Backing up data dir")
.setAuthor("AppRunner BackupService", "[email protected]")
.call();
Iterable<PushResult> pushResults = repo.push().call();
for (PushResult pushResult : pushResults) {
log.info("Result of pushing to remote: " + pushResult.getRemoteUpdates());
}
} else {
log.info("No changes to back up");
}
}
示例3: pushToRepository
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
/**
* Push all changes and tags to given remote.
*
* @param git
* instance.
* @param remote
* to be used.
* @param passphrase
* to access private key.
* @param privateKey
* file location.
*
* @return List of all results of given push.
*/
public Iterable<PushResult> pushToRepository(Git git, String remote, String passphrase, Path privateKey) {
SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host host, Session session) {
session.setUserInfo(new PassphraseUserInfo(passphrase));
}
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
if (privateKey != null) {
JSch defaultJSch = super.createDefaultJSch(fs);
defaultJSch.addIdentity(privateKey.toFile().getAbsolutePath());
return defaultJSch;
} else {
return super.createDefaultJSch(fs);
}
}
};
try {
return git.push()
.setRemote(remote)
.setPushAll()
.setPushTags()
.setTransportConfigCallback(transport -> {
SshTransport sshTransport = (SshTransport) transport;
sshTransport.setSshSessionFactory(sshSessionFactory);
})
.call();
} catch (GitAPIException e) {
throw new IllegalStateException(e);
}
}
示例4: doPush
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
protected void doPush(Exchange exchange, String operation) throws Exception {
Iterable<PushResult> result = null;
try {
if (ObjectHelper.isEmpty(endpoint.getRemotePath())) {
throw new IllegalArgumentException("Remote path must be specified to execute " + operation);
}
if (ObjectHelper.isNotEmpty(endpoint.getBranchName())) {
git.checkout().setCreateBranch(false).setName(endpoint.getBranchName()).call();
}
if (ObjectHelper.isNotEmpty(endpoint.getUsername()) && ObjectHelper.isNotEmpty(endpoint.getPassword())) {
UsernamePasswordCredentialsProvider credentials = new UsernamePasswordCredentialsProvider(endpoint.getUsername(), endpoint.getPassword());
result = git.push().setCredentialsProvider(credentials).setRemote(endpoint.getRemotePath()).call();
} else {
result = git.push().setRemote(endpoint.getRemotePath()).call();
}
} catch (Exception e) {
LOG.error("There was an error in Git " + operation + " operation");
throw e;
}
exchange.getOut().setBody(result);
}
示例5: processPushResult
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
private void processPushResult( Iterable<PushResult> resultIterable ) throws Exception {
resultIterable.forEach( result -> { // for each (push)url
StringBuilder sb = new StringBuilder();
result.getRemoteUpdates().stream()
.filter( update -> update.getStatus() != RemoteRefUpdate.Status.OK )
.filter( update -> update.getStatus() != RemoteRefUpdate.Status.UP_TO_DATE )
.forEach( update -> { // for each failed refspec
sb.append(
result.getURI().toString()
+ "\n" + update.getSrcRef().toString()
+ "\n" + update.getStatus().toString()
+ ( update.getMessage() == null ? "" : "\n" + update.getMessage() )
+ "\n\n"
);
} );
if ( sb.length() == 0 ) {
showMessageBox( BaseMessages.getString( PKG, "Dialog.Success" ), BaseMessages.getString( PKG, "Dialog.Success" ) );
} else {
showMessageBox( BaseMessages.getString( PKG, "Dialog.Error" ), sb.toString() );
}
} );
}
示例6: pushToRemote
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
/**
* Push git changes to remote git repository
*
* @param git Local git repository
* @param name Remote name
* @param url Remote Git url
* @return push result
* @throws WsSrvException
*/
public static String pushToRemote(Git git, String name, String url)
throws WsSrvException {
checkRemoteGitConfig(name, url);
try {
String res = "";
Iterable<PushResult> pres = git.push().setRemote(name).call();
for (PushResult r: pres)
res += r.getMessages();
return res;
} catch (GitAPIException e) {
throw new WsSrvException(249, e,
"Error push to remote [" + name + "]");
}
}
示例7: pushVia
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
private PushResult pushVia(Transport tn)
throws IOException, NotSupportedException, TransportException, PermissionBackendException {
tn.applyConfig(config);
tn.setCredentialsProvider(credentialsProvider);
List<RemoteRefUpdate> todo = generateUpdates(tn);
if (todo.isEmpty()) {
// If we have no commands selected, we have nothing to do.
// Calling JGit at this point would just redo the work we
// already did, and come up with the same answer. Instead
// send back an empty result.
return new PushResult();
}
repLog.info("Push to " + uri + " references: " + todo);
return tn.push(NullProgressMonitor.INSTANCE, todo);
}
示例8: doCommitAndPush
import org.eclipse.jgit.transport.PushResult; //导入依赖的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;
}
示例9: pushOne
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
public static PushResult pushOne(
TestRepository<?> testRepo,
String source,
String target,
boolean pushTags,
boolean force,
List<String> pushOptions)
throws GitAPIException {
PushCommand pushCmd = testRepo.git().push();
pushCmd.setForce(force);
pushCmd.setPushOptions(pushOptions);
pushCmd.setRefSpecs(new RefSpec((source != null ? source : "") + ":" + target));
if (pushTags) {
pushCmd.setPushTags();
}
Iterable<PushResult> r = pushCmd.call();
return Iterables.getOnlyElement(r);
}
示例10: pushInitialCommitForMasterBranch
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
@TestProjectInput(createEmptyCommit = false)
public void pushInitialCommitForMasterBranch() throws Exception {
RevCommit c = testRepo.commit().message("Initial commit").insertChangeId().create();
String id = GitUtil.getChangeId(testRepo, c).get();
testRepo.reset(c);
String r = "refs/for/master";
PushResult pr = pushHead(testRepo, r, false);
assertPushOk(pr, r);
ChangeInfo change = gApi.changes().id(id).info();
assertThat(change.branch).isEqualTo("master");
assertThat(change.status).isEqualTo(ChangeStatus.NEW);
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("master")).isNull();
}
gApi.changes().id(change.id).current().review(ReviewInput.approve());
gApi.changes().id(change.id).current().submit();
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("master")).isEqualTo(c);
}
}
示例11: pushInitialCommitForNormalNonExistingBranchFails
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
public void pushInitialCommitForNormalNonExistingBranchFails() throws Exception {
RevCommit c =
testRepo
.commit()
.message("Initial commit")
.author(admin.getIdent())
.committer(admin.getIdent())
.insertChangeId()
.create();
testRepo.reset(c);
String r = "refs/for/foo";
PushResult pr = pushHead(testRepo, r, false);
assertPushRejected(pr, r, "branch foo not found");
try (Repository repo = repoManager.openRepository(project)) {
assertThat(repo.resolve("foo")).isNull();
}
}
示例12: pushSameCommitTwiceUsingMagicBranchBaseOption
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
public void pushSameCommitTwiceUsingMagicBranchBaseOption() throws Exception {
grant(project, "refs/heads/master", Permission.PUSH);
PushOneCommit.Result rBase = pushTo("refs/heads/master");
rBase.assertOkStatus();
gApi.projects().name(project.get()).branch("foo").create(new BranchInput());
PushOneCommit push =
pushFactory.create(
db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "anotherContent");
PushOneCommit.Result r = push.to("refs/for/master");
r.assertOkStatus();
PushResult pr =
GitUtil.pushHead(testRepo, "refs/for/foo%base=" + rBase.getCommit().name(), false, false);
// BatchUpdate implementations differ in how they hook into progress monitors. We mostly just
// care that there is a new change.
assertThat(pr.getMessages()).containsMatch("changes: new: 1,( refs: 1)? done");
assertTwoChangesWithSameRevision(r);
}
示例13: mergedOptionWithNewCommitWithSameChangeIdFails
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
public void mergedOptionWithNewCommitWithSameChangeIdFails() throws Exception {
PushOneCommit.Result r = pushTo("refs/for/master");
r.assertOkStatus();
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(r.getChangeId()).current().submit();
RevCommit c2 =
testRepo
.amend(r.getCommit())
.message("New subject")
.insertChangeId(r.getChangeId().substring(1))
.create();
testRepo.reset(c2);
String ref = "refs/for/master%merged";
PushResult pr = pushHead(testRepo, ref, false);
RemoteRefUpdate rru = pr.getRemoteUpdate(ref);
assertThat(rru.getStatus()).isEqualTo(RemoteRefUpdate.Status.REJECTED_OTHER_REASON);
assertThat(rru.getMessage()).contains("not merged into branch");
}
示例14: maxBatchCommits
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@GerritConfig(name = "receive.maxBatchCommits", value = "2")
@Test
public void maxBatchCommits() throws Exception {
List<RevCommit> commits = new ArrayList<>();
commits.addAll(initChanges(2));
String master = "refs/heads/master";
assertPushOk(pushHead(testRepo, master), master);
commits.addAll(initChanges(3));
assertPushRejected(pushHead(testRepo, master), master, "too many commits");
grantSkipValidation(project, master, SystemGroupBackend.REGISTERED_USERS);
PushResult r =
pushHead(testRepo, master, false, false, ImmutableList.of(PUSH_OPTION_SKIP_VALIDATION));
assertPushOk(r, master);
// No open changes; branch was advanced.
String q = commits.stream().map(ObjectId::name).collect(joining(" OR commit:", "commit:", ""));
assertThat(gApi.changes().query(q).get()).isEmpty();
assertThat(gApi.projects().name(project.get()).branch(master).get().revision)
.isEqualTo(Iterables.getLast(commits).name());
}
示例15: allowedButNotSubscribed
import org.eclipse.jgit.transport.PushResult; //导入依赖的package包/类
@Test
public void allowedButNotSubscribed() throws Exception {
TestRepository<?> superRepo = createProjectWithPush("super-project");
TestRepository<?> subRepo = createProjectWithPush("subscribed-to-project");
allowMatchingSubmoduleSubscription(
"subscribed-to-project", "refs/heads/master", "super-project", "refs/heads/master");
pushChangeTo(subRepo, "master");
subRepo
.branch("HEAD")
.commit()
.insertChangeId()
.message("some change")
.add("b.txt", "b contents for testing")
.create();
String refspec = "HEAD:refs/heads/master";
PushResult r =
Iterables.getOnlyElement(
subRepo.git().push().setRemote("origin").setRefSpecs(new RefSpec(refspec)).call());
assertThat(r.getMessages()).doesNotContain("error");
assertThat(r.getRemoteUpdate("refs/heads/master").getStatus())
.isEqualTo(RemoteRefUpdate.Status.OK);
assertThat(hasSubmodule(superRepo, "master", "subscribed-to-project")).isFalse();
}