use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitWithCommitAndItsMergeCommitTogether.
@Test
public void submitWithCommitAndItsMergeCommitTogether() throws Exception {
assume().that(isSubmitWholeTopicEnabled()).isTrue();
RevCommit initialHead = getRemoteHead();
// Create a stable branch and bootstrap it.
gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo, "initial commit", "a.txt", "a");
PushOneCommit.Result change = push.to("refs/heads/stable");
RevCommit stable = getRemoteHead(project, "stable");
RevCommit master = getRemoteHead(project, "master");
assertThat(master).isEqualTo(initialHead);
assertThat(stable).isEqualTo(change.getCommit());
testRepo.git().fetch().call();
testRepo.git().branchCreate().setName("stable").setStartPoint(stable).call();
testRepo.git().branchCreate().setName("master").setStartPoint(master).call();
// Create a fix in stable branch.
testRepo.reset(stable);
RevCommit fix = testRepo.commit().parent(stable).message("small fix").add("b.txt", "b").insertChangeId().create();
testRepo.branch("refs/heads/stable").update(fix);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/stable:refs/for/stable/" + name("topic"))).call();
// Merge the fix into master.
testRepo.reset(master);
RevCommit merge = testRepo.commit().parent(master).parent(fix).message("Merge stable into master").insertChangeId().create();
testRepo.branch("refs/heads/master").update(merge);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/master:refs/for/master/" + name("topic"))).call();
// Submit together.
String fixId = GitUtil.getChangeId(testRepo, fix).get();
String mergeId = GitUtil.getChangeId(testRepo, merge).get();
approve(fixId);
approve(mergeId);
submit(mergeId);
assertMerged(fixId);
assertMerged(mergeId);
testRepo.git().fetch().call();
RevWalk rw = testRepo.getRevWalk();
master = rw.parseCommit(getRemoteHead(project, "master"));
assertThat(rw.isMergedInto(merge, master)).isTrue();
assertThat(rw.isMergedInto(fix, master)).isTrue();
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class GitUtil method pushOne.
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 + ":" + target));
if (pushTags) {
pushCmd.setPushTags();
}
Iterable<PushResult> r = pushCmd.call();
return Iterables.getOnlyElement(r);
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class GitUtil method fetch.
public static void fetch(TestRepository<?> testRepo, String spec) throws GitAPIException {
FetchCommand fetch = testRepo.git().fetch();
fetch.setRefSpecs(new RefSpec(spec));
fetch.call();
}
use of org.eclipse.jgit.transport.RefSpec in project gerrit by GerritCodeReview.
the class GitUtil method pushTag.
public static PushResult pushTag(TestRepository<?> testRepo, String tag, boolean force) throws GitAPIException {
PushCommand pushCmd = testRepo.git().push();
pushCmd.setForce(force);
pushCmd.setRefSpecs(new RefSpec("refs/tags/" + tag + ":refs/tags/" + tag));
Iterable<PushResult> r = pushCmd.call();
return Iterables.getOnlyElement(r);
}
use of org.eclipse.jgit.transport.RefSpec in project che by eclipse.
the class JGitConnection method remoteUpdate.
@Override
public void remoteUpdate(RemoteUpdateParams params) throws GitException {
String remoteName = params.getName();
if (isNullOrEmpty(remoteName)) {
throw new GitException(ERROR_UPDATE_REMOTE_NAME_MISSING);
}
StoredConfig config = repository.getConfig();
Set<String> remoteNames = config.getSubsections(ConfigConstants.CONFIG_KEY_REMOTE);
if (!remoteNames.contains(remoteName)) {
throw new GitException("Remote " + remoteName + " not found. ");
}
RemoteConfig remoteConfig;
try {
remoteConfig = new RemoteConfig(config, remoteName);
} catch (URISyntaxException e) {
throw new GitException(e.getMessage(), e);
}
List<String> branches = params.getBranches();
if (!branches.isEmpty()) {
if (!params.isAddBranches()) {
remoteConfig.setFetchRefSpecs(Collections.emptyList());
remoteConfig.setPushRefSpecs(Collections.emptyList());
} else {
// Replace wildcard refSpec if any.
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*").setForceUpdate(true));
remoteConfig.removeFetchRefSpec(new RefSpec(Constants.R_HEADS + "*" + ":" + Constants.R_REMOTES + remoteName + "/*"));
}
// Add new refSpec.
for (String branch : branches) {
remoteConfig.addFetchRefSpec(new RefSpec(Constants.R_HEADS + branch + ":" + Constants.R_REMOTES + remoteName + "/" + branch).setForceUpdate(true));
}
}
// Remove URLs first.
for (String url : params.getRemoveUrl()) {
try {
remoteConfig.removeURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add new URLs.
for (String url : params.getAddUrl()) {
try {
remoteConfig.addURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote url " + url + " is invalid. ");
}
}
// Remove URLs for pushing.
for (String url : params.getRemovePushUrl()) {
try {
remoteConfig.removePushURI(new URIish(url));
} catch (URISyntaxException e) {
LOG.debug(ERROR_UPDATE_REMOTE_REMOVE_INVALID_URL);
}
}
// Add URLs for pushing.
for (String url : params.getAddPushUrl()) {
try {
remoteConfig.addPushURI(new URIish(url));
} catch (URISyntaxException e) {
throw new GitException("Remote push url " + url + " is invalid. ");
}
}
remoteConfig.update(config);
try {
config.save();
} catch (IOException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
Aggregations