From 32c3c359697bb837cfa4e1a380a823d811797709 Mon Sep 17 00:00:00 2001 From: Kirill Likhodedov Date: Sun, 3 Nov 2013 19:26:35 +0400 Subject: [PATCH] [log] Add "New Branch", "New Tag" actions to the log + refactor * Extract GitLogSingleCommitAction - the common class for all Git actions on the log, which operate on a single commit. * Implement "New Branch" and "New Tag" actions. Use GitBrancher for the first, reuse the existing CreateNewTag for the latter. * Regroup actions in plugin.xml so that they form a single group which is then added to the Vcs group. It lets add a separator, and also makes the code more clear. --- plugins/git4idea/src/META-INF/plugin.xml | 23 ++++++++--- .../actions/GitCheckoutRevisionAction.java | 34 +++++++++++++++ .../actions/GitCreateNewBranchAction.java | 41 +++++++++++++++++++ .../git4idea/actions/GitCreateTagAction.java | 31 ++++++++++++++ .../GitLogSingleCommitAction.java} | 17 +++++--- 5 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 plugins/git4idea/src/git4idea/actions/GitCheckoutRevisionAction.java create mode 100644 plugins/git4idea/src/git4idea/actions/GitCreateNewBranchAction.java create mode 100644 plugins/git4idea/src/git4idea/actions/GitCreateTagAction.java rename plugins/git4idea/src/git4idea/{branch/GitCheckoutRevisionAction.java => actions/GitLogSingleCommitAction.java} (85%) diff --git a/plugins/git4idea/src/META-INF/plugin.xml b/plugins/git4idea/src/META-INF/plugin.xml index 79aa72185c32..da7d14a9117a 100644 --- a/plugins/git4idea/src/META-INF/plugin.xml +++ b/plugins/git4idea/src/META-INF/plugin.xml @@ -75,14 +75,27 @@ - + + + + + + + + + + + + + + + - + - - - diff --git a/plugins/git4idea/src/git4idea/actions/GitCheckoutRevisionAction.java b/plugins/git4idea/src/git4idea/actions/GitCheckoutRevisionAction.java new file mode 100644 index 000000000000..fc2451820fee --- /dev/null +++ b/plugins/git4idea/src/git4idea/actions/GitCheckoutRevisionAction.java @@ -0,0 +1,34 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.actions; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.vcs.log.VcsFullCommitDetails; +import git4idea.branch.GitBrancher; +import git4idea.repo.GitRepository; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; + +public class GitCheckoutRevisionAction extends GitLogSingleCommitAction { + + @Override + protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) { + GitBrancher brancher = ServiceManager.getService(repository.getProject(), GitBrancher.class); + brancher.checkout(commit.getHash().asString(), Collections.singletonList(repository), null); + } + +} diff --git a/plugins/git4idea/src/git4idea/actions/GitCreateNewBranchAction.java b/plugins/git4idea/src/git4idea/actions/GitCreateNewBranchAction.java new file mode 100644 index 000000000000..e53f243608fd --- /dev/null +++ b/plugins/git4idea/src/git4idea/actions/GitCreateNewBranchAction.java @@ -0,0 +1,41 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.actions; + +import com.intellij.openapi.components.ServiceManager; +import com.intellij.openapi.project.Project; +import com.intellij.vcs.log.VcsFullCommitDetails; +import git4idea.branch.GitBranchUtil; +import git4idea.branch.GitBrancher; +import git4idea.repo.GitRepository; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; + +public class GitCreateNewBranchAction extends GitLogSingleCommitAction { + + @Override + protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) { + Project project = repository.getProject(); + String reference = commit.getHash().asString(); + final String name = GitBranchUtil.getNewBranchNameFromUser(project, Collections.singleton(repository), + "Checkout New Branch From " + reference); + if (name != null) { + GitBrancher brancher = ServiceManager.getService(project, GitBrancher.class); + brancher.checkoutNewBranchStartingFrom(name, reference, Collections.singletonList(repository), null); + } + } +} diff --git a/plugins/git4idea/src/git4idea/actions/GitCreateTagAction.java b/plugins/git4idea/src/git4idea/actions/GitCreateTagAction.java new file mode 100644 index 000000000000..344c236b3f37 --- /dev/null +++ b/plugins/git4idea/src/git4idea/actions/GitCreateTagAction.java @@ -0,0 +1,31 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package git4idea.actions; + +import com.intellij.vcs.log.VcsFullCommitDetails; +import git4idea.history.wholeTree.GitCreateNewTag; +import git4idea.repo.GitRepository; +import org.jetbrains.annotations.NotNull; + +public class GitCreateTagAction extends GitLogSingleCommitAction { + + @Override + protected void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit) { + String reference = commit.getHash().asString(); + new GitCreateNewTag(repository.getProject(), repository, reference, null).execute(); + } + +} diff --git a/plugins/git4idea/src/git4idea/branch/GitCheckoutRevisionAction.java b/plugins/git4idea/src/git4idea/actions/GitLogSingleCommitAction.java similarity index 85% rename from plugins/git4idea/src/git4idea/branch/GitCheckoutRevisionAction.java rename to plugins/git4idea/src/git4idea/actions/GitLogSingleCommitAction.java index f0b4dee02555..364b1f58b15e 100644 --- a/plugins/git4idea/src/git4idea/branch/GitCheckoutRevisionAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitLogSingleCommitAction.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package git4idea.branch; +package git4idea.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.CommonDataKeys; @@ -27,13 +27,18 @@ import com.intellij.vcs.log.VcsLogDataKeys; import git4idea.GitUtil; import git4idea.repo.GitRepository; import git4idea.repo.GitRepositoryManager; +import org.jetbrains.annotations.NotNull; -import java.util.Collections; import java.util.List; -public class GitCheckoutRevisionAction extends DumbAwareAction { +/** + * @author Kirill Likhodedov + */ +public abstract class GitLogSingleCommitAction extends DumbAwareAction { - private static final Logger LOG = Logger.getInstance(GitCheckoutRevisionAction.class); + private static final Logger LOG = Logger.getInstance(GitLogSingleCommitAction.class); + + protected abstract void actionPerformed(@NotNull GitRepository repository, @NotNull VcsFullCommitDetails commit); @Override public void actionPerformed(AnActionEvent e) { @@ -54,8 +59,8 @@ public class GitCheckoutRevisionAction extends DumbAwareAction { GitUtil.noRepositoryForRoot(LOG, commit.getRoot(), data.project); return; } - GitBrancher brancher = ServiceManager.getService(data.project, GitBrancher.class); - brancher.checkout(commit.getHash().asString(), Collections.singletonList(repository), null); + + actionPerformed(repository, commit); } @Override