Skip to content

Commit

Permalink
Merge branch 'release/0.7.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
OpherV committed May 3, 2020
2 parents 9058f74 + e2f8e85 commit b41850b
Show file tree
Hide file tree
Showing 24 changed files with 333 additions and 169 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ Feedback and suggestions are also very welcome.
## License

This plugin is under the [Apache 2.0 license](http://www.apache.org/licenses/LICENSE-2.0.html).
Copyright 2013-2019, Opher Vishnia.
Copyright 2013-2020, Opher Vishnia.


20 changes: 14 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
plugins {
id 'java'
id 'org.jetbrains.intellij' version '0.4.7'
id 'org.jetbrains.intellij' version '0.4.18'
}

compileJava {
options.compilerArgs += ["-Xlint"]
}

group 'gitflow4idea'
version '0.7.1'
version '0.7.2'

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
Expand All @@ -22,18 +22,26 @@ dependencies {
}

intellij {
version '2019.3'
version '2020.1'
plugins 'git4idea', 'tasks'
}

patchPluginXml {
pluginId "Gitflow"
pluginDescription 'Git Flow Integration'
version '0.7.1'
sinceBuild '182.0'
untilBuild '193.*'
version '0.7.2'
sinceBuild '201.0'
untilBuild '201.*'
changeNotes """
<H2>Changelog for 0.7.2</H2>
<ul>
<li>Support for Idea build 200 #276 (@fabmars, @tumb1er )</li>
<li>Fix Icon cannot be found in 'AllIcons.Vcs.' #286 (@fabmars)</li>
<li>Fix finish release error (Mac OS) #273 (@opherv)</li>
<li>Breaking 'Search Everywhere' dialog window for projects without git #265 (@opherv)</li>
</ul>
<H2>Changelog for 0.7.1</H2>
<ul>
<li>Support for Idea build 193 #259 (@opherv)</li>
Expand Down
4 changes: 2 additions & 2 deletions docs/project_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ And that's it. You can now make changes to the source and run them.

#### Language level

This project is written to target Java 6, so make sure to set the project language level appropriately
to avoid accidentally using newer features. You can do so in the module settings under "modules -> gitflow4idea -> sources -> Language level".
This project is written to target Java 8, so make sure to set the project language level appropriately
to avoid accidentally using newer features. You can do so in the module settings under "modules -> gitflow4idea -> sources -> Language level".
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
2 changes: 2 additions & 0 deletions src/main/java/gitflow/Gitflow.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package gitflow;

import com.intellij.openapi.project.Project;
import git4idea.commands.Git;
import git4idea.commands.GitCommandResult;
import git4idea.commands.GitLineHandlerListener;
Expand Down Expand Up @@ -109,4 +110,5 @@ GitCommandResult trackBugfix(@NotNull GitRepository repository,
@NotNull GitRemote remote,
@Nullable GitLineHandlerListener... listeners);

GitCommandResult version(@NotNull Project project, GitLineHandlerListener... listeners);
}
55 changes: 12 additions & 43 deletions src/main/java/gitflow/GitflowComponent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gitflow;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.ProjectComponent;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ProjectLevelVcsManager;
import com.intellij.openapi.vcs.VcsListener;
Expand All @@ -11,73 +10,43 @@
import com.intellij.openapi.wm.WindowManager;
import com.intellij.util.messages.MessageBus;
import git4idea.GitVcs;
import gitflow.ui.GitflowUnsupportedVersionWidget;
import gitflow.ui.GitflowWidget;
import org.jetbrains.annotations.NotNull;


/**
* @author Opher Vishnia / opherv.com / [email protected]
* One instance per project
*/
public class GitflowComponent implements ProjectComponent, VcsListener {
public class GitflowComponent implements VcsListener, Disposable {
Project myProject;
GitflowWidget myGitflowWidget;
MessageBus messageBus;

public GitflowComponent(Project project) {
myProject = project;
}

public void initComponent() {
messageBus = myProject.getMessageBus();
messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this);
// Seems the event triggering this component happens after the directory mapping change
directoryMappingChanged();
}

public void disposeComponent() {
@Override
public void dispose() {
// TODO: insert component disposal logic here
}

@NotNull
public String getComponentName() {
return "GitflowComponent";
}

public void projectOpened() {

}

public void projectClosed() {

}

@Override
public void directoryMappingChanged() {
VcsRoot[] vcsRoots = ProjectLevelVcsManager.getInstance(myProject).getAllVcsRoots();
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);

//git repo present
if (vcsRoots.length > 0 && vcsRoots[0].getVcs() instanceof GitVcs) {


StatusBarWidget widgetToAdd;

//make sure to not reinitialize the widget if it's already present
if (GitflowVersionTester.isSupportedVersion() && myGitflowWidget == null) {
myGitflowWidget = new GitflowWidget(myProject);
widgetToAdd = (StatusBarWidget) myGitflowWidget;
StatusBar statusBar = WindowManager.getInstance().getStatusBar(myProject);
GitflowWidget widget = (GitflowWidget) statusBar.getWidget(GitflowWidget.class.getName());
if (widget != null) {
widget.updateAsync();
} else {
widgetToAdd = new GitflowUnsupportedVersionWidget(myProject);
throw new NullPointerException("widget");
}

if (statusBar != null) {
statusBar.addWidget(widgetToAdd, "after " + git4idea.ui.branch.GitBranchWidget.class.getName(), myProject);
}
} else {
if (myGitflowWidget != null) {
myGitflowWidget.deactivate();
}
myGitflowWidget = null;
}
}

}
26 changes: 22 additions & 4 deletions src/main/java/gitflow/GitflowImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ public GitCommandResult finishRelease(@NotNull GitRepository repository,
addOptionsCommand(h, repository.getProject(),"RELEASE_keepBranch");
// addOptionsCommand(h, repository.getProject(),"RELEASE_squash");

h.addParameters(releaseName);

HashMap<String,String> dontTag = GitflowOptionsFactory.getOptionById("RELEASE_dontTag");
if (GitflowConfigurable.isOptionActive(repository.getProject(), dontTag.get("id"))){
h.addParameters(dontTag.get("flag"));
Expand All @@ -253,8 +255,6 @@ public GitCommandResult finishRelease(@NotNull GitRepository repository,
h.addParameters(tagMessage);
}

h.addParameters(releaseName);

for (GitLineHandlerListener listener : listeners) {
h.addLineListener(listener);
}
Expand Down Expand Up @@ -339,6 +339,8 @@ public GitCommandResult finishHotfix(@NotNull GitRepository repository,
addOptionsCommand(h, repository.getProject(),"HOTFIX_fetchFromOrigin");
addOptionsCommand(h, repository.getProject(),"HOTFIX_pushOnFinish");

h.addParameters(hotfixName);

HashMap<String,String> dontTag = GitflowOptionsFactory.getOptionById("HOTFIX_dontTag");
if (GitflowConfigurable.isOptionActive(repository.getProject(), dontTag.get("id"))){
h.addParameters(dontTag.get("flag"));
Expand All @@ -348,8 +350,6 @@ public GitCommandResult finishHotfix(@NotNull GitRepository repository,
h.addParameters(tagMessage);
}

h.addParameters(hotfixName);

for (GitLineHandlerListener listener : listeners) {
h.addLineListener(listener);
}
Expand Down Expand Up @@ -491,4 +491,22 @@ public GitCommandResult trackBugfix(@NotNull GitRepository repository,
return runCommand(h);
}

@Override
public GitCommandResult version(@NotNull Project project, GitLineHandlerListener... listeners) {
//getProjectFile is null for default project.
if (project.isDefault()) {
throw new IllegalArgumentException("Cannot determine git flow version for default project");
} else {
assert project.getProjectFile() != null : "No project file for " + project;
}

final GitLineHandler h = new GitLineHandler(project, project.getProjectFile().getParent(), GitflowCommand());

h.addParameters("version");

for (GitLineHandlerListener listener : listeners) {
h.addLineListener(listener);
}
return runCommand(h);
}
}
90 changes: 67 additions & 23 deletions src/main/java/gitflow/GitflowVersionTester.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,75 @@
package gitflow;

import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.ExecutionException;
import com.intellij.execution.util.ExecUtil;
import com.intellij.execution.process.ProcessOutput;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nullable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class GitflowVersionTester {
static Boolean isSupportedVersion = null;

static boolean isSupportedVersion(){
if (isSupportedVersion == null) {

ProcessOutput output = null;
GeneralCommandLine commandLine = new GeneralCommandLine();
commandLine.setExePath("git");
commandLine.addParameters("flow");
commandLine.addParameters("version");
try {
output = ExecUtil.execAndGetOutput(commandLine);
} catch (ExecutionException e) {
e.printStackTrace();

private static final Logger logger = Logger.getInstance(GitflowVersionTester.class);

private static final Map<Project, GitflowVersionTester> testers = new ConcurrentHashMap<>();

public static GitflowVersionTester forProject(@NotNull Project project) {
return testers.computeIfAbsent(
project,
p -> {
Disposer.register(p, () -> testers.remove(p));
return new GitflowVersionTester(ServiceManager.getService(Gitflow.class), p);
}
String stdout = output.getStdout();
// System.out.println("output: " + stdout);
// test that the installed git flow CLI version is AVH and not the unmaintained NVIE version
isSupportedVersion = stdout.contains("AVH");
);
}

@NotNull private final Gitflow gitflow;
@NotNull private final Project project;

private String version = null;

private GitflowVersionTester(@NotNull Gitflow gitflow, @NotNull Project project) {
this.gitflow = gitflow;
this.project = project;
}

/**
* <p>Returns the installed {@code git-flow} version. The version
* is loaded on the first call to this method and is determined
* by looking at the output of a {@code git flow version} command.</p>
* <p>If the command fails, {@code null} is returned.</p>
*
* @return the {@code git flow} version, or {@code null}
*/
@Nullable
public String getVersion() {
return version;
}

/**
* Returns true if the {@code git flow} version can be determined
* and is any AVH version ({@code #contains("AVH")}) and
* not the unmaintained NVIE version.
*
* @return true if we think the git flow version is an AVH version.
*/
public boolean isSupportedVersion() {
return version != null && version.contains("AVH");
}

public void init(){
String returnedVersion = null;
try {
returnedVersion = gitflow.version(project).getOutputOrThrow();
logger.info("git flow version: " + version);
} catch (Exception e) {
logger.error("Could not determine git flow version", e);
}
if (returnedVersion != null){
version = returnedVersion;
}
return isSupportedVersion;
}
}
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishBugfixAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)){
that.runAction(project, bugfixName);
FinishBugfixAction completeFinishBugfixAction = new FinishBugfixAction(myRepo, bugfixName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishFeatureAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()){
if (handleMerge(project)) {
that.runAction(project, featureName);
FinishFeatureAction completeFinishFeatureAction = new FinishFeatureAction(myRepo, featureName);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/gitflow/actions/FinishReleaseAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void onSuccess() {

//merge conflicts if necessary
if (errorLineHandler.hasMergeError){
if (handleMerge()) {
if (handleMerge(myProject)) {
FinishReleaseAction completeFinisReleaseAction = new FinishReleaseAction(releaseName, tagMessage);
completeFinisReleaseAction.actionPerformed(event);
}
Expand Down
Loading

0 comments on commit b41850b

Please sign in to comment.