]>
Commit | Line | Data |
---|---|---|
8434c2f1 DB |
1 | /* |
2 | * Builtin "git clone" | |
3 | * | |
4 | * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>, | |
5 | * 2008 Daniel Barkalow <barkalow@iabervon.org> | |
6 | * Based on git-commit.sh by Junio C Hamano and Linus Torvalds | |
7 | * | |
8 | * Clone a repository into a different directory that does not yet exist. | |
9 | */ | |
10 | ||
11 | #include "cache.h" | |
12 | #include "parse-options.h" | |
13 | #include "fetch-pack.h" | |
14 | #include "refs.h" | |
15 | #include "tree.h" | |
16 | #include "tree-walk.h" | |
17 | #include "unpack-trees.h" | |
18 | #include "transport.h" | |
19 | #include "strbuf.h" | |
20 | #include "dir.h" | |
3e8aded2 | 21 | #include "pack-refs.h" |
8434c2f1 DB |
22 | |
23 | /* | |
24 | * Overall FIXMEs: | |
25 | * - respect DB_ENVIRONMENT for .git/objects. | |
26 | * | |
27 | * Implementation notes: | |
28 | * - dropping use-separate-remote and no-separate-remote compatibility | |
29 | * | |
30 | */ | |
31 | static const char * const builtin_clone_usage[] = { | |
1b1dd23f | 32 | "git clone [options] [--] <repo> [<dir>]", |
8434c2f1 DB |
33 | NULL |
34 | }; | |
35 | ||
bc699afc | 36 | static int option_quiet, option_no_checkout, option_bare, option_mirror; |
8434c2f1 DB |
37 | static int option_local, option_no_hardlinks, option_shared; |
38 | static char *option_template, *option_reference, *option_depth; | |
39 | static char *option_origin = NULL; | |
40 | static char *option_upload_pack = "git-upload-pack"; | |
41 | ||
42 | static struct option builtin_clone_options[] = { | |
43 | OPT__QUIET(&option_quiet), | |
44 | OPT_BOOLEAN('n', "no-checkout", &option_no_checkout, | |
45 | "don't create a checkout"), | |
46 | OPT_BOOLEAN(0, "bare", &option_bare, "create a bare repository"), | |
47 | OPT_BOOLEAN(0, "naked", &option_bare, "create a bare repository"), | |
bc699afc JS |
48 | OPT_BOOLEAN(0, "mirror", &option_mirror, |
49 | "create a mirror repository (implies bare)"), | |
8434c2f1 DB |
50 | OPT_BOOLEAN('l', "local", &option_local, |
51 | "to clone from a local repository"), | |
52 | OPT_BOOLEAN(0, "no-hardlinks", &option_no_hardlinks, | |
53 | "don't use local hardlinks, always copy"), | |
54 | OPT_BOOLEAN('s', "shared", &option_shared, | |
55 | "setup as shared repository"), | |
56 | OPT_STRING(0, "template", &option_template, "path", | |
57 | "path the template repository"), | |
58 | OPT_STRING(0, "reference", &option_reference, "repo", | |
59 | "reference repository"), | |
60 | OPT_STRING('o', "origin", &option_origin, "branch", | |
61 | "use <branch> instead or 'origin' to track upstream"), | |
62 | OPT_STRING('u', "upload-pack", &option_upload_pack, "path", | |
63 | "path to git-upload-pack on the remote"), | |
64 | OPT_STRING(0, "depth", &option_depth, "depth", | |
65 | "create a shallow clone of that depth"), | |
66 | ||
67 | OPT_END() | |
68 | }; | |
69 | ||
70 | static char *get_repo_path(const char *repo, int *is_bundle) | |
71 | { | |
72 | static char *suffix[] = { "/.git", ".git", "" }; | |
73 | static char *bundle_suffix[] = { ".bundle", "" }; | |
74 | struct stat st; | |
75 | int i; | |
76 | ||
77 | for (i = 0; i < ARRAY_SIZE(suffix); i++) { | |
78 | const char *path; | |
79 | path = mkpath("%s%s", repo, suffix[i]); | |
80 | if (!stat(path, &st) && S_ISDIR(st.st_mode)) { | |
81 | *is_bundle = 0; | |
1b9a9467 | 82 | return xstrdup(make_nonrelative_path(path)); |
8434c2f1 DB |
83 | } |
84 | } | |
85 | ||
86 | for (i = 0; i < ARRAY_SIZE(bundle_suffix); i++) { | |
87 | const char *path; | |
88 | path = mkpath("%s%s", repo, bundle_suffix[i]); | |
89 | if (!stat(path, &st) && S_ISREG(st.st_mode)) { | |
90 | *is_bundle = 1; | |
1b9a9467 | 91 | return xstrdup(make_nonrelative_path(path)); |
8434c2f1 DB |
92 | } |
93 | } | |
94 | ||
95 | return NULL; | |
96 | } | |
97 | ||
6612f877 | 98 | static char *guess_dir_name(const char *repo, int is_bundle, int is_bare) |
8434c2f1 | 99 | { |
b8c5db35 JS |
100 | const char *end = repo + strlen(repo), *start; |
101 | ||
102 | /* | |
103 | * Strip trailing slashes and /.git | |
104 | */ | |
105 | while (repo < end && is_dir_sep(end[-1])) | |
106 | end--; | |
107 | if (end - repo > 5 && is_dir_sep(end[-5]) && | |
108 | !strncmp(end - 4, ".git", 4)) { | |
109 | end -= 5; | |
110 | while (repo < end && is_dir_sep(end[-1])) | |
111 | end--; | |
112 | } | |
113 | ||
114 | /* | |
115 | * Find last component, but be prepared that repo could have | |
116 | * the form "remote.example.com:foo.git", i.e. no slash | |
117 | * in the directory part. | |
118 | */ | |
119 | start = end; | |
120 | while (repo < start && !is_dir_sep(start[-1]) && start[-1] != ':') | |
121 | start--; | |
122 | ||
123 | /* | |
124 | * Strip .{bundle,git}. | |
125 | */ | |
126 | if (is_bundle) { | |
127 | if (end - start > 7 && !strncmp(end - 7, ".bundle", 7)) | |
128 | end -= 7; | |
129 | } else { | |
130 | if (end - start > 4 && !strncmp(end - 4, ".git", 4)) | |
131 | end -= 4; | |
8434c2f1 DB |
132 | } |
133 | ||
6612f877 JS |
134 | if (is_bare) { |
135 | char *result = xmalloc(end - start + 5); | |
136 | sprintf(result, "%.*s.git", (int)(end - start), start); | |
137 | return result; | |
138 | } | |
139 | ||
8434c2f1 DB |
140 | return xstrndup(start, end - start); |
141 | } | |
142 | ||
143 | static int is_directory(const char *path) | |
144 | { | |
145 | struct stat buf; | |
146 | ||
147 | return !stat(path, &buf) && S_ISDIR(buf.st_mode); | |
148 | } | |
149 | ||
150 | static void setup_reference(const char *repo) | |
151 | { | |
152 | const char *ref_git; | |
153 | char *ref_git_copy; | |
154 | ||
155 | struct remote *remote; | |
156 | struct transport *transport; | |
157 | const struct ref *extra; | |
158 | ||
159 | ref_git = make_absolute_path(option_reference); | |
160 | ||
161 | if (is_directory(mkpath("%s/.git/objects", ref_git))) | |
162 | ref_git = mkpath("%s/.git", ref_git); | |
163 | else if (!is_directory(mkpath("%s/objects", ref_git))) | |
164 | die("reference repository '%s' is not a local directory.", | |
165 | option_reference); | |
166 | ||
167 | ref_git_copy = xstrdup(ref_git); | |
168 | ||
169 | add_to_alternates_file(ref_git_copy); | |
170 | ||
171 | remote = remote_get(ref_git_copy); | |
172 | transport = transport_get(remote, ref_git_copy); | |
173 | for (extra = transport_get_remote_refs(transport); extra; | |
174 | extra = extra->next) | |
175 | add_extra_ref(extra->name, extra->old_sha1, 0); | |
176 | ||
177 | transport_disconnect(transport); | |
178 | ||
179 | free(ref_git_copy); | |
180 | } | |
181 | ||
182 | static void copy_or_link_directory(char *src, char *dest) | |
183 | { | |
184 | struct dirent *de; | |
185 | struct stat buf; | |
186 | int src_len, dest_len; | |
187 | DIR *dir; | |
188 | ||
189 | dir = opendir(src); | |
190 | if (!dir) | |
191 | die("failed to open %s\n", src); | |
192 | ||
193 | if (mkdir(dest, 0777)) { | |
194 | if (errno != EEXIST) | |
195 | die("failed to create directory %s\n", dest); | |
196 | else if (stat(dest, &buf)) | |
197 | die("failed to stat %s\n", dest); | |
198 | else if (!S_ISDIR(buf.st_mode)) | |
199 | die("%s exists and is not a directory\n", dest); | |
200 | } | |
201 | ||
202 | src_len = strlen(src); | |
203 | src[src_len] = '/'; | |
204 | dest_len = strlen(dest); | |
205 | dest[dest_len] = '/'; | |
206 | ||
207 | while ((de = readdir(dir)) != NULL) { | |
208 | strcpy(src + src_len + 1, de->d_name); | |
209 | strcpy(dest + dest_len + 1, de->d_name); | |
210 | if (stat(src, &buf)) { | |
211 | warning ("failed to stat %s\n", src); | |
212 | continue; | |
213 | } | |
214 | if (S_ISDIR(buf.st_mode)) { | |
215 | if (de->d_name[0] != '.') | |
216 | copy_or_link_directory(src, dest); | |
217 | continue; | |
218 | } | |
219 | ||
220 | if (unlink(dest) && errno != ENOENT) | |
221 | die("failed to unlink %s\n", dest); | |
fdabc242 DB |
222 | if (!option_no_hardlinks) { |
223 | if (!link(src, dest)) | |
224 | continue; | |
225 | if (option_local) | |
8434c2f1 | 226 | die("failed to create link %s\n", dest); |
fdabc242 | 227 | option_no_hardlinks = 1; |
8434c2f1 | 228 | } |
fdabc242 DB |
229 | if (copy_file(dest, src, 0666)) |
230 | die("failed to copy file to %s\n", dest); | |
8434c2f1 | 231 | } |
689ef4d4 | 232 | closedir(dir); |
8434c2f1 DB |
233 | } |
234 | ||
235 | static const struct ref *clone_local(const char *src_repo, | |
236 | const char *dest_repo) | |
237 | { | |
238 | const struct ref *ret; | |
239 | char src[PATH_MAX]; | |
240 | char dest[PATH_MAX]; | |
241 | struct remote *remote; | |
242 | struct transport *transport; | |
243 | ||
244 | if (option_shared) | |
245 | add_to_alternates_file(src_repo); | |
246 | else { | |
247 | snprintf(src, PATH_MAX, "%s/objects", src_repo); | |
248 | snprintf(dest, PATH_MAX, "%s/objects", dest_repo); | |
249 | copy_or_link_directory(src, dest); | |
250 | } | |
251 | ||
252 | remote = remote_get(src_repo); | |
253 | transport = transport_get(remote, src_repo); | |
254 | ret = transport_get_remote_refs(transport); | |
255 | transport_disconnect(transport); | |
256 | return ret; | |
257 | } | |
258 | ||
259 | static const char *junk_work_tree; | |
260 | static const char *junk_git_dir; | |
261 | pid_t junk_pid; | |
262 | ||
263 | static void remove_junk(void) | |
264 | { | |
265 | struct strbuf sb; | |
266 | if (getpid() != junk_pid) | |
267 | return; | |
268 | strbuf_init(&sb, 0); | |
269 | if (junk_git_dir) { | |
270 | strbuf_addstr(&sb, junk_git_dir); | |
271 | remove_dir_recursively(&sb, 0); | |
272 | strbuf_reset(&sb); | |
273 | } | |
274 | if (junk_work_tree) { | |
275 | strbuf_addstr(&sb, junk_work_tree); | |
276 | remove_dir_recursively(&sb, 0); | |
277 | strbuf_reset(&sb); | |
278 | } | |
279 | } | |
280 | ||
281 | static void remove_junk_on_signal(int signo) | |
282 | { | |
283 | remove_junk(); | |
284 | signal(SIGINT, SIG_DFL); | |
285 | raise(signo); | |
286 | } | |
287 | ||
288 | static const struct ref *locate_head(const struct ref *refs, | |
289 | const struct ref *mapped_refs, | |
290 | const struct ref **remote_head_p) | |
291 | { | |
292 | const struct ref *remote_head = NULL; | |
293 | const struct ref *remote_master = NULL; | |
294 | const struct ref *r; | |
295 | for (r = refs; r; r = r->next) | |
296 | if (!strcmp(r->name, "HEAD")) | |
297 | remote_head = r; | |
298 | ||
299 | for (r = mapped_refs; r; r = r->next) | |
300 | if (!strcmp(r->name, "refs/heads/master")) | |
301 | remote_master = r; | |
302 | ||
303 | if (remote_head_p) | |
304 | *remote_head_p = remote_head; | |
305 | ||
306 | /* If there's no HEAD value at all, never mind. */ | |
307 | if (!remote_head) | |
308 | return NULL; | |
309 | ||
310 | /* If refs/heads/master could be right, it is. */ | |
311 | if (remote_master && !hashcmp(remote_master->old_sha1, | |
312 | remote_head->old_sha1)) | |
313 | return remote_master; | |
314 | ||
315 | /* Look for another ref that points there */ | |
316 | for (r = mapped_refs; r; r = r->next) | |
317 | if (r != remote_head && | |
318 | !hashcmp(r->old_sha1, remote_head->old_sha1)) | |
319 | return r; | |
320 | ||
321 | /* Nothing is the same */ | |
322 | return NULL; | |
323 | } | |
324 | ||
325 | static struct ref *write_remote_refs(const struct ref *refs, | |
326 | struct refspec *refspec, const char *reflog) | |
327 | { | |
328 | struct ref *local_refs = NULL; | |
329 | struct ref **tail = &local_refs; | |
330 | struct ref *r; | |
331 | ||
332 | get_fetch_map(refs, refspec, &tail, 0); | |
468386a9 JS |
333 | if (!option_mirror) |
334 | get_fetch_map(refs, tag_refspec, &tail, 0); | |
8434c2f1 DB |
335 | |
336 | for (r = local_refs; r; r = r->next) | |
3e8aded2 JH |
337 | add_extra_ref(r->peer_ref->name, r->old_sha1, 0); |
338 | ||
339 | pack_refs(PACK_REFS_ALL); | |
340 | clear_extra_refs(); | |
341 | ||
8434c2f1 DB |
342 | return local_refs; |
343 | } | |
344 | ||
345 | int cmd_clone(int argc, const char **argv, const char *prefix) | |
346 | { | |
347 | int use_local_hardlinks = 1; | |
348 | int use_separate_remote = 1; | |
349 | int is_bundle = 0; | |
350 | struct stat buf; | |
351 | const char *repo_name, *repo, *work_tree, *git_dir; | |
352 | char *path, *dir; | |
353 | const struct ref *refs, *head_points_at, *remote_head, *mapped_refs; | |
354 | char branch_top[256], key[256], value[256]; | |
355 | struct strbuf reflog_msg; | |
1db4a75c | 356 | struct transport *transport = NULL; |
bc699afc | 357 | char *src_ref_prefix = "refs/heads/"; |
8434c2f1 DB |
358 | |
359 | struct refspec refspec; | |
360 | ||
361 | junk_pid = getpid(); | |
362 | ||
363 | argc = parse_options(argc, argv, builtin_clone_options, | |
364 | builtin_clone_usage, 0); | |
365 | ||
366 | if (argc == 0) | |
367 | die("You must specify a repository to clone."); | |
368 | ||
369 | if (option_no_hardlinks) | |
370 | use_local_hardlinks = 0; | |
371 | ||
bc699afc JS |
372 | if (option_mirror) |
373 | option_bare = 1; | |
374 | ||
8434c2f1 DB |
375 | if (option_bare) { |
376 | if (option_origin) | |
377 | die("--bare and --origin %s options are incompatible.", | |
378 | option_origin); | |
379 | option_no_checkout = 1; | |
380 | use_separate_remote = 0; | |
381 | } | |
382 | ||
383 | if (!option_origin) | |
384 | option_origin = "origin"; | |
385 | ||
386 | repo_name = argv[0]; | |
387 | ||
388 | path = get_repo_path(repo_name, &is_bundle); | |
389 | if (path) | |
390 | repo = path; | |
391 | else if (!strchr(repo_name, ':')) | |
392 | repo = xstrdup(make_absolute_path(repo_name)); | |
393 | else | |
394 | repo = repo_name; | |
395 | ||
396 | if (argc == 2) | |
397 | dir = xstrdup(argv[1]); | |
398 | else | |
6612f877 | 399 | dir = guess_dir_name(repo_name, is_bundle, option_bare); |
8434c2f1 DB |
400 | |
401 | if (!stat(dir, &buf)) | |
402 | die("destination directory '%s' already exists.", dir); | |
403 | ||
404 | strbuf_init(&reflog_msg, 0); | |
405 | strbuf_addf(&reflog_msg, "clone: from %s", repo); | |
406 | ||
407 | if (option_bare) | |
408 | work_tree = NULL; | |
409 | else { | |
410 | work_tree = getenv("GIT_WORK_TREE"); | |
411 | if (work_tree && !stat(work_tree, &buf)) | |
412 | die("working tree '%s' already exists.", work_tree); | |
413 | } | |
414 | ||
415 | if (option_bare || work_tree) | |
416 | git_dir = xstrdup(dir); | |
417 | else { | |
418 | work_tree = dir; | |
419 | git_dir = xstrdup(mkpath("%s/.git", dir)); | |
420 | } | |
421 | ||
422 | if (!option_bare) { | |
423 | junk_work_tree = work_tree; | |
8e21d63b JK |
424 | if (safe_create_leading_directories_const(work_tree) < 0) |
425 | die("could not create leading directories of '%s'", | |
426 | work_tree); | |
8434c2f1 DB |
427 | if (mkdir(work_tree, 0755)) |
428 | die("could not create work tree dir '%s'.", work_tree); | |
429 | set_git_work_tree(work_tree); | |
430 | } | |
431 | junk_git_dir = git_dir; | |
432 | atexit(remove_junk); | |
433 | signal(SIGINT, remove_junk_on_signal); | |
434 | ||
435 | setenv(CONFIG_ENVIRONMENT, xstrdup(mkpath("%s/config", git_dir)), 1); | |
436 | ||
8e21d63b JK |
437 | if (safe_create_leading_directories_const(git_dir) < 0) |
438 | die("could not create leading directories of '%s'", git_dir); | |
8434c2f1 DB |
439 | set_git_dir(make_absolute_path(git_dir)); |
440 | ||
8434c2f1 DB |
441 | init_db(option_template, option_quiet ? INIT_DB_QUIET : 0); |
442 | ||
5b8063b5 JS |
443 | /* |
444 | * At this point, the config exists, so we do not need the | |
445 | * environment variable. We actually need to unset it, too, to | |
446 | * re-enable parsing of the global configs. | |
447 | */ | |
448 | unsetenv(CONFIG_ENVIRONMENT); | |
449 | ||
8434c2f1 DB |
450 | if (option_reference) |
451 | setup_reference(git_dir); | |
452 | ||
9bd81e42 | 453 | git_config(git_default_config, NULL); |
8434c2f1 DB |
454 | |
455 | if (option_bare) { | |
bc699afc JS |
456 | if (option_mirror) |
457 | src_ref_prefix = "refs/"; | |
458 | strcpy(branch_top, src_ref_prefix); | |
8434c2f1 DB |
459 | |
460 | git_config_set("core.bare", "true"); | |
461 | } else { | |
462 | snprintf(branch_top, sizeof(branch_top), | |
463 | "refs/remotes/%s/", option_origin); | |
bc699afc | 464 | } |
8434c2f1 | 465 | |
bc699afc | 466 | if (option_mirror || !option_bare) { |
8434c2f1 | 467 | /* Configure the remote */ |
bc699afc JS |
468 | if (option_mirror) { |
469 | snprintf(key, sizeof(key), | |
470 | "remote.%s.mirror", option_origin); | |
471 | git_config_set(key, "true"); | |
472 | } | |
473 | ||
8434c2f1 DB |
474 | snprintf(key, sizeof(key), "remote.%s.url", option_origin); |
475 | git_config_set(key, repo); | |
476 | ||
477 | snprintf(key, sizeof(key), "remote.%s.fetch", option_origin); | |
478 | snprintf(value, sizeof(value), | |
bc699afc | 479 | "+%s*:%s*", src_ref_prefix, branch_top); |
8434c2f1 DB |
480 | git_config_set_multivar(key, value, "^$", 0); |
481 | } | |
482 | ||
483 | refspec.force = 0; | |
484 | refspec.pattern = 1; | |
bc699afc | 485 | refspec.src = src_ref_prefix; |
8434c2f1 DB |
486 | refspec.dst = branch_top; |
487 | ||
488 | if (path && !is_bundle) | |
489 | refs = clone_local(path, git_dir); | |
490 | else { | |
491 | struct remote *remote = remote_get(argv[0]); | |
1db4a75c | 492 | transport = transport_get(remote, remote->url[0]); |
8434c2f1 | 493 | |
37b78c25 JK |
494 | if (!transport->get_refs_list || !transport->fetch) |
495 | die("Don't know how to clone %s", transport->url); | |
496 | ||
8434c2f1 DB |
497 | transport_set_option(transport, TRANS_OPT_KEEP, "yes"); |
498 | ||
499 | if (option_depth) | |
500 | transport_set_option(transport, TRANS_OPT_DEPTH, | |
501 | option_depth); | |
502 | ||
503 | if (option_quiet) | |
504 | transport->verbose = -1; | |
505 | ||
837c8767 SH |
506 | if (option_upload_pack) |
507 | transport_set_option(transport, TRANS_OPT_UPLOADPACK, | |
508 | option_upload_pack); | |
509 | ||
8434c2f1 DB |
510 | refs = transport_get_remote_refs(transport); |
511 | transport_fetch_refs(transport, refs); | |
512 | } | |
513 | ||
514 | clear_extra_refs(); | |
515 | ||
516 | mapped_refs = write_remote_refs(refs, &refspec, reflog_msg.buf); | |
517 | ||
518 | head_points_at = locate_head(refs, mapped_refs, &remote_head); | |
519 | ||
520 | if (head_points_at) { | |
521 | /* Local default branch link */ | |
522 | create_symref("HEAD", head_points_at->name, NULL); | |
523 | ||
524 | if (!option_bare) { | |
525 | struct strbuf head_ref; | |
526 | const char *head = head_points_at->name; | |
527 | ||
528 | if (!prefixcmp(head, "refs/heads/")) | |
529 | head += 11; | |
530 | ||
531 | /* Set up the initial local branch */ | |
532 | ||
533 | /* Local branch initial value */ | |
534 | update_ref(reflog_msg.buf, "HEAD", | |
535 | head_points_at->old_sha1, | |
536 | NULL, 0, DIE_ON_ERR); | |
537 | ||
538 | strbuf_init(&head_ref, 0); | |
539 | strbuf_addstr(&head_ref, branch_top); | |
540 | strbuf_addstr(&head_ref, "HEAD"); | |
541 | ||
542 | /* Remote branch link */ | |
543 | create_symref(head_ref.buf, | |
544 | head_points_at->peer_ref->name, | |
545 | reflog_msg.buf); | |
546 | ||
547 | snprintf(key, sizeof(key), "branch.%s.remote", head); | |
548 | git_config_set(key, option_origin); | |
549 | snprintf(key, sizeof(key), "branch.%s.merge", head); | |
550 | git_config_set(key, head_points_at->name); | |
551 | } | |
552 | } else if (remote_head) { | |
553 | /* Source had detached HEAD pointing somewhere. */ | |
554 | if (!option_bare) | |
555 | update_ref(reflog_msg.buf, "HEAD", | |
556 | remote_head->old_sha1, | |
557 | NULL, REF_NODEREF, DIE_ON_ERR); | |
558 | } else { | |
559 | /* Nothing to checkout out */ | |
560 | if (!option_no_checkout) | |
561 | warning("remote HEAD refers to nonexistent ref, " | |
562 | "unable to checkout.\n"); | |
563 | option_no_checkout = 1; | |
564 | } | |
565 | ||
1db4a75c SP |
566 | if (transport) |
567 | transport_unlock_pack(transport); | |
568 | ||
8434c2f1 DB |
569 | if (!option_no_checkout) { |
570 | struct lock_file *lock_file = xcalloc(1, sizeof(struct lock_file)); | |
571 | struct unpack_trees_options opts; | |
572 | struct tree *tree; | |
573 | struct tree_desc t; | |
574 | int fd; | |
575 | ||
576 | /* We need to be in the new work tree for the checkout */ | |
577 | setup_work_tree(); | |
578 | ||
579 | fd = hold_locked_index(lock_file, 1); | |
580 | ||
581 | memset(&opts, 0, sizeof opts); | |
582 | opts.update = 1; | |
a73bc127 JS |
583 | opts.merge = 1; |
584 | opts.fn = oneway_merge; | |
8434c2f1 | 585 | opts.verbose_update = !option_quiet; |
a73bc127 | 586 | opts.src_index = &the_index; |
8434c2f1 DB |
587 | opts.dst_index = &the_index; |
588 | ||
589 | tree = parse_tree_indirect(remote_head->old_sha1); | |
590 | parse_tree(tree); | |
591 | init_tree_desc(&t, tree->buffer, tree->size); | |
592 | unpack_trees(1, &t, &opts); | |
593 | ||
594 | if (write_cache(fd, active_cache, active_nr) || | |
595 | commit_locked_index(lock_file)) | |
596 | die("unable to write new index file"); | |
597 | } | |
598 | ||
599 | strbuf_release(&reflog_msg); | |
600 | junk_pid = 0; | |
601 | return 0; | |
602 | } |