Fix branches file configuration
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>
Daniel Barkalow committed
Mar 25, 2008 at 19:35 UTC
472fa4cd33c690dd9b338c02af3ed135666aea43
1 file changed
+22
-6
remote.c
+22
-6
@@ -171,7 +171,7 @@ static void read_branches_file(struct remote *remote)
171
{
172
const char *slash = strchr(remote->name, '/');
173
char *frag;
174
- char *branch;
174
+ struct strbuf branch;
175
int n = slash ? slash - remote->name : 1000;
176
FILE *f = fopen(git_path("branches/%.*s", n, remote->name), "r");
177
char *s, *p;
@@ -197,17 +197,33 @@ static void read_branches_file(struct remote *remote)
197
strcpy(p, s);
198
if (slash)
199
strcat(p, slash);
200
+
201
+ /*
202
+ * With "slash", e.g. "git fetch jgarzik/netdev-2.6" when
203
+ * reading from $GIT_DIR/branches/jgarzik fetches "HEAD" from
204
+ * the partial URL obtained from the branches file plus
205
+ * "/netdev-2.6" and does not store it in any tracking ref.
206
+ * #branch specifier in the file is ignored.
207
+ *
208
+ * Otherwise, the branches file would have URL and optionally
209
+ * #branch specified. The "master" (or specified) branch is
210
+ * fetched and stored in the local branch of the same name.
211
+ */
212
+ strbuf_init(&branch, 0);
213
frag = strchr(p, '#');
214
if (frag) {
215
*(frag++) = '\0';
203
- branch = xmalloc(strlen(frag) + 12);
204
- strcpy(branch, "refs/heads/");
205
- strcat(branch, frag);
216
+ strbuf_addf(&branch, "refs/heads/%s", frag);
217
+ } else
218
+ strbuf_addstr(&branch, "refs/heads/master");
219
+ if (!slash) {
220
+ strbuf_addf(&branch, ":refs/heads/%s", remote->name);
221
} else {
207
- branch = "refs/heads/master";
222
+ strbuf_reset(&branch);
223
+ strbuf_addstr(&branch, "HEAD:");
224
}
225
add_url(remote, p);
210
- add_fetch_refspec(remote, branch);
226
+ add_fetch_refspec(remote, strbuf_detach(&branch, 0));
227
remote->fetch_tags = 1; /* always auto-follow */
228
}
229