From 36f58ef867fc180aaca20dfa58a1b14f6b79e59a Mon Sep 17 00:00:00 2001 From: Robin Rosenberg Date: Sat, 26 Apr 2014 13:05:53 +0200 Subject: [PATCH] Fix ArrayIndexOutOfBoundsException in CreateBranchCommand If remote name contains / or there was a branch directly under the refs/remotes namespace (wrong) the computation of remote name and suggested local branch name would fail. Fix this by looking at the configured remotes. A ref under refs/remotes that does not match a remote configuration is not considered a remote tracking branch anymore. This patch does not fix all similar errors in EGit/JGit. Bug: 411002 Bug: 400414 Change-Id: I2515a6ed05f9104c387ce4e43b24dae942ae2473 --- .../src/org/eclipse/jgit/api/CreateBranchCommand.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java index aa1484c0f..92e8b466b 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java @@ -246,12 +246,11 @@ public class CreateBranchCommand extends GitCommand { if (doConfigure) { StoredConfig config = repo.getConfig(); - String[] tokens = baseBranch.split("/", 4); //$NON-NLS-1$ - boolean isRemote = tokens[1].equals("remotes"); //$NON-NLS-1$ - if (isRemote) { - // refs/remotes// - String remoteName = tokens[2]; - String branchName = tokens[3]; + + String remoteName = repo.getRemoteName(baseBranch); + if (remoteName != null) { + String branchName = repo + .shortenRemoteBranchName(baseBranch); config .setString(ConfigConstants.CONFIG_BRANCH_SECTION, name, ConfigConstants.CONFIG_KEY_REMOTE,