const char *slash = strchr(remote->name, '/');
int n = slash ? slash - remote->name : 1000;
FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
+ * With "slash", e.g. "git fetch jgarzik/netdev-2.6" when
+ * reading from $GIT_DIR/branches/jgarzik fetches "HEAD" from
+ * the partial URL obtained from the branches file plus
+ * "/netdev-2.6" and does not store it in any tracking ref.
+ * #branch specifier in the file is ignored.
+ * Otherwise, the branches file would have URL and optionally
+ * #branch specified. The "master" (or specified) branch is
+ * fetched and stored in the local branch of the same name.
+ strbuf_init(&branch, 0);
- branch = xmalloc(strlen(frag) + 12);
- strcpy(branch, "refs/heads/");
+ strbuf_addf(&branch, "refs/heads/%s", frag);
+ strbuf_addstr(&branch, "refs/heads/master");
+ strbuf_addf(&branch, ":refs/heads/%s", remote->name);
- branch = "refs/heads/master";
+ strbuf_addstr(&branch, "HEAD:");
- add_fetch_refspec(remote, branch);
+ add_fetch_refspec(remote, branch);
remote->fetch_tags = 1; /* always auto-follow */