Bug 400414 - CreateBranchCommand does not support tracking remotes with / in name
Summary: CreateBranchCommand does not support tracking remotes with / in name
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 2.2   Edit
Hardware: PC Linux
: P3 normal with 1 vote (vote)
Target Milestone: 3.4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2013-02-10 19:43 EST by Abdullah Asif CLA
Modified: 2014-04-27 10:23 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Abdullah Asif CLA 2013-02-10 19:43:51 EST
CreateBranchCommand does not support tracking remotes with "/" character in it.

Step 1) Configure a remote, "github/asif"

Step 2) Fetch branches from the remote, "github/asif"

Step 3) Create Branch with starting point (or tracked to) "github/asif/master"

CreateBranchCommand will create local branch "master" as follows,

[branch "master"]
    remote = github
    merge = refs/heads/asif/master

It should have been remote = github/asif. Btw, jGit as well as git cli allows creating remote with / characters in the name.

After doing a bit of debugging, following snippet in class CreateBranchCommand causes the issue; It blindly tokenizes based of "/" which is not very clever as it breaks when remote name has "/" character.

String[] tokens = baseBranch.split("/", 4);
boolean isRemote = tokens[1].equals("remotes");
if (isRemote) {
	// refs/remotes/<remote name>/<branch>
	String remoteName = tokens[2];
	String branchName = tokens[3];
	config
			.setString(ConfigConstants.CONFIG_BRANCH_SECTION,
					name, ConfigConstants.CONFIG_KEY_REMOTE,
					remoteName);
	config.setString(ConfigConstants.CONFIG_BRANCH_SECTION,
			name, ConfigConstants.CONFIG_KEY_MERGE,
			Constants.R_HEADS + branchName);
}
Comment 1 Robin Stocker CLA 2014-04-25 18:13:54 EDT
Looks to be still a problem. The right thing to do would be to go through the remote name to see which one matches and then use the remaining part of the string for the branch name.
Comment 3 Matthias Sohn CLA 2014-04-27 10:23:51 EDT
(In reply to Robin Rosenberg from comment #2)
> Patches:
> 
> https://git.eclipse.org/r/#/c/25604/
merged as 36f58ef867fc180aaca20dfa58a1b14f6b79e59a

> https://git.eclipse.org/r/#/c/25603/1
merged as 6605255d9906c5277d215396ebcc395484b9f10c

> https://git.eclipse.org/r/#/c/25605/
merged as e329fb8c8d0afa6a93cd73c8b7978ff77db05c81