Remove Git -> "Change Tracked Branch" action
authorKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Wed, 1 Feb 2012 13:28:01 +0000 (17:28 +0400)
committerKirill Likhodedov <Kirill.Likhodedov@jetbrains.com>
Wed, 1 Feb 2012 14:01:21 +0000 (18:01 +0400)
The only popular reasonable use cases of setting/changing tracked branch are: sharing the local branch by pushing it, and checking out a remote branch as local.
Both actions are available via Push and GitBranchPopup, so there is no need in this action, especially since it confuses some users.

plugins/git4idea/src/META-INF/plugin.xml
plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java [deleted file]
plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.form [deleted file]
plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.java [deleted file]

index cba4acd503cfbe3ba5ccc2a09ff1cc622c139c20..b03f30f168046f842f2bd1d988aac0ab379edf45 100644 (file)
@@ -36,7 +36,6 @@
 
     <group id="GitRepositoryActions">
       <action id="Git.Branches" class="git4idea.ui.branch.GitBranchesAction" text="_Branches"/>
-      <action id="Git.CurrentBranch" class="git4idea.actions.GitCurrentBranch" text="Configure Tracked Branch..."/>
       <separator/>
 
       <action id="Git.Tag" class="git4idea.actions.GitTag" text="Tag Files..."/>
diff --git a/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java b/plugins/git4idea/src/git4idea/actions/GitCurrentBranch.java
deleted file mode 100644 (file)
index 02242e9..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright 2000-2009 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.project.Project;
-import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vfs.VirtualFile;
-import git4idea.i18n.GitBundle;
-import git4idea.ui.CurrentBranchDialog;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.List;
-import java.util.Set;
-
-/**
- * Git action for showing the current branch
- */
-public class GitCurrentBranch extends GitRepositoryAction {
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  @NotNull
-  protected String getActionName() {
-    return GitBundle.getString("current.branch.action.name");
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  protected void perform(@NotNull final Project project,
-                         @NotNull final List<VirtualFile> gitRoots,
-                         @NotNull final VirtualFile defaultRoot,
-                         final Set<VirtualFile> affectedRoots,
-                         final List<VcsException> exceptions) throws VcsException {
-    CurrentBranchDialog dialog = new CurrentBranchDialog(project, gitRoots, defaultRoot);
-    dialog.show();
-    if (dialog.isOK()) {
-      dialog.updateTrackedBranch();
-    }
-  }
-}
diff --git a/plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.form b/plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.form
deleted file mode 100644 (file)
index 51e5e8d..0000000
+++ /dev/null
@@ -1,94 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="git4idea.ui.CurrentBranchDialog">
-  <grid id="27dc6" binding="myPanel" layout-manager="GridLayoutManager" row-count="6" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
-    <margin top="0" left="0" bottom="0" right="0"/>
-    <constraints>
-      <xy x="20" y="20" width="500" height="165"/>
-    </constraints>
-    <properties/>
-    <border type="none"/>
-    <children>
-      <component id="2ab6f" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="5be22"/>
-          <text resource-bundle="git4idea/i18n/GitBundle" key="common.git.root"/>
-        </properties>
-      </component>
-      <vspacer id="c04c7">
-        <constraints>
-          <grid row="5" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
-        </constraints>
-      </vspacer>
-      <component id="5be22" class="javax.swing.JComboBox" binding="myGitRoot">
-        <constraints>
-          <grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="common.git.root.tooltip"/>
-        </properties>
-      </component>
-      <component id="c406c" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text resource-bundle="git4idea/i18n/GitBundle" key="common.current.branch"/>
-        </properties>
-      </component>
-      <component id="7211d" class="javax.swing.JLabel" binding="myCurrentBranch">
-        <constraints>
-          <grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text value=""/>
-          <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="common.current.branch.tooltip"/>
-        </properties>
-      </component>
-      <component id="31c5d" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="217e"/>
-          <text resource-bundle="git4idea/i18n/GitBundle" key="current.branch.tracked.repository"/>
-        </properties>
-      </component>
-      <component id="217e" class="javax.swing.JComboBox" binding="myRepositoryComboBox" default-binding="true">
-        <constraints>
-          <grid row="3" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="current.branch.tracked.repository.tooltip"/>
-        </properties>
-      </component>
-      <component id="79e75" class="javax.swing.JLabel">
-        <constraints>
-          <grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <labelFor value="88f68"/>
-          <text resource-bundle="git4idea/i18n/GitBundle" key="current.branch.tracked.branch"/>
-        </properties>
-      </component>
-      <component id="88f68" class="javax.swing.JComboBox" binding="myBranchComboBox" default-binding="true">
-        <constraints>
-          <grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <toolTipText resource-bundle="git4idea/i18n/GitBundle" key="current.branch.tracked.branch.tooltip"/>
-        </properties>
-      </component>
-      <component id="24b6e" class="com.intellij.ui.TitledSeparator">
-        <constraints>
-          <grid row="2" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="2" fill="1" indent="0" use-parent-layout="false"/>
-        </constraints>
-        <properties>
-          <text resource-bundle="git4idea/i18n/GitBundle" key="current.branch.tracked.title"/>
-        </properties>
-      </component>
-    </children>
-  </grid>
-</form>
diff --git a/plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.java b/plugins/git4idea/src/git4idea/ui/CurrentBranchDialog.java
deleted file mode 100644 (file)
index 1912231..0000000
+++ /dev/null
@@ -1,269 +0,0 @@
-/*
- * Copyright 2000-2009 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.ui;
-
-import com.intellij.openapi.project.Project;
-import com.intellij.openapi.ui.DialogWrapper;
-import com.intellij.openapi.vcs.VcsException;
-import com.intellij.openapi.vfs.VirtualFile;
-import git4idea.GitBranch;
-import git4idea.GitDeprecatedRemote;
-import git4idea.i18n.GitBundle;
-import git4idea.util.GitUIUtil;
-
-import javax.swing.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Current branch dialog
- */
-public class CurrentBranchDialog extends DialogWrapper {
-  /**
-   * The selection used to indicate that the branch from the current repository is tracked
-   */
-  private static final String REMOTE_THIS = GitBundle.getString("current.branch.tracked.remote.this");
-  /**
-   * The selection used to indicate that nothing is tracked
-   */
-  private static final String REMOTE_NONE = GitBundle.getString("current.branch.tracked.remote.none");
-  /**
-   * The selection used to indicate that nothing is tracked
-   */
-  private static final String BRANCH_NONE = GitBundle.getString("current.branch.tracked.branch.none");
-  /**
-   * The container panel
-   */
-  private JPanel myPanel;
-  /**
-   * Git root selector
-   */
-  private JComboBox myGitRoot;
-  /**
-   * The current branch
-   */
-  private JLabel myCurrentBranch;
-  /**
-   * The repository
-   */
-  private JComboBox myRepositoryComboBox;
-  /**
-   * The tracked branch
-   */
-  private JComboBox myBranchComboBox;
-  /**
-   * The branches to merge
-   */
-  private final List<GitBranch> myBranches = new ArrayList<GitBranch>();
-  /**
-   * The repository tracked for the current branch
-   */
-  private String myTrackedRepository;
-  /**
-   * The tracked branch
-   */
-  private String myTrackedBranch;
-  /**
-   * The current project for the dialog
-   */
-  private final Project myProject;
-
-  /**
-   * A constructor
-   *
-   * @param project     the context project
-   * @param roots       the git roots for the project
-   * @param defaultRoot the default root
-   * @throws VcsException if there is a problem with running git
-   */
-  public CurrentBranchDialog(Project project, List<VirtualFile> roots, VirtualFile defaultRoot) throws VcsException {
-    super(project, true);
-    myProject = project;
-    setTitle(GitBundle.getString("current.branch.title"));
-    setOKButtonText(GitBundle.getString("current.branch.change.tracked"));
-    GitUIUtil.setupRootChooser(project, roots, defaultRoot, myGitRoot, myCurrentBranch);
-    myGitRoot.addActionListener(new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        try {
-          rootUpdated();
-        }
-        catch (VcsException ex) {
-          GitUIUtil.showOperationError(myProject, ex, "git config");
-        }
-      }
-    });
-    myRepositoryComboBox.addActionListener(new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        trackedRemoteUpdated();
-      }
-    });
-    myBranchComboBox.addActionListener(new ActionListener() {
-      public void actionPerformed(ActionEvent e) {
-        validateFields();
-      }
-    });
-    rootUpdated();
-    init();
-  }
-
-  /**
-   * Update tracked branches for the root
-   *
-   * @throws VcsException if there is a problem with git
-   */
-  private void rootUpdated() throws VcsException {
-    VirtualFile root = getRoot();
-    GitBranch current = GitBranch.current(myProject, root);
-    myRepositoryComboBox.removeAllItems();
-    myRepositoryComboBox.addItem(REMOTE_NONE);
-    if (current != null) {
-      myRepositoryComboBox.addItem(REMOTE_THIS);
-      for (GitDeprecatedRemote r : GitDeprecatedRemote.list(myProject, root)) {
-        myRepositoryComboBox.addItem(r.name());
-      }
-    }
-    myTrackedRepository = current == null ? null : current.getTrackedRemoteName(myProject, root);
-    if (myTrackedRepository == null) {
-      myTrackedRepository = REMOTE_NONE;
-    }
-    else if (".".equals(myTrackedRepository)) {
-      myTrackedRepository = REMOTE_THIS;
-    }
-    myTrackedBranch = current == null ? null : current.getTrackedBranchName(myProject, root);
-    if (myTrackedBranch == null) {
-      myTrackedBranch = BRANCH_NONE;
-    }
-    else if (myTrackedBranch.startsWith(GitBranch.REFS_HEADS_PREFIX)) {
-      myTrackedBranch = myTrackedBranch.substring(GitBranch.REFS_HEADS_PREFIX.length());
-    }
-    myRepositoryComboBox.setSelectedItem(myTrackedRepository);
-    myBranches.clear();
-    GitBranch.list(myProject, root, true, true, myBranches, null);
-    trackedRemoteUpdated();
-  }
-
-  /**
-   * Update tracked remote
-   */
-  private void trackedRemoteUpdated() {
-    String remote = getTrackedRemote();
-    myBranchComboBox.removeAllItems();
-    if (REMOTE_NONE.equals(remote)) {
-      myBranchComboBox.addItem(BRANCH_NONE);
-      myBranchComboBox.setSelectedItem(BRANCH_NONE);
-    }
-    else {
-      if (REMOTE_THIS.equals(remote)) {
-        for (GitBranch b : myBranches) {
-          if (!b.isRemote()) {
-            myBranchComboBox.addItem(b.getName());
-          }
-        }
-      }
-      else {
-        String prefix = GitBranch.REFS_REMOTES_PREFIX + remote + "/";
-        for (GitBranch b : myBranches) {
-          if (b.isRemote()) {
-            String name = b.getFullName();
-            if (name.startsWith(prefix)) {
-              myBranchComboBox.addItem(b.getFullName().substring(prefix.length()));
-            }
-          }
-        }
-      }
-      if (myTrackedBranch != null) {
-        // select the same branch for the remote if it exists
-        myBranchComboBox.setSelectedItem(myTrackedBranch);
-      }
-    }
-    validateFields();
-  }
-
-  /**
-   * Specify new tracked branch
-   *
-   * @throws VcsException if there is a problem with calling git
-   */
-  public void updateTrackedBranch() throws VcsException {
-    String remote = getTrackedRemote();
-    String branch = getTrackedBranch();
-    if (remote.equals(REMOTE_NONE) || branch.equals(REMOTE_NONE)) {
-      remote = null;
-      branch = null;
-    }
-    else if (remote.equals(REMOTE_THIS)) {
-      remote = ".";
-    }
-    GitBranch c = GitBranch.current(myProject, getRoot());
-    if (c != null) {
-      c.setTrackedBranch(myProject, getRoot(), remote, GitBranch.REFS_HEADS_PREFIX + branch);
-    }
-  }
-
-  /**
-   * @return the currently selected tracked remote ({@link #REMOTE_NONE} if no branch is tracked)
-   */
-  private String getTrackedRemote() {
-    String remote = (String)myRepositoryComboBox.getSelectedItem();
-    return remote == null ? REMOTE_NONE : remote;
-  }
-
-  /**
-   * Validate fields and update tracked branch as result
-   */
-  private void validateFields() {
-    if (getTrackedRemote().equals(myTrackedRepository) && getTrackedBranch().equals(myTrackedBranch)) {
-      // nothing to change
-      setOKActionEnabled(false);
-    }
-    else {
-      setOKActionEnabled(true);
-    }
-  }
-
-  /**
-   * @return the currently selected tracked branch ({@link #BRANCH_NONE} if no branch is tracked)
-   */
-  private String getTrackedBranch() {
-    String branch = (String)myBranchComboBox.getSelectedItem();
-    return branch == null ? BRANCH_NONE : branch;
-  }
-
-  /**
-   * @return the current git root
-   */
-  private VirtualFile getRoot() {
-    return GitUIUtil.getRootFromRootChooser(myGitRoot);
-  }
-
-
-  /**
-   * {@inheritDoc}
-   */
-  protected JComponent createCenterPanel() {
-    return myPanel;
-  }
-
-  /**
-   * {@inheritDoc}
-   */
-  @Override
-  protected String getHelpId() {
-    return "reference.vcs.git.current.branch";
-  }
-}