Search in sources :

Example 26 with RefSpec

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();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 27 with RefSpec

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);
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PushResult(org.eclipse.jgit.transport.PushResult) PushCommand(org.eclipse.jgit.api.PushCommand)

Example 28 with RefSpec

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();
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) FetchCommand(org.eclipse.jgit.api.FetchCommand)

Example 29 with RefSpec

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);
}
Also used : RefSpec(org.eclipse.jgit.transport.RefSpec) PushResult(org.eclipse.jgit.transport.PushResult) PushCommand(org.eclipse.jgit.api.PushCommand)

Example 30 with RefSpec

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);
    }
}
Also used : StoredConfig(org.eclipse.jgit.lib.StoredConfig) URIish(org.eclipse.jgit.transport.URIish) RefSpec(org.eclipse.jgit.transport.RefSpec) GitException(org.eclipse.che.api.git.exception.GitException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) RemoteConfig(org.eclipse.jgit.transport.RemoteConfig)

Aggregations

RefSpec (org.eclipse.jgit.transport.RefSpec)46 Test (org.junit.Test)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)15 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)12 IOException (java.io.IOException)11 ObjectId (org.eclipse.jgit.lib.ObjectId)11 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)9 Git (org.eclipse.jgit.api.Git)8 PushCommand (org.eclipse.jgit.api.PushCommand)8 File (java.io.File)7 PushResult (org.eclipse.jgit.transport.PushResult)7 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)6 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)6 AppServicePlan (com.microsoft.azure.management.appservice.AppServicePlan)5 PublishingProfile (com.microsoft.azure.management.appservice.PublishingProfile)5 ArrayList (java.util.ArrayList)5 FetchCommand (org.eclipse.jgit.api.FetchCommand)5 ChangeApi (com.google.gerrit.extensions.api.changes.ChangeApi)4 CherryPickInput (com.google.gerrit.extensions.api.changes.CherryPickInput)4 GitException (org.eclipse.che.api.git.exception.GitException)4