summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: c091b3d)
raw | patch | inline | side by side (parent: c091b3d)
author | Daniel Barkalow <barkalow@iabervon.org> | |
Tue, 25 Mar 2008 23:35:28 +0000 (19:35 -0400) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 26 Mar 2008 07:50:51 +0000 (00:50 -0700) |
Fetched remote branch from .git/branches/foo should fetch into
refs/heads/foo. Also when partial URL is given, the fetched head should
always be remote HEAD, and the result should not be stored anywhere.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/heads/foo. Also when partial URL is given, the fetched head should
always be remote HEAD, and the result should not be stored anywhere.
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
remote.c | patch | blob | history |
diff --git a/remote.c b/remote.c
index 95d65a07ef3b2a1076936e47bb98d5b6095c95e7..d8a4671e68b4b59611ca4826dc88586f044210d5 100644 (file)
--- a/remote.c
+++ b/remote.c
{
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;
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(remote, p);
- add_fetch_refspec(remote, branch);
+ add_fetch_refspec(remote, strbuf_detach(&branch, 0));
remote->fetch_tags = 1; /* always auto-follow */
}