From d8dd8dd8c117d5aee08df9fad2585d988ce39e23 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Fri, 4 Sep 2015 12:11:03 +0200 Subject: [PATCH 01/18] Changed gitignore to ignore all *.iml files instead of one with a specific project name --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0fdb83c..b954802 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ *.zip *.jar out -gitflow.iml \ No newline at end of file +*.iml \ No newline at end of file From b9805839fd6ca9a98fa92962b14bf3a2653a5934 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Fri, 4 Sep 2015 12:20:46 +0200 Subject: [PATCH 02/18] Added a small guide how to setup the project for development --- docs/project_setup.md | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 docs/project_setup.md diff --git a/docs/project_setup.md b/docs/project_setup.md new file mode 100644 index 0000000..4c370a6 --- /dev/null +++ b/docs/project_setup.md @@ -0,0 +1,56 @@ +# Project setup help + +This is a quick overview how to setup the project for development. + +## 1. Make sure the plugin development plugin is enabled + +Start IDEA, go to Settings->Plugins and make sure that `Plugin DevKit` is installed and enabled. +If it's not, install it now. + +## 2. Clone the project + +## 3. Import the project into IDEA + +Select "Import Project" and navigate to the cloned repository when prompted. + * Chose "From existing sources" when prompted for a model + * At the SDK step (if you dont have a plugin SDK yet): Click `+` to add an SDK and select "IntelliJ Platform Plugin SDK" + - Navigate to your IDEA installation and select the installation directory. + - Afterwards select a JDK when prompted + * At the SDK step select your Plugin SDK (if you followed the previous step select the newly created SDK) + * The remaining options can be left at default + +## 4. Change the project type + +Open the projects iml file (it should be named `gitflow4idea.iml` by default) and replace its contents with this: + +``` + + + + + + + + + + + +``` + +Then close and reopen the project to apply the changes. + +## 5. Add git4idea dependency + +Open the module settings and navigate to modules -> gitflow4idea (or your project name here) -> dependencies. +Click add -> "JARs or directories" and add `git4idea.jar`. +This can be found in your IDEA installation directory under `plugins/git4idea/lib`. +Change the scope of the added JAR to **provided**. + +## 6. Create a run configuration + +Go to Run/Debug configurations and create a new configuration of the type `Plugin`. Under "Use classpath of module" select the project (`gitflow4idea` by default). +Run it. A new IDEA instance should start with the plugin running. + +And that's it. You can now make changes to the source and run them. + + From 2a70f2cd64dbe5f6049529bc1c03abc9e4160104 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Fri, 4 Sep 2015 12:25:51 +0200 Subject: [PATCH 03/18] Fixed some bad formatting in the setup guide --- docs/project_setup.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/project_setup.md b/docs/project_setup.md index 4c370a6..16ff418 100644 --- a/docs/project_setup.md +++ b/docs/project_setup.md @@ -12,12 +12,13 @@ If it's not, install it now. ## 3. Import the project into IDEA Select "Import Project" and navigate to the cloned repository when prompted. - * Chose "From existing sources" when prompted for a model - * At the SDK step (if you dont have a plugin SDK yet): Click `+` to add an SDK and select "IntelliJ Platform Plugin SDK" - - Navigate to your IDEA installation and select the installation directory. - - Afterwards select a JDK when prompted - * At the SDK step select your Plugin SDK (if you followed the previous step select the newly created SDK) - * The remaining options can be left at default + +* Chose "From existing sources" when prompted for a model +* At the SDK step (if you dont have a plugin SDK yet): Click `+` to add an SDK and select "IntelliJ Platform Plugin SDK" + - Navigate to your IDEA installation and select the installation directory. + - Afterwards select a JDK when prompted +* At the SDK step select your Plugin SDK (if you followed the previous step select the newly created SDK) +* The remaining options can be left at default ## 4. Change the project type From 405473c9d623132f2e4256caa427ca09b8a23102 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Fri, 4 Sep 2015 12:36:02 +0200 Subject: [PATCH 04/18] Reformatted project setup guide * more consistent formatting * syntax highlighting for github --- docs/project_setup.md | 43 ++++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 15 deletions(-) diff --git a/docs/project_setup.md b/docs/project_setup.md index 16ff418..e75085e 100644 --- a/docs/project_setup.md +++ b/docs/project_setup.md @@ -4,27 +4,40 @@ This is a quick overview how to setup the project for development. ## 1. Make sure the plugin development plugin is enabled -Start IDEA, go to Settings->Plugins and make sure that `Plugin DevKit` is installed and enabled. +Start IDEA, go to *Settings -> Plugins* and make sure that `Plugin DevKit` is installed and enabled. If it's not, install it now. -## 2. Clone the project +## 2. Clone the project from GitHub + +Typically you check out your fork of the project on GitHub here. ## 3. Import the project into IDEA -Select "Import Project" and navigate to the cloned repository when prompted. +Select the *Import Project* option (e.g. by pressing shift twice and entering "import project") +and navigate to the cloned repository directory when prompted. + +### Model + +Chose "From existing sources" when prompted for a model. -* Chose "From existing sources" when prompted for a model -* At the SDK step (if you dont have a plugin SDK yet): Click `+` to add an SDK and select "IntelliJ Platform Plugin SDK" - - Navigate to your IDEA installation and select the installation directory. - - Afterwards select a JDK when prompted -* At the SDK step select your Plugin SDK (if you followed the previous step select the newly created SDK) -* The remaining options can be left at default +### SDK Setup + +If you dont have a plugin SDK yet, click `+` to add an SDK and select *IntelliJ Platform Plugin SDK* + +1. Navigate to your IDEA installation and select the installation directory. +2. Afterwards select a JDK when prompted + +Select your plugin SDK as the one to use. + +### Other + +The remaining options can be left at default ## 4. Change the project type Open the projects iml file (it should be named `gitflow4idea.iml` by default) and replace its contents with this: -``` +```xml @@ -42,15 +55,15 @@ Then close and reopen the project to apply the changes. ## 5. Add git4idea dependency -Open the module settings and navigate to modules -> gitflow4idea (or your project name here) -> dependencies. -Click add -> "JARs or directories" and add `git4idea.jar`. -This can be found in your IDEA installation directory under `plugins/git4idea/lib`. -Change the scope of the added JAR to **provided**. +1. Open the module settings and navigate to *Modules -> gitflow4idea (or your project name here)* and select the *Dependencies* tab. +2. Click add -> "JARs or directories" and add `git4idea.jar`. + This can be found in your IDEA installation directory under `plugins/git4idea/lib`. +3. Change the scope of the added JAR to **provided**. ## 6. Create a run configuration Go to Run/Debug configurations and create a new configuration of the type `Plugin`. Under "Use classpath of module" select the project (`gitflow4idea` by default). -Run it. A new IDEA instance should start with the plugin running. +Click run. A new IDEA instance should start with the plugin running. And that's it. You can now make changes to the source and run them. From e0d071e63015944093e374120d7932ba250c8ff0 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Fri, 4 Sep 2015 13:14:29 +0200 Subject: [PATCH 05/18] Prefixed actions with "Gitflow:" ...to make action naming consistent with other plugins and to make searching for gitflow feature easier from the action or global search. Other plugins typically apply a prefix (like "git:" or "perforce:") if the action is specific to a single plugin. Prefixes are only omitted when they contribute to a global action (like commit, which exists for multiple VCS). Also added ellipsis (...) to the actions to indicate that further information is required and prompted for in the form of a dialog after the action is selected. See http://ux.stackexchange.com/questions/30420/what-are-the-rules-of-using-ellipsis-on-buttons for instance. --- META-INF/plugin.xml | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index dddc32a..0540850 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -17,23 +17,21 @@ - - - - - - - - - - - - - + + + + + + + + + + + + + - - gitflow.GitflowComponent From ba493a0f4c2ebb0bb5b467ed69c9ca616e0cd94a Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Sat, 5 Sep 2015 01:25:24 +0200 Subject: [PATCH 06/18] Issue #72: Fixed wrong prefixes The name of the development branch was outputted twice, which shifted all other prefixes by one. Now the second prompt just gets a simple newline instead, this seems to work on my machine (I could reproduce the issue on a local repo reliably). --- src/gitflow/GitInitLineHandler.java | 36 +++++++++++++++++------------ 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/gitflow/GitInitLineHandler.java b/src/gitflow/GitInitLineHandler.java index 5ae5dc5..94945f2 100644 --- a/src/gitflow/GitInitLineHandler.java +++ b/src/gitflow/GitInitLineHandler.java @@ -4,24 +4,25 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Key; import com.intellij.openapi.vfs.VirtualFile; -import git4idea.commands.GitCommand; -import git4idea.commands.GitLineHandler; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; -import java.io.PrintWriter; + +import git4idea.commands.GitCommand; +import git4idea.commands.GitLineHandler; public class GitInitLineHandler extends GitLineHandler { private BufferedWriter writer; GitflowInitOptions _initOptions; - public GitInitLineHandler(GitflowInitOptions initOptions,@NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull GitCommand command) { + public GitInitLineHandler(GitflowInitOptions initOptions, @NotNull Project project, @NotNull VirtualFile vcsRoot, @NotNull GitCommand command) { super(project, vcsRoot, command); - _initOptions=initOptions; + _initOptions = initOptions; } @Nullable @@ -39,54 +40,59 @@ protected void processTerminated(final int exitCode) { @Override protected void onTextAvailable(String s, Key key) { - super.onTextAvailable(s,key); + super.onTextAvailable(s, key); try { - if (s.contains("Branch name for production releases")){ + if (s.contains("Branch name for production releases")) { writer.write(_initOptions.getProductionBranch()); myVcs.showCommandLine(_initOptions.getProductionBranch()); writer.newLine(); writer.flush(); } - if (s.contains("Branch name for \"next release\"") || - s.contains("Which branch should be used for integration of the")){ + if (s.contains("Branch name for \"next release\"")) { writer.write(_initOptions.getDevelopmentBranch()); myVcs.showCommandLine(_initOptions.getDevelopmentBranch()); writer.newLine(); writer.flush(); } - if (s.contains("Feature branches")){ + + if (s.contains("Which branch should be used for integration of the")) { + writer.newLine(); + writer.flush(); + } + + if (s.contains("Feature branches")) { writer.write(_initOptions.getFeaturePrefix()); myVcs.showCommandLine(_initOptions.getFeaturePrefix()); writer.newLine(); writer.flush(); } - if (s.contains("Release branches")){ + if (s.contains("Release branches")) { writer.write(_initOptions.getReleasePrefix()); myVcs.showCommandLine(_initOptions.getReleasePrefix()); writer.newLine(); writer.flush(); } - if (s.contains("Hotfix branches")){ + if (s.contains("Hotfix branches")) { writer.write(_initOptions.getHotfixPrefix()); myVcs.showCommandLine(_initOptions.getHotfixPrefix()); writer.newLine(); writer.flush(); } - if (s.contains("Support branches")){ + if (s.contains("Support branches")) { writer.write(_initOptions.getSupportPrefix()); myVcs.showCommandLine(_initOptions.getSupportPrefix()); writer.newLine(); writer.flush(); } - if (s.contains("Version tag")){ + if (s.contains("Version tag")) { writer.write(_initOptions.getVersionPrefix()); myVcs.showCommandLine(_initOptions.getVersionPrefix()); writer.newLine(); writer.flush(); } - if (s.contains("Hooks and filters")){ + if (s.contains("Hooks and filters")) { writer.newLine(); writer.flush(); } From 7a28aee409d9a54ca3b88ca170b08a5ba6e2e7fc Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Sun, 6 Sep 2015 03:49:49 +0200 Subject: [PATCH 07/18] Reworked new hotfix/feature dialog This dialog has now a combobox to select the branch on which the new feature or hotfix branch should be based on. The branch selection still needs some work, so the dialog is not yet completely usable. WIP. --- src/gitflow/Gitflow.java | 37 +++--- src/gitflow/GitflowImpl.java | 107 ++++++++++-------- src/gitflow/actions/StartHotfixAction.java | 53 +++++---- .../GitflowNewFeatureHotfixOptionsDialog.form | 45 ++++++++ .../GitflowNewFeatureHotfixOptionsDialog.java | 91 +++++++++++++++ 5 files changed, 247 insertions(+), 86 deletions(-) create mode 100644 src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form create mode 100644 src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java diff --git a/src/gitflow/Gitflow.java b/src/gitflow/Gitflow.java index 3bc4560..6e52cad 100644 --- a/src/gitflow/Gitflow.java +++ b/src/gitflow/Gitflow.java @@ -1,16 +1,17 @@ package gitflow; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + import git4idea.commands.Git; import git4idea.commands.GitCommandResult; import git4idea.commands.GitLineHandlerListener; import git4idea.repo.GitRemote; import git4idea.repo.GitRepository; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; /** - * - * * @author Opher Vishnia / opherv.com / opherv@gmail.com */ public interface Gitflow extends Git { @@ -26,23 +27,23 @@ GitCommandResult startFeature(@NotNull GitRepository repository, @Nullable GitLineHandlerListener... listeners); GitCommandResult finishFeature(@NotNull GitRepository repository, - @NotNull String featureName, - @Nullable GitLineHandlerListener... listeners); - - GitCommandResult publishFeature(@NotNull GitRepository repository, @NotNull String featureName, @Nullable GitLineHandlerListener... listeners); - GitCommandResult pullFeature(@NotNull GitRepository repository, + GitCommandResult publishFeature(@NotNull GitRepository repository, @NotNull String featureName, - @NotNull GitRemote remote, @Nullable GitLineHandlerListener... listeners); - GitCommandResult trackFeature(@NotNull GitRepository repository, + GitCommandResult pullFeature(@NotNull GitRepository repository, @NotNull String featureName, @NotNull GitRemote remote, @Nullable GitLineHandlerListener... listeners); + GitCommandResult trackFeature(@NotNull GitRepository repository, + @NotNull String featureName, + @NotNull GitRemote remote, + @Nullable GitLineHandlerListener... listeners); + //release GitCommandResult startRelease(@NotNull GitRepository repository, @@ -61,8 +62,8 @@ GitCommandResult publishRelease(@NotNull GitRepository repository, @Nullable GitLineHandlerListener... listeners); GitCommandResult trackRelease(@NotNull GitRepository repository, - @NotNull String releaseName, - @Nullable GitLineHandlerListener... listeners); + @NotNull String releaseName, + @Nullable GitLineHandlerListener... listeners); //hotfix @@ -71,12 +72,16 @@ GitCommandResult startHotfix(@NotNull GitRepository repository, @Nullable GitLineHandlerListener... listeners); GitCommandResult finishHotfix(@NotNull GitRepository repository, - @NotNull String hotfixName, - @NotNull String tagMessage, - @Nullable GitLineHandlerListener... listeners); + @NotNull String hotfixName, + @NotNull String tagMessage, + @Nullable GitLineHandlerListener... listeners); GitCommandResult publishHotfix(@NotNull GitRepository repository, @NotNull String hotfixName, @Nullable GitLineHandlerListener... listeners); + /** + * @return A list of all branches within the given repository + */ + List getBranchList(GitRepository repository); } diff --git a/src/gitflow/GitflowImpl.java b/src/gitflow/GitflowImpl.java index a8ed4e3..66218e2 100644 --- a/src/gitflow/GitflowImpl.java +++ b/src/gitflow/GitflowImpl.java @@ -1,20 +1,25 @@ package gitflow; import com.intellij.openapi.project.Project; -import git4idea.commands.*; -import git4idea.repo.GitRemote; -import git4idea.repo.GitRepository; +import com.intellij.openapi.vfs.VirtualFile; + import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; +import java.util.List; + +import git4idea.commands.GitCommand; +import git4idea.commands.GitCommandResult; +import git4idea.commands.GitImpl; +import git4idea.commands.GitLineHandler; +import git4idea.commands.GitLineHandlerListener; +import git4idea.repo.GitRemote; +import git4idea.repo.GitRepository; /** - * - * * @author Opher Vishnia / opherv.com / opherv@gmail.com */ @@ -22,10 +27,10 @@ public class GitflowImpl extends GitImpl implements Gitflow { //we must use reflection to add this command, since the git4idea implementation doesn't expose it - private GitCommand GitflowCommand(){ - Method m= null; + private GitCommand GitflowCommand() { + Method m = null; try { - m = GitCommand.class.getDeclaredMethod("write",String.class); + m = GitCommand.class.getDeclaredMethod("write", String.class); } catch (NoSuchMethodException e) { e.printStackTrace(); } @@ -35,7 +40,7 @@ private GitCommand GitflowCommand(){ GitCommand command = null; try { - command = (GitCommand) m.invoke(null,"flow");//now its ok + command = (GitCommand) m.invoke(null, "flow");//now its ok } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { @@ -46,10 +51,10 @@ private GitCommand GitflowCommand(){ } //we must use reflection to add this command, since the git4idea implementation doesn't expose it - private static GitCommandResult run(@org.jetbrains.annotations.NotNull git4idea.commands.GitLineHandler handler){ - Method m = null; + private static GitCommandResult run(@org.jetbrains.annotations.NotNull git4idea.commands.GitLineHandler handler) { + Method m = null; try { - m = GitImpl.class.getDeclaredMethod("run",GitLineHandler.class); + m = GitImpl.class.getDeclaredMethod("run", GitLineHandler.class); } catch (NoSuchMethodException e) { e.printStackTrace(); } @@ -59,7 +64,7 @@ private static GitCommandResult run(@org.jetbrains.annotations.NotNull git4idea. GitCommandResult result = null; try { - result = (GitCommandResult ) m.invoke(null, handler);//now its ok + result = (GitCommandResult) m.invoke(null, handler);//now its ok } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { @@ -74,7 +79,7 @@ public GitCommandResult initRepo(@NotNull GitRepository repository, GitCommandResult result; - if(initOptions.isUseDefaults()) { + if (initOptions.isUseDefaults()) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); h.setSilent(false); h.setStdoutSuppressed(false); @@ -83,12 +88,11 @@ public GitCommandResult initRepo(@NotNull GitRepository repository, h.addParameters("init"); h.addParameters("-d"); - result = run(h); - } - else{ + result = run(h); + } else { - final GitInitLineHandler h = new GitInitLineHandler(initOptions,repository.getProject(), repository.getRoot(), GitflowCommand()); + final GitInitLineHandler h = new GitInitLineHandler(initOptions, repository.getProject(), repository.getRoot(), GitflowCommand()); h.setSilent(false); h.setStdoutSuppressed(false); @@ -99,7 +103,7 @@ public GitCommandResult initRepo(@NotNull GitRepository repository, for (GitLineHandlerListener listener : listeners) { h.addLineListener(listener); } - result = run(h); + result = run(h); } @@ -129,8 +133,8 @@ public GitCommandResult startFeature(@NotNull GitRepository repository, } public GitCommandResult finishFeature(@NotNull GitRepository repository, - @NotNull String featureName, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String featureName, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); @@ -157,8 +161,8 @@ public GitCommandResult finishFeature(@NotNull GitRepository repository, public GitCommandResult publishFeature(@NotNull GitRepository repository, - @NotNull String featureName, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String featureName, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); h.setSilent(false); @@ -177,9 +181,9 @@ public GitCommandResult publishFeature(@NotNull GitRepository repository, // feature pull seems to be kind of useless. see // http://stackoverflow.com/questions/18412750/why-doesnt-git-flow-feature-pull-track public GitCommandResult pullFeature(@NotNull GitRepository repository, - @NotNull String featureName, - @NotNull GitRemote remote, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String featureName, + @NotNull GitRemote remote, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); h.setSilent(false); @@ -195,9 +199,9 @@ public GitCommandResult pullFeature(@NotNull GitRepository repository, } public GitCommandResult trackFeature(@NotNull GitRepository repository, - @NotNull String featureName, - @NotNull GitRemote remote, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String featureName, + @NotNull GitRemote remote, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); h.setSilent(false); @@ -248,14 +252,13 @@ public GitCommandResult finishRelease(@NotNull GitRepository repository, if (GitflowConfigurable.releaseFetchOrigin(repository.getProject())) { h.addParameters("-F"); } - if(GitflowConfigurable.pushOnReleaseFinish(repository.getProject())) { + if (GitflowConfigurable.pushOnReleaseFinish(repository.getProject())) { h.addParameters("-p"); } if (GitflowConfigurable.dontTagRelease(repository.getProject())) { h.addParameters("-n"); - } - else{ + } else { h.addParameters("-m"); h.addParameters(tagMessage); } @@ -288,8 +291,8 @@ public GitCommandResult publishRelease(@NotNull GitRepository repository, } public GitCommandResult trackRelease(@NotNull GitRepository repository, - @NotNull String releaseName, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String releaseName, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); h.setSilent(false); @@ -308,8 +311,8 @@ public GitCommandResult trackRelease(@NotNull GitRepository repository, //hotfix public GitCommandResult startHotfix(@NotNull GitRepository repository, - @NotNull String hotfixName, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String hotfixName, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); h.setSilent(false); @@ -327,9 +330,9 @@ public GitCommandResult startHotfix(@NotNull GitRepository repository, } public GitCommandResult finishHotfix(@NotNull GitRepository repository, - @NotNull String hotfixName, - @NotNull String tagMessage, - @Nullable GitLineHandlerListener... listeners) { + @NotNull String hotfixName, + @NotNull String tagMessage, + @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); setUrl(h, repository); h.setSilent(false); @@ -346,8 +349,7 @@ public GitCommandResult finishHotfix(@NotNull GitRepository repository, if (GitflowConfigurable.dontTagHotfix(repository.getProject())) { h.addParameters("-n"); - } - else{ + } else { h.addParameters("-m"); h.addParameters(tagMessage); } @@ -378,13 +380,28 @@ public GitCommandResult publishHotfix(@NotNull GitRepository repository, return run(h); } - private void setUrl (GitLineHandler h, GitRepository repository){ - ArrayList remotes = new ArrayList(repository.getRemotes()); + @Override + public List getBranchList(GitRepository repository) { + final Project project = repository.getProject(); + final VirtualFile root = repository.getRoot(); + + GitCommandResult commandResult = run(new GitLineHandler(project, root, GitCommand.BRANCH)); + List result = new ArrayList<>(commandResult.getOutput().size()); + for (String line : commandResult.getOutput()) { + result.add(line.replace("*", "").trim()); + } + + return result; + } + + private void setUrl(GitLineHandler h, GitRepository repository) { + ArrayList remotes = new ArrayList<>(repository.getRemotes()); //make sure a remote repository is available - if (!remotes.isEmpty()){ + if (!remotes.isEmpty()) { h.setUrl(remotes.iterator().next().getFirstUrl()); } } + } diff --git a/src/gitflow/actions/StartHotfixAction.java b/src/gitflow/actions/StartHotfixAction.java index e898f21..8f389f5 100644 --- a/src/gitflow/actions/StartHotfixAction.java +++ b/src/gitflow/actions/StartHotfixAction.java @@ -3,11 +3,13 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; -import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.DialogWrapper; + +import org.jetbrains.annotations.NotNull; + import git4idea.commands.GitCommandResult; -import git4idea.validators.GitNewBranchNameValidator; +import gitflow.ui.GitflowNewFeatureHotfixOptionsDialog; import gitflow.ui.NotifyUtil; -import org.jetbrains.annotations.NotNull; public class StartHotfixAction extends GitflowAction { @@ -19,34 +21,35 @@ public class StartHotfixAction extends GitflowAction { public void actionPerformed(AnActionEvent e) { super.actionPerformed(e); - final String hotfixName = Messages.showInputDialog(myProject, "Enter the name of the new hotfix:", "New Hotfix", Messages.getQuestionIcon(), "", - GitNewBranchNameValidator.newInstance(repos)); - final GitflowErrorsListener errorLineHandler = new GitflowErrorsListener(myProject); + GitflowNewFeatureHotfixOptionsDialog dialog = + new GitflowNewFeatureHotfixOptionsDialog(myGitflow, repo, myProject, "hotfix"); + dialog.show(); - //must insert hotfix name - if (hotfixName!=null && !hotfixName.isEmpty()){ - new Task.Backgroundable(myProject,"Starting hotfix "+hotfixName,false){ - @Override - public void run(@NotNull ProgressIndicator indicator) { - GitCommandResult result = myGitflow.startHotfix(repo, hotfixName, errorLineHandler); + if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; - if (result.success()) { - String startedHotfixMessage = String.format("A new hotfix '%s%s' was created, based on '%s'", hotfixPrefix, hotfixName, masterBranch); - NotifyUtil.notifySuccess(myProject, hotfixName, startedHotfixMessage); - } - else { - NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details"); - } + final String hotfixBranchName = dialog.getNewBranchName(); + final String baseBranchName = dialog.getBaseBranchName(); - repo.update(); + new Task.Backgroundable(myProject, "Starting hotfix " + hotfixBranchName, false) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + createHotfixBranch(baseBranchName, hotfixBranchName); + } + }.queue(); + } - } - }.queue(); + private void createHotfixBranch(String baseBranchName, String hotfixBranchName) { + GitflowErrorsListener errorListener = new GitflowErrorsListener(myProject); + GitCommandResult result = myGitflow.startHotfix(repo, hotfixBranchName, errorListener); - } - else{ - Messages.showWarningDialog(myProject, "You must provide a name for the hotfix", "Whoops"); + if (result.success()) { + String startedHotfixMessage = String.format("A new hotfix '%s%s' was created, based on '%s'", + hotfixPrefix, hotfixBranchName, masterBranch); + NotifyUtil.notifySuccess(myProject, hotfixBranchName, startedHotfixMessage); + } else { + NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details"); } + repo.update(); } } \ No newline at end of file diff --git a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form b/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form new file mode 100644 index 0000000..3399cf2 --- /dev/null +++ b/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form @@ -0,0 +1,45 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java b/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java new file mode 100644 index 0000000..51754da --- /dev/null +++ b/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java @@ -0,0 +1,91 @@ +package gitflow.ui; + +import com.intellij.openapi.project.Project; +import com.intellij.openapi.ui.DialogWrapper; +import com.intellij.openapi.ui.ValidationInfo; + +import java.util.List; + +import javax.swing.*; + +import git4idea.repo.GitRepository; +import gitflow.Gitflow; + +/** + * This dialog gets displayed when the user selected the option to create a new feature or hotfix. + * It prompts the user to enter a name for the new branch and (optionally) to select a branch on + * which the new branch is based. + * + * The default selection for the base branch is
  • new feature: the development branch
  • + *
  • new hotfix: the release branch
