Skip to main content
summaryrefslogtreecommitdiffstats
blob: f61664e13f648d5f79e8697c0db8f20cb336234a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/*******************************************************************************
 * Copyright (C) 2015, Max Hohenegger <eclipse@hohenegger.eu>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.gitflow.op;

import java.io.IOException;

import static java.lang.String.format;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;

import static org.eclipse.egit.gitflow.Activator.error;
import static org.eclipse.jgit.lib.Constants.*;

import org.eclipse.egit.gitflow.GitFlowRepository;
import org.eclipse.egit.gitflow.WrongGitFlowStateException;
import org.eclipse.egit.gitflow.internal.CoreText;
import org.eclipse.jgit.errors.AmbiguousObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.osgi.util.NLS;

/**
 * git flow release start
 */
public final class ReleaseStartOperation extends AbstractReleaseOperation {
	private String startCommitSha1;

	/**
	 * start release from given commit
	 *
	 * @param repository
	 * @param startCommitSha1
	 * @param releaseName
	 */
	public ReleaseStartOperation(GitFlowRepository repository,
			String startCommitSha1, String releaseName) {
		super(repository, releaseName);
		this.startCommitSha1 = startCommitSha1;
	}

	/**
	 * start release from HEAD
	 *
	 * @param repository
	 * @param releaseName
	 * @throws WrongGitFlowStateException
	 */
	public ReleaseStartOperation(GitFlowRepository repository,
			String releaseName) throws WrongGitFlowStateException {
		super(repository, releaseName);
		this.startCommitSha1 = repository.findHead().getName();
	}

	@Override
	public void execute(IProgressMonitor monitor) throws CoreException {
		String branchName = repository.getConfig().getReleaseBranchName(versionName);

		try {
			if (releaseExists()) {
				throw new CoreException(
						error(format(
								CoreText.ReleaseStartOperation_releaseNameAlreadyExists,
								versionName)));
			}
			if (!repository.isDevelop()) {
				throw new CoreException(
						error(NLS.bind(CoreText.ReleaseStartOperation_notOn, repository.getConfig().getDevelop())));
			}
		} catch (IOException e) {
			throw new CoreException(error(e.getMessage(), e));
		}

		RevCommit commit = repository.findCommit(startCommitSha1);
		if (commit == null) {
			throw new IllegalStateException(NLS.bind(CoreText.ReleaseStartOperation_unableToFindCommit, commit));
		}
		start(monitor, branchName, commit);
	}

	/**
	 * @return whether or not the given versionName exists
	 * @throws RevisionSyntaxException
	 * @throws AmbiguousObjectException
	 * @throws IncorrectObjectTypeException
	 * @throws IOException
	 */
	public boolean releaseExists()
			throws RevisionSyntaxException, AmbiguousObjectException,
			IncorrectObjectTypeException, IOException {
		return null != repository.getRepository().resolve(
				R_TAGS + repository.getConfig().getVersionTagPrefix() + versionName);
	}
}

Back to the top