diff options
author | Gerd Zanker | 2013-12-28 13:33:01 +0000 |
---|---|---|
committer | Matthias Sohn | 2014-02-13 19:10:18 +0000 |
commit | a41ca8e7db559cdeb7dfdc31edb3d5081eeba654 (patch) | |
tree | 8e6ddce6ab206744c598c3c3ca0b365f68ae83ce | |
parent | 8040df0d82d85cc5684628cf8f3b3090930602b1 (diff) | |
download | egit-a41ca8e7db559cdeb7dfdc31edb3d5081eeba654.tar.gz egit-a41ca8e7db559cdeb7dfdc31edb3d5081eeba654.tar.xz egit-a41ca8e7db559cdeb7dfdc31edb3d5081eeba654.zip |
Add a config option for the default source ref when branching
[workflow]
defbranchstartpoint = refs/remotes/origin/master
This change is needed to enable the automatic creation and
checkout of branches based on the active task.
Bug: 309578
Change-Id: I66b0997a697978d90edf6ec946dc1ab7f8d4466b
AlsoBy: Steffen Pingel <steffen.pingel@tasktop.com>
AlsoBy: Manuel Doninger <manuel.doninger@googlemail.com>
Signed-off-by: Steffen Pingel <steffen.pingel@tasktop.com>
Signed-off-by: Gerd Zanker <gerd.zanker@web.de>
Signed-off-by: Stefan Lay <stefan.lay@sap.com>
4 files changed, 51 insertions, 39 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java index 5161e5aa85..9a63a03ad6 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/actions/SwitchToMenu.java @@ -29,6 +29,7 @@ import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jgit.lib.CheckoutEntry; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.ReflogEntry; @@ -116,7 +117,19 @@ public class SwitchToMenu extends ContributionItem implements newBranch.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - BranchOperationUI.create(repository).start(); + String sourceRef = repository.getConfig().getString( + ConfigConstants.CONFIG_WORKFLOW_SECTION, null, + ConfigConstants.CONFIG_KEY_DEFBRANCHSTARTPOINT); + try { + Ref ref = repository.getRef(sourceRef); + if (ref != null) + BranchOperationUI.createWithRef(repository, + ref.getName()).start(); + else + BranchOperationUI.create(repository).start(); + } catch (IOException e1) { + BranchOperationUI.create(repository).start(); + } } }); new MenuItem(menu, SWT.SEPARATOR); diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java index fa862011ac..ce95977e2e 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/branch/BranchOperationUI.java @@ -70,6 +70,8 @@ public class BranchOperationUI { private String target; + private String base; + /** * In the case of checkout conflicts, a dialog is shown to let the user * stash, reset or commit. After that, checkout is tried again. The second @@ -112,6 +114,19 @@ public class BranchOperationUI { } /** + * Create an operation for creating a local branch with a given base reference + * + * @param repository + * @param baseRef + * @return the {@link BranchOperationUI} + */ + public static BranchOperationUI createWithRef(Repository repository, String baseRef) { + BranchOperationUI op = new BranchOperationUI(repository, MODE_CREATE); + op.base = baseRef; + return op; + } + + /** * Create an operation for checking out a local branch * * @param repository @@ -345,7 +360,9 @@ public class BranchOperationUI { case MODE_CREATE: CreateBranchWizard wiz; try { - wiz = new CreateBranchWizard(repository, repository.getFullBranch()); + if (base == null) + base = repository.getFullBranch(); + wiz = new CreateBranchWizard(repository, base); } catch (IOException e) { wiz = new CreateBranchWizard(repository); } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionAndEditDialog.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionAndEditDialog.java index 874de62b5c..fa597aad02 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionAndEditDialog.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/BranchSelectionAndEditDialog.java @@ -30,7 +30,9 @@ import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.jgit.api.Git; +import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.lib.Repository; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; @@ -168,8 +170,23 @@ public class BranchSelectionAndEditDialog extends newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - CreateBranchWizard wiz = new CreateBranchWizard(repo, - refNameFromDialog()); + // try to read default source ref from git config + // in the case that no base is selected in dialog + String base = refNameFromDialog(); + if (base == null) { + String sourceRef = repo.getConfig().getString( + ConfigConstants.CONFIG_WORKFLOW_SECTION, null, + ConfigConstants.CONFIG_KEY_DEFBRANCHSTARTPOINT); + try { + Ref ref = repo.getRef(sourceRef); + if (ref != null) { + base = ref.getName(); + } + } catch (IOException e1) { + // base = null; + } + } + CreateBranchWizard wiz = new CreateBranchWizard(repo, base); if (new WizardDialog(getShell(), wiz).open() == Window.OK) { String newRefName = wiz.getNewBranchName(); try { diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CreateBranchCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CreateBranchCommand.java index a0f8c29fb0..3cf4961b6d 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CreateBranchCommand.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CreateBranchCommand.java @@ -21,7 +21,6 @@ import org.eclipse.egit.ui.internal.repository.CreateBranchWizard; import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode; import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Ref; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevWalk; @@ -56,40 +55,6 @@ public class CreateBranchCommand extends String base = null; if (node.getObject() instanceof Ref) base = ((Ref) node.getObject()).getName(); - else { - // we are on another node, so we have no Ref as context - // -> try to determine the currently checked out branch - Ref branch; - try { - if (node.getRepository().getFullBranch().startsWith( - Constants.R_HEADS)) { - // simple case: local branch checked out - branch = node.getRepository().getRef( - node.getRepository().getFullBranch()); - } else { - // remote branch or tag checked out: resolve the commit - String ref = Activator - .getDefault() - .getRepositoryUtil() - .mapCommitToRef(node.getRepository(), - node.getRepository().getFullBranch(), false); - if (ref == null) - branch = null; - else { - if (ref.startsWith(Constants.R_TAGS)) - // if a tag is checked out, we don't suggest - // anything - branch = null; - else - branch = node.getRepository().getRef(ref); - } - } - } catch (IOException e) { - branch = null; - } - if (branch != null) - base = branch.getName(); - } new WizardDialog(getShell(event), new CreateBranchWizard(node .getRepository(), base)).open(); return null; |