+ * + * These are always selected when the dialog is opened to allow the user to skip branch selection, + * given that this is the common use-case. + */ +public class GitflowNewFeatureHotfixOptionsDialog extends DialogWrapper { + + private JPanel contentPane; + private JTextField branchNameTextField; + private JComboBox branchFromCombo; + private JLabel branchNameLabel; + + private GitRepository repository; + private Gitflow gitflow; + + /** + * @param label The label/type of the dialog, for example "hotfix" or "feature". Used for the + */ + public GitflowNewFeatureHotfixOptionsDialog(Gitflow gitflow, GitRepository repository, Project project, String label) { + super(project, false); + this.gitflow = gitflow; + this.repository = repository; + + init(); + setTitle("New " + label + "..."); + branchNameLabel.setText(String.format("Enter a name for the new %s...", label)); + setModal(true); + + branchFromCombo.setModel(createBranchComboModel()); + } + + @Override + protected JComponent createCenterPanel() { + return contentPane; + } + + @Override + public JComponent getPreferredFocusedComponent() { + return branchNameTextField; + } + + private ComboBoxModel createBranchComboModel() { + List branchList = gitflow.getBranchList(repository); + String[] branchListArray = branchList.toArray(new String[branchList.size()]); + return new DefaultComboBoxModel<>(branchListArray); + } + + @Override + protected ValidationInfo doValidate() { + boolean isBranchNameSpecified = branchNameTextField.getText().trim().length() > 0; + if (!isBranchNameSpecified) { + return new ValidationInfo("No branch name specified", branchNameTextField); + } else { + return null; + } + } + + /** + * @return The name of the new branch as specified by the user + */ + public String getNewBranchName() { + return branchNameTextField.getText().trim(); + } + + /** + * @return The name of the base branch (the branch on which the new hotfix or feature should be + * based on) + */ + public String getBaseBranchName() { + return ""; + } +} From 67100ef83af8319b79f00b8f92db8507352ee706 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Mon, 7 Sep 2015 16:01:23 +0200 Subject: [PATCH 08/18] Implemented new start feature and start hotfix dialog --- src/gitflow/Gitflow.java | 2 + src/gitflow/GitflowImpl.java | 12 ++- src/gitflow/actions/StartFeatureAction.java | 52 +++++------ src/gitflow/actions/StartHotfixAction.java | 16 ++-- ...og.form => AbstractBranchStartDialog.form} | 2 +- ...og.java => AbstractBranchStartDialog.java} | 86 +++++++++++-------- src/gitflow/ui/GitflowStartFeatureDialog.java | 24 ++++++ src/gitflow/ui/GitflowStartHotfixDialog.java | 24 ++++++ 8 files changed, 147 insertions(+), 71 deletions(-) rename src/gitflow/ui/{GitflowNewFeatureHotfixOptionsDialog.form => AbstractBranchStartDialog.form} (96%) rename src/gitflow/ui/{GitflowNewFeatureHotfixOptionsDialog.java => AbstractBranchStartDialog.java} (60%) create mode 100644 src/gitflow/ui/GitflowStartFeatureDialog.java create mode 100644 src/gitflow/ui/GitflowStartHotfixDialog.java diff --git a/src/gitflow/Gitflow.java b/src/gitflow/Gitflow.java index 6e52cad..755db3f 100644 --- a/src/gitflow/Gitflow.java +++ b/src/gitflow/Gitflow.java @@ -24,6 +24,7 @@ public GitCommandResult initRepo(@NotNull GitRepository repository, GitCommandResult startFeature(@NotNull GitRepository repository, @NotNull String featureName, + @Nullable String baseBranch, @Nullable GitLineHandlerListener... listeners); GitCommandResult finishFeature(@NotNull GitRepository repository, @@ -69,6 +70,7 @@ GitCommandResult trackRelease(@NotNull GitRepository repository, GitCommandResult startHotfix(@NotNull GitRepository repository, @NotNull String hotfixName, + @Nullable String baseBranch, @Nullable GitLineHandlerListener... listeners); GitCommandResult finishHotfix(@NotNull GitRepository repository, diff --git a/src/gitflow/GitflowImpl.java b/src/gitflow/GitflowImpl.java index 66218e2..94c2744 100644 --- a/src/gitflow/GitflowImpl.java +++ b/src/gitflow/GitflowImpl.java @@ -115,6 +115,7 @@ public GitCommandResult initRepo(@NotNull GitRepository repository, public GitCommandResult startFeature(@NotNull GitRepository repository, @NotNull String featureName, + @Nullable String baseBranch, @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); h.setSilent(false); @@ -126,6 +127,10 @@ public GitCommandResult startFeature(@NotNull GitRepository repository, } h.addParameters(featureName); + if (baseBranch != null) { + h.addParameters(baseBranch); + } + for (GitLineHandlerListener listener : listeners) { h.addLineListener(listener); } @@ -312,6 +317,7 @@ public GitCommandResult trackRelease(@NotNull GitRepository repository, public GitCommandResult startHotfix(@NotNull GitRepository repository, @NotNull String hotfixName, + @Nullable String baseBranch, @Nullable GitLineHandlerListener... listeners) { final GitLineHandler h = new GitLineHandler(repository.getProject(), repository.getRoot(), GitflowCommand()); h.setSilent(false); @@ -323,6 +329,10 @@ public GitCommandResult startHotfix(@NotNull GitRepository repository, } h.addParameters(hotfixName); + if (baseBranch != null) { + h.addParameters(baseBranch); + } + for (GitLineHandlerListener listener : listeners) { h.addLineListener(listener); } @@ -390,7 +400,7 @@ public List getBranchList(GitRepository repository) { for (String line : commandResult.getOutput()) { result.add(line.replace("*", "").trim()); } - + return result; } diff --git a/src/gitflow/actions/StartFeatureAction.java b/src/gitflow/actions/StartFeatureAction.java index d08f02c..5d00507 100644 --- a/src/gitflow/actions/StartFeatureAction.java +++ b/src/gitflow/actions/StartFeatureAction.java @@ -3,51 +3,51 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; -import com.intellij.openapi.ui.Messages; +import com.intellij.openapi.ui.DialogWrapper; + +import org.jetbrains.annotations.NotNull; + import git4idea.commands.GitCommandResult; -import git4idea.validators.GitNewBranchNameValidator; +import gitflow.ui.GitflowStartFeatureDialog; import gitflow.ui.NotifyUtil; -import org.jetbrains.annotations.NotNull; public class StartFeatureAction extends GitflowAction { - StartFeatureAction() { super("Start Feature"); } @Override public void actionPerformed(AnActionEvent e) { - //set up context variables super.actionPerformed(e); - final String featureName = Messages.showInputDialog(myProject, "Enter the name of new feature:", "New Feature", Messages.getQuestionIcon(), "", - GitNewBranchNameValidator.newInstance(repos)); - - if (featureName!=null && !featureName.isEmpty()){ - new Task.Backgroundable(myProject,"Starting feature "+featureName,false){ - @Override - public void run(@NotNull ProgressIndicator indicator) { - GitCommandResult result = myGitflow.startFeature(repo,featureName,new GitflowErrorsListener(myProject)); + GitflowStartFeatureDialog dialog = new GitflowStartFeatureDialog(myGitflow, repo, myProject); + dialog.show(); + if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; - if (result.success()) { - String startedFeatureMessage = String.format("A new branch '%s%s' was created, based on '%s'", featurePrefix, featureName, developBranch); - NotifyUtil.notifySuccess(myProject, featureName, startedFeatureMessage); - } - else { - NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details"); - } + final String featureName = dialog.getNewBranchName(); + final String baseBranchName = dialog.getBaseBranchName(); - repo.update(); + new Task.Backgroundable(myProject, "Starting feature " + featureName, false) { + @Override + public void run(@NotNull ProgressIndicator indicator) { + createFeatureBranch(baseBranchName, featureName); + } + }.queue(); + } - } - }.queue(); + private void createFeatureBranch(String baseBranchName, String featureName) { + GitflowErrorsListener errorListener = new GitflowErrorsListener(myProject); + GitCommandResult result = myGitflow.startFeature(repo, featureName, baseBranchName, errorListener); - } - else{ - Messages.showWarningDialog(myProject, "You must provide a name for the feature", "Whoops"); + if (result.success()) { + String startedFeatureMessage = String.format("A new branch '%s%s' was created, based on '%s'", featurePrefix, featureName, baseBranchName); + NotifyUtil.notifySuccess(myProject, featureName, startedFeatureMessage); + } else { + NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details"); } + repo.update(); } } \ No newline at end of file diff --git a/src/gitflow/actions/StartHotfixAction.java b/src/gitflow/actions/StartHotfixAction.java index 8f389f5..95780aa 100644 --- a/src/gitflow/actions/StartHotfixAction.java +++ b/src/gitflow/actions/StartHotfixAction.java @@ -8,9 +8,10 @@ import org.jetbrains.annotations.NotNull; import git4idea.commands.GitCommandResult; -import gitflow.ui.GitflowNewFeatureHotfixOptionsDialog; +import gitflow.ui.GitflowStartHotfixDialog; import gitflow.ui.NotifyUtil; + public class StartHotfixAction extends GitflowAction { StartHotfixAction() { @@ -21,30 +22,29 @@ public class StartHotfixAction extends GitflowAction { public void actionPerformed(AnActionEvent e) { super.actionPerformed(e); - GitflowNewFeatureHotfixOptionsDialog dialog = - new GitflowNewFeatureHotfixOptionsDialog(myGitflow, repo, myProject, "hotfix"); + GitflowStartHotfixDialog dialog = new GitflowStartHotfixDialog(myGitflow, repo, myProject); dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; - final String hotfixBranchName = dialog.getNewBranchName(); + final String hotfixName = dialog.getNewBranchName(); final String baseBranchName = dialog.getBaseBranchName(); - new Task.Backgroundable(myProject, "Starting hotfix " + hotfixBranchName, false) { + new Task.Backgroundable(myProject, "Starting hotfix " + hotfixName, false) { @Override public void run(@NotNull ProgressIndicator indicator) { - createHotfixBranch(baseBranchName, hotfixBranchName); + createHotfixBranch(baseBranchName, hotfixName); } }.queue(); } private void createHotfixBranch(String baseBranchName, String hotfixBranchName) { GitflowErrorsListener errorListener = new GitflowErrorsListener(myProject); - GitCommandResult result = myGitflow.startHotfix(repo, hotfixBranchName, errorListener); + GitCommandResult result = myGitflow.startHotfix(repo, hotfixBranchName, baseBranchName, errorListener); if (result.success()) { String startedHotfixMessage = String.format("A new hotfix '%s%s' was created, based on '%s'", - hotfixPrefix, hotfixBranchName, masterBranch); + hotfixPrefix, hotfixBranchName, baseBranchName); NotifyUtil.notifySuccess(myProject, hotfixBranchName, startedHotfixMessage); } else { NotifyUtil.notifyError(myProject, "Error", "Please have a look at the Version Control console for more details"); diff --git a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form b/src/gitflow/ui/AbstractBranchStartDialog.form similarity index 96% rename from src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form rename to src/gitflow/ui/AbstractBranchStartDialog.form index 3399cf2..44c0611 100644 --- a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.form +++ b/src/gitflow/ui/AbstractBranchStartDialog.form @@ -1,5 +1,5 @@ -
+ diff --git a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java similarity index 60% rename from src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java rename to src/gitflow/ui/AbstractBranchStartDialog.java index 51754da..77b2711 100644 --- a/src/gitflow/ui/GitflowNewFeatureHotfixOptionsDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -4,6 +4,7 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.ValidationInfo; +import java.util.Collections; import java.util.List; import javax.swing.*; @@ -12,17 +13,10 @@ import gitflow.Gitflow; /** - * This dialog gets displayed when the user selected the option to create a new feature or hotfix. - * It prompts the user to enter a name for the new branch and (optionally) to select a branch on - * which the new branch is based. - * - * The default selection for the base branch is
  • new feature: the development branch
  • - *
  • new hotfix: the release branch
- * - * These are always selected when the dialog is opened to allow the user to skip branch selection, - * given that this is the common use-case. + * Base class for a "start" dialog. Prompts the user to enter a name for a new branch and select a + * base branch. See {@link GitflowStartFeatureDialog} for an example implementation. */ -public class GitflowNewFeatureHotfixOptionsDialog extends DialogWrapper { +public abstract class AbstractBranchStartDialog extends DialogWrapper { private JPanel contentPane; private JTextField branchNameTextField; @@ -31,16 +25,16 @@ public class GitflowNewFeatureHotfixOptionsDialog extends DialogWrapper { private GitRepository repository; private Gitflow gitflow; + private Project project; - /** - * @param label The label/type of the dialog, for example "hotfix" or "feature". Used for the - */ - public GitflowNewFeatureHotfixOptionsDialog(Gitflow gitflow, GitRepository repository, Project project, String label) { + public AbstractBranchStartDialog(Gitflow gitflow, GitRepository repository, Project project) { super(project, false); this.gitflow = gitflow; this.repository = repository; + this.project = project; init(); + final String label = getLabel(); setTitle("New " + label + "..."); branchNameLabel.setText(String.format("Enter a name for the new %s...", label)); setModal(true); @@ -48,44 +42,66 @@ public GitflowNewFeatureHotfixOptionsDialog(Gitflow gitflow, GitRepository repos branchFromCombo.setModel(createBranchComboModel()); } - @Override - protected JComponent createCenterPanel() { - return contentPane; - } - @Override public JComponent getPreferredFocusedComponent() { return branchNameTextField; } - private ComboBoxModel createBranchComboModel() { - List branchList = gitflow.getBranchList(repository); - String[] branchListArray = branchList.toArray(new String[branchList.size()]); - return new DefaultComboBoxModel<>(branchListArray); + /** + * @return The name of the new branch as specified by the user + */ + public String getNewBranchName() { + return branchNameTextField.getText().trim(); + } + + /** + * @return The name of the base branch (the branch on which the new hotfix or feature should be + * based on) + */ + public String getBaseBranchName() { + return (String) branchFromCombo.getModel().getSelectedItem(); + } + + /** + * @return The label for this dialog (e.g. "hotfix" or "feature"). Will be used for the window + * title and other labels. + */ + protected abstract String getLabel(); + + /** + * @return The name of the default branch, i.e. the branch that is selected by default when + * opening the dialog. + */ + protected abstract String getDefaultBranch(); + + protected Project getProject() { + return this.project; } @Override protected ValidationInfo doValidate() { boolean isBranchNameSpecified = branchNameTextField.getText().trim().length() > 0; if (!isBranchNameSpecified) { - return new ValidationInfo("No branch name specified", branchNameTextField); + return new ValidationInfo("No name specified", branchNameTextField); } else { return null; } } - /** - * @return The name of the new branch as specified by the user - */ - public String getNewBranchName() { - return branchNameTextField.getText().trim(); + @Override + protected JComponent createCenterPanel() { + return contentPane; } - /** - * @return The name of the base branch (the branch on which the new hotfix or feature should be - * based on) - */ - public String getBaseBranchName() { - return ""; + private ComboBoxModel createBranchComboModel() { + List branchList = gitflow.getBranchList(repository); + + final String defaultBranch = getDefaultBranch(); + branchList.remove(defaultBranch); + Collections.sort(branchList); + branchList.add(0, defaultBranch); + + String[] branchListArray = branchList.toArray(new String[branchList.size()]); + return new DefaultComboBoxModel<>(branchListArray); } } diff --git a/src/gitflow/ui/GitflowStartFeatureDialog.java b/src/gitflow/ui/GitflowStartFeatureDialog.java new file mode 100644 index 0000000..8049ac8 --- /dev/null +++ b/src/gitflow/ui/GitflowStartFeatureDialog.java @@ -0,0 +1,24 @@ +package gitflow.ui; + +import com.intellij.openapi.project.Project; + +import git4idea.repo.GitRepository; +import gitflow.Gitflow; +import gitflow.GitflowConfigUtil; + +public class GitflowStartFeatureDialog extends AbstractBranchStartDialog { + + public GitflowStartFeatureDialog(Gitflow gitflow, GitRepository repository, Project project) { + super(gitflow, repository, project); + } + + @Override + protected String getLabel() { + return "feature"; + } + + @Override + protected String getDefaultBranch() { + return GitflowConfigUtil.getDevelopBranch(getProject()); + } +} diff --git a/src/gitflow/ui/GitflowStartHotfixDialog.java b/src/gitflow/ui/GitflowStartHotfixDialog.java new file mode 100644 index 0000000..0c87d27 --- /dev/null +++ b/src/gitflow/ui/GitflowStartHotfixDialog.java @@ -0,0 +1,24 @@ +package gitflow.ui; + +import com.intellij.openapi.project.Project; + +import git4idea.repo.GitRepository; +import gitflow.Gitflow; +import gitflow.GitflowConfigUtil; + +public class GitflowStartHotfixDialog extends AbstractBranchStartDialog { + + public GitflowStartHotfixDialog(Gitflow gitflow, GitRepository repository, Project project) { + super(gitflow, repository, project); + } + + @Override + protected String getLabel() { + return "hotfix"; + } + + @Override + protected String getDefaultBranch() { + return GitflowConfigUtil.getMasterBranch(getProject()); + } +} From 5a94ad401e0cc739f1e5d8440b013ab022a7d930 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Mon, 7 Sep 2015 19:04:42 +0200 Subject: [PATCH 09/18] Implemented new start feature and start hotfix dialog --- src/gitflow/ui/AbstractBranchStartDialog.java | 50 +++++++++++++++---- 1 file changed, 39 insertions(+), 11 deletions(-) diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index 77b2711..6e77b93 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -4,7 +4,6 @@ import com.intellij.openapi.ui.DialogWrapper; import com.intellij.openapi.ui.ValidationInfo; -import java.util.Collections; import java.util.List; import javax.swing.*; @@ -13,8 +12,8 @@ import gitflow.Gitflow; /** - * Base class for a "start" dialog. Prompts the user to enter a name for a new branch and select a - * base branch. See {@link GitflowStartFeatureDialog} for an example implementation. + * Base class for a "start" dialog. Such a dialog prompts the user to enter a name for a new branch + * and select a base branch. See {@link GitflowStartFeatureDialog} for an example implementation. */ public abstract class AbstractBranchStartDialog extends DialogWrapper { @@ -59,7 +58,8 @@ public String getNewBranchName() { * based on) */ public String getBaseBranchName() { - return (String) branchFromCombo.getModel().getSelectedItem(); + ComboEntry selectedBranch = (ComboEntry) branchFromCombo.getModel().getSelectedItem(); + return selectedBranch.getBranchName(); } /** @@ -93,15 +93,43 @@ protected JComponent createCenterPanel() { return contentPane; } - private ComboBoxModel createBranchComboModel() { - List branchList = gitflow.getBranchList(repository); - + private ComboBoxModel createBranchComboModel() { + final List branchList = gitflow.getBranchList(repository); final String defaultBranch = getDefaultBranch(); branchList.remove(defaultBranch); - Collections.sort(branchList); - branchList.add(0, defaultBranch); - String[] branchListArray = branchList.toArray(new String[branchList.size()]); - return new DefaultComboBoxModel<>(branchListArray); + ComboEntry[] entries = new ComboEntry[branchList.size() + 1]; + entries[0] = new ComboEntry(defaultBranch, defaultBranch + " (default)"); + for (int i = 1; i <= branchList.size(); i++) { + String branchName = branchList.get(i - 1); + entries[i] = new ComboEntry(branchName, branchName); + } + + return new DefaultComboBoxModel<>(entries); + } + + /** + * An entry for the branch selection dropdown/combo. + */ + private static class ComboEntry { + private String branchName, label; + + public ComboEntry(String branchName, String label) { + this.branchName = branchName; + this.label = label; + } + + public String getBranchName() { + return branchName; + } + + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; + } } } From 949e9d6fe5156f1b6fee5ec3c27bccaf07093b10 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Mon, 7 Sep 2015 19:04:55 +0200 Subject: [PATCH 10/18] Implemented new start feature and start hotfix dialog --- src/gitflow/ui/AbstractBranchStartDialog.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index 6e77b93..7debb7d 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -123,10 +123,6 @@ public String getBranchName() { return branchName; } - public String getLabel() { - return label; - } - @Override public String toString() { return label; From 87f855ec69909fbfb7bcc2e83c57a03328a4556e Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Mon, 7 Sep 2015 19:08:01 +0200 Subject: [PATCH 11/18] Implemented new start feature and start hotfix dialog --- src/gitflow/ui/AbstractBranchStartDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index 7debb7d..1650d41 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -19,7 +19,7 @@ public abstract class AbstractBranchStartDialog extends DialogWrapper { private JPanel contentPane; private JTextField branchNameTextField; - private JComboBox branchFromCombo; + private JComboBox branchFromCombo; private JLabel branchNameLabel; private GitRepository repository; From b78cb534dfca114b60722cc61c1862b56489a6d2 Mon Sep 17 00:00:00 2001 From: OpherV Date: Wed, 9 Sep 2015 13:33:44 +0300 Subject: [PATCH 12/18] readme: remove bitdeli tag --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 32ba425..7ec2d29 100644 --- a/README.md +++ b/README.md @@ -59,4 +59,3 @@ This plugin is under the [Apache 2.0 license](http://www.apache.org/licenses/LIC Copyright 2013-2014, Opher Vishnia. -[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/OpherV/gitflow4idea/trend.png)](https://bitdeli.com/free "Bitdeli Badge") From 028456b7b931c5b3bee0d870b51acd64da763339 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Wed, 9 Sep 2015 16:22:55 +0200 Subject: [PATCH 13/18] Removed Gitflow.getBranchList() and replaced usages with GitflowBranchUtil.getLocalBranchNames() This fixes accidentally duplicated code functionality. --- src/gitflow/Gitflow.java | 7 ------- src/gitflow/GitflowImpl.java | 14 -------------- src/gitflow/ui/AbstractBranchStartDialog.java | 5 ++++- 3 files changed, 4 insertions(+), 22 deletions(-) diff --git a/src/gitflow/Gitflow.java b/src/gitflow/Gitflow.java index 755db3f..0d5aeb9 100644 --- a/src/gitflow/Gitflow.java +++ b/src/gitflow/Gitflow.java @@ -3,8 +3,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; - import git4idea.commands.Git; import git4idea.commands.GitCommandResult; import git4idea.commands.GitLineHandlerListener; @@ -81,9 +79,4 @@ GitCommandResult finishHotfix(@NotNull GitRepository repository, GitCommandResult publishHotfix(@NotNull GitRepository repository, @NotNull String hotfixName, @Nullable GitLineHandlerListener... listeners); - - /** - * @return A list of all branches within the given repository - */ - List getBranchList(GitRepository repository); } diff --git a/src/gitflow/GitflowImpl.java b/src/gitflow/GitflowImpl.java index 94c2744..d9f1f23 100644 --- a/src/gitflow/GitflowImpl.java +++ b/src/gitflow/GitflowImpl.java @@ -390,20 +390,6 @@ public GitCommandResult publishHotfix(@NotNull GitRepository repository, return run(h); } - @Override - public List getBranchList(GitRepository repository) { - final Project project = repository.getProject(); - final VirtualFile root = repository.getRoot(); - - GitCommandResult commandResult = run(new GitLineHandler(project, root, GitCommand.BRANCH)); - List result = new ArrayList<>(commandResult.getOutput().size()); - for (String line : commandResult.getOutput()) { - result.add(line.replace("*", "").trim()); - } - - return result; - } - private void setUrl(GitLineHandler h, GitRepository repository) { ArrayList remotes = new ArrayList<>(repository.getRemotes()); diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index 1650d41..ab4d7bb 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -10,6 +10,7 @@ import git4idea.repo.GitRepository; import gitflow.Gitflow; +import gitflow.GitflowBranchUtil; /** * Base class for a "start" dialog. Such a dialog prompts the user to enter a name for a new branch @@ -25,12 +26,14 @@ public abstract class AbstractBranchStartDialog extends DialogWrapper { private GitRepository repository; private Gitflow gitflow; private Project project; + private GitflowBranchUtil util; public AbstractBranchStartDialog(Gitflow gitflow, GitRepository repository, Project project) { super(project, false); this.gitflow = gitflow; this.repository = repository; this.project = project; + this.util = new GitflowBranchUtil(project); init(); final String label = getLabel(); @@ -94,7 +97,7 @@ protected JComponent createCenterPanel() { } private ComboBoxModel createBranchComboModel() { - final List branchList = gitflow.getBranchList(repository); + final List branchList = util.getLocalBranchNames(); final String defaultBranch = getDefaultBranch(); branchList.remove(defaultBranch); From 0d8f422c894e3392f4f91e89392c6d10dd430424 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Wed, 9 Sep 2015 16:25:10 +0200 Subject: [PATCH 14/18] AbstractBranchStartDialog: Removed unused fields and adjusted field naming --- src/gitflow/ui/AbstractBranchStartDialog.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index ab4d7bb..4866407 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -23,17 +23,13 @@ public abstract class AbstractBranchStartDialog extends DialogWrapper { private JComboBox branchFromCombo; private JLabel branchNameLabel; - private GitRepository repository; - private Gitflow gitflow; private Project project; - private GitflowBranchUtil util; + private GitflowBranchUtil gitflowBranchUtil; - public AbstractBranchStartDialog(Gitflow gitflow, GitRepository repository, Project project) { + public AbstractBranchStartDialog(Project project) { super(project, false); - this.gitflow = gitflow; - this.repository = repository; this.project = project; - this.util = new GitflowBranchUtil(project); + this.gitflowBranchUtil = new GitflowBranchUtil(project); init(); final String label = getLabel(); @@ -97,7 +93,7 @@ protected JComponent createCenterPanel() { } private ComboBoxModel createBranchComboModel() { - final List branchList = util.getLocalBranchNames(); + final List branchList = gitflowBranchUtil.getLocalBranchNames(); final String defaultBranch = getDefaultBranch(); branchList.remove(defaultBranch); From 27f5cf599a261590b17083e90d9e11eebae90215 Mon Sep 17 00:00:00 2001 From: Alex Schwabe <-> Date: Wed, 9 Sep 2015 16:27:17 +0200 Subject: [PATCH 15/18] AbstractBranchStartDialog: Adjusted constructor usage. --- src/gitflow/actions/StartFeatureAction.java | 2 +- src/gitflow/actions/StartHotfixAction.java | 2 +- src/gitflow/ui/GitflowStartFeatureDialog.java | 6 ++---- src/gitflow/ui/GitflowStartHotfixDialog.java | 6 ++---- 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/gitflow/actions/StartFeatureAction.java b/src/gitflow/actions/StartFeatureAction.java index 5d00507..98d3606 100644 --- a/src/gitflow/actions/StartFeatureAction.java +++ b/src/gitflow/actions/StartFeatureAction.java @@ -21,7 +21,7 @@ public class StartFeatureAction extends GitflowAction { public void actionPerformed(AnActionEvent e) { super.actionPerformed(e); - GitflowStartFeatureDialog dialog = new GitflowStartFeatureDialog(myGitflow, repo, myProject); + GitflowStartFeatureDialog dialog = new GitflowStartFeatureDialog(myProject); dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; diff --git a/src/gitflow/actions/StartHotfixAction.java b/src/gitflow/actions/StartHotfixAction.java index 95780aa..dff5bb6 100644 --- a/src/gitflow/actions/StartHotfixAction.java +++ b/src/gitflow/actions/StartHotfixAction.java @@ -22,7 +22,7 @@ public class StartHotfixAction extends GitflowAction { public void actionPerformed(AnActionEvent e) { super.actionPerformed(e); - GitflowStartHotfixDialog dialog = new GitflowStartHotfixDialog(myGitflow, repo, myProject); + GitflowStartHotfixDialog dialog = new GitflowStartHotfixDialog(myProject); dialog.show(); if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) return; diff --git a/src/gitflow/ui/GitflowStartFeatureDialog.java b/src/gitflow/ui/GitflowStartFeatureDialog.java index 8049ac8..ded81b3 100644 --- a/src/gitflow/ui/GitflowStartFeatureDialog.java +++ b/src/gitflow/ui/GitflowStartFeatureDialog.java @@ -2,14 +2,12 @@ import com.intellij.openapi.project.Project; -import git4idea.repo.GitRepository; -import gitflow.Gitflow; import gitflow.GitflowConfigUtil; public class GitflowStartFeatureDialog extends AbstractBranchStartDialog { - public GitflowStartFeatureDialog(Gitflow gitflow, GitRepository repository, Project project) { - super(gitflow, repository, project); + public GitflowStartFeatureDialog(Project project) { + super(project); } @Override diff --git a/src/gitflow/ui/GitflowStartHotfixDialog.java b/src/gitflow/ui/GitflowStartHotfixDialog.java index 0c87d27..101b6f5 100644 --- a/src/gitflow/ui/GitflowStartHotfixDialog.java +++ b/src/gitflow/ui/GitflowStartHotfixDialog.java @@ -2,14 +2,12 @@ import com.intellij.openapi.project.Project; -import git4idea.repo.GitRepository; -import gitflow.Gitflow; import gitflow.GitflowConfigUtil; public class GitflowStartHotfixDialog extends AbstractBranchStartDialog { - public GitflowStartHotfixDialog(Gitflow gitflow, GitRepository repository, Project project) { - super(gitflow, repository, project); + public GitflowStartHotfixDialog(Project project) { + super(project); } @Override From f4a830219719bc31759bef108baf247e5274ea75 Mon Sep 17 00:00:00 2001 From: OpherV Date: Thu, 10 Sep 2015 14:56:01 +0300 Subject: [PATCH 16/18] bump to 0.4.4 --- META-INF/plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/META-INF/plugin.xml b/META-INF/plugin.xml index 0540850..807db2e 100644 --- a/META-INF/plugin.xml +++ b/META-INF/plugin.xml @@ -2,7 +2,7 @@ Git Flow Integration Gitflow Git Flow Integration - 0.4.3 + 0.4.4 VCS Integration Opher Vishnia From c2bb35854f5bdade8297c657f78f12f8178f95cd Mon Sep 17 00:00:00 2001 From: OpherV Date: Thu, 10 Sep 2015 15:20:08 +0300 Subject: [PATCH 17/18] don't use diamond types, a JDK 1.7 feature --- src/gitflow/GitflowImpl.java | 2 +- src/gitflow/ui/AbstractBranchStartDialog.java | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gitflow/GitflowImpl.java b/src/gitflow/GitflowImpl.java index d9f1f23..b9382ff 100644 --- a/src/gitflow/GitflowImpl.java +++ b/src/gitflow/GitflowImpl.java @@ -391,7 +391,7 @@ public GitCommandResult publishHotfix(@NotNull GitRepository repository, } private void setUrl(GitLineHandler h, GitRepository repository) { - ArrayList remotes = new ArrayList<>(repository.getRemotes()); + ArrayList remotes = new ArrayList(repository.getRemotes()); //make sure a remote repository is available if (!remotes.isEmpty()) { diff --git a/src/gitflow/ui/AbstractBranchStartDialog.java b/src/gitflow/ui/AbstractBranchStartDialog.java index 4866407..9ab59af 100644 --- a/src/gitflow/ui/AbstractBranchStartDialog.java +++ b/src/gitflow/ui/AbstractBranchStartDialog.java @@ -20,7 +20,7 @@ public abstract class AbstractBranchStartDialog extends DialogWrapper { private JPanel contentPane; private JTextField branchNameTextField; - private JComboBox branchFromCombo; + private JComboBox branchFromCombo; private JLabel branchNameLabel; private Project project; @@ -92,7 +92,7 @@ protected JComponent createCenterPanel() { return contentPane; } - private ComboBoxModel createBranchComboModel() { + private ComboBoxModel createBranchComboModel() { final List branchList = gitflowBranchUtil.getLocalBranchNames(); final String defaultBranch = getDefaultBranch(); branchList.remove(defaultBranch); @@ -104,7 +104,7 @@ private ComboBoxModel createBranchComboModel() { entries[i] = new ComboEntry(branchName, branchName); } - return new DefaultComboBoxModel<>(entries); + return new DefaultComboBoxModel(entries); } /** From 562aba8d95c7f49a871693ce02ac4d9c487868cc Mon Sep 17 00:00:00 2001 From: OpherV Date: Thu, 10 Sep 2015 16:10:09 +0300 Subject: [PATCH 18/18] fix for #73 "Synchronize" after starting a feature branch while inside another feature branch --- src/gitflow/actions/StartFeatureAction.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gitflow/actions/StartFeatureAction.java b/src/gitflow/actions/StartFeatureAction.java index 98d3606..8e33fde 100644 --- a/src/gitflow/actions/StartFeatureAction.java +++ b/src/gitflow/actions/StartFeatureAction.java @@ -1,6 +1,7 @@ package gitflow.actions; import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.progress.Task; import com.intellij.openapi.ui.DialogWrapper; @@ -49,5 +50,6 @@ private void createFeatureBranch(String baseBranchName, String featureName) { } repo.update(); + virtualFileMananger.asyncRefresh(null); //update editors } } \ No newline at end of file