summaryrefslogtreecommitdiff
path: root/remote.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2008-03-26 01:49:41 -0700
committerJunio C Hamano <gitster@pobox.com>2008-03-26 01:49:41 -0700
commit660b9c3a4e24ce9a2628f2ec88902e2384d1aade (patch)
tree5fd25724e2838ff6466932702876bcdbfb10204d /remote.c
parent7d19da46fd108ec463e555cb9fd9efd13b582d4a (diff)
parenta466637c57b969626344e5998b29fb123569fdc2 (diff)
downloadgit-660b9c3a4e24ce9a2628f2ec88902e2384d1aade.tar.gz
Merge branch 'jc/maint-fetch-regression-1.5.4'
* jc/maint-fetch-regression-1.5.4: git-fetch test: test tracking fetch results, not just FETCH_HEAD Fix branches file configuration Tighten refspec processing Fix the wrong output of `git-show v1.3.0~155^2~4` in documentation.
Diffstat (limited to 'remote.c')
-rw-r--r--remote.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/remote.c b/remote.c
index 04f7521c29..08af7f9de1 100644
--- a/remote.c
+++ b/remote.c
@@ -232,7 +232,7 @@ static void read_branches_file(struct remote *remote)
{
const char *slash = strchr(remote->name, '/');
char *frag;
- char *branch;
+ struct strbuf branch;
int n = slash ? slash - remote->name : 1000;
FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
char *s, *p;
@@ -258,17 +258,33 @@ static void read_branches_file(struct remote *remote)
strcpy(p, s);
if (slash)
strcat(p, slash);
+
+ /*
+ * 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);
frag = strchr(p, '#');
if (frag) {
*(frag++) = '\0';
- branch = xmalloc(strlen(frag) + 12);
- strcpy(branch, "refs/heads/");
- strcat(branch, frag);
+ strbuf_addf(&branch, "refs/heads/%s", frag);
+ } else
+ strbuf_addstr(&branch, "refs/heads/master");
+ if (!slash) {
+ strbuf_addf(&branch, ":refs/heads/%s", remote->name);
} else {
- branch = "refs/heads/master";
+ strbuf_reset(&branch);
+ strbuf_addstr(&branch, "HEAD:");
}
add_url_alias(remote, p);
- add_fetch_refspec(remote, branch);
+ add_fetch_refspec(remote, strbuf_detach(&branch, 0));
remote->fetch_tags = 1; /* always auto-follow */
}