All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlassian.jgitflow.core.ReleasePublishCommand Maven / Gradle / Ivy

There is a newer version: 1.0-m5.1
Show newest version
package com.atlassian.jgitflow.core;

import java.io.IOException;

import com.atlassian.jgitflow.core.exception.*;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.util.StringUtils;

import static com.atlassian.jgitflow.core.util.Preconditions.checkState;

/**
 * Publishes release branch to the remote repository
 * 

* Examples (flow is a {@link com.atlassian.jgitflow.core.JGitFlow} instance): *

* Publish a hotfix: * *

 * flow.releasePublish("release").call();
 * 
*/ public class ReleasePublishCommand extends AbstractGitFlowCommand { private static final String SHORT_NAME = "release-publish"; private final String branchName; /** * Create a new release publish command instance. *

* An instance of this class is usually obtained by calling * {@link com.atlassian.jgitflow.core.JGitFlow#hotfixPublish(String)} * * @param name The name of the feature * @param git The git instance to use * @param gfConfig The GitFlowConfiguration to use */ public ReleasePublishCommand(String name, Git git, GitFlowConfiguration gfConfig, JGitFlowReporter reporter) { super(git, gfConfig, reporter); checkState(!StringUtils.isEmptyOrNull(name)); this.branchName = name; } /** * * @return nothing * @throws com.atlassian.jgitflow.core.exception.NotInitializedException * @throws com.atlassian.jgitflow.core.exception.JGitFlowGitAPIException * @throws com.atlassian.jgitflow.core.exception.DirtyWorkingTreeException * @throws com.atlassian.jgitflow.core.exception.JGitFlowIOException * @throws com.atlassian.jgitflow.core.exception.LocalBranchMissingException * @throws com.atlassian.jgitflow.core.exception.RemoteBranchExistsException */ @Override public Void call() throws NotInitializedException, JGitFlowGitAPIException, DirtyWorkingTreeException, JGitFlowIOException, LocalBranchMissingException, RemoteBranchExistsException { requireGitFlowInitialized(); String prefixedBranchName = gfConfig.getPrefixValue(JGitFlowConstants.PREFIXES.RELEASE.configKey()) + branchName; requireCleanWorkingTree(); requireLocalBranchExists(prefixedBranchName); try { git.fetch().setRemote("origin").call(); requireRemoteBranchAbsent(prefixedBranchName); //create remote hotfix branch RefSpec branchSpec = new RefSpec(prefixedBranchName + ":" + Constants.R_HEADS + prefixedBranchName); git.push().setRemote("origin").setRefSpecs(branchSpec).call(); git.fetch().setRemote("origin").call(); //setup tracking StoredConfig config = git.getRepository().getConfig(); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedBranchName, ConfigConstants.CONFIG_KEY_REMOTE, "origin"); config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, prefixedBranchName, ConfigConstants.CONFIG_KEY_MERGE, Constants.R_HEADS + prefixedBranchName); config.save(); //checkout the branch git.checkout().setName(prefixedBranchName).call(); } catch (IOException e) { throw new JGitFlowIOException(e); } catch (GitAPIException e) { throw new JGitFlowGitAPIException(e); } return null; } @Override protected String getCommandName() { return SHORT_NAME; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy