| 2350 | } |
| 2351 | |
| 2352 | static void copy_templates(struct repository *repo, const char *option_template) |
| 2353 | { |
| 2354 | const char *template_dir = get_template_dir(option_template); |
| 2355 | struct strbuf path = STRBUF_INIT; |
| 2356 | struct strbuf template_path = STRBUF_INIT; |
| 2357 | size_t template_len; |
| 2358 | struct repository_format template_format = REPOSITORY_FORMAT_INIT; |
| 2359 | struct strbuf err = STRBUF_INIT; |
| 2360 | DIR *dir; |
| 2361 | char *to_free = NULL; |
| 2362 | |
| 2363 | if (!template_dir || !*template_dir) |
| 2364 | return; |
| 2365 | |
| 2366 | strbuf_addstr(&template_path, template_dir); |
| 2367 | strbuf_complete(&template_path, '/'); |
| 2368 | template_len = template_path.len; |
| 2369 | |
| 2370 | dir = opendir(template_path.buf); |
| 2371 | if (!dir) { |
| 2372 | warning(_("templates not found in %s"), template_dir); |
| 2373 | goto free_return; |
| 2374 | } |
| 2375 | |
| 2376 | /* Make sure that template is from the correct vintage */ |
| 2377 | strbuf_addstr(&template_path, "config"); |
| 2378 | read_repository_format(&template_format, template_path.buf); |
| 2379 | strbuf_setlen(&template_path, template_len); |
| 2380 | |
| 2381 | /* |
| 2382 | * No mention of version at all is OK, but anything else should be |
| 2383 | * verified. |
| 2384 | */ |
| 2385 | if (template_format.version >= 0 && |
| 2386 | verify_repository_format(&template_format, &err) < 0) { |
| 2387 | warning(_("not copying templates from '%s': %s"), |
| 2388 | template_dir, err.buf); |
| 2389 | strbuf_release(&err); |
| 2390 | goto close_free_return; |
| 2391 | } |
| 2392 | |
| 2393 | strbuf_addstr(&path, repo_get_common_dir(repo)); |
| 2394 | strbuf_complete(&path, '/'); |
| 2395 | copy_templates_1(repo, &path, &template_path, dir); |
| 2396 | close_free_return: |
| 2397 | closedir(dir); |
| 2398 | free_return: |
| 2399 | free(to_free); |
| 2400 | strbuf_release(&path); |
| 2401 | strbuf_release(&template_path); |
| 2402 | clear_repository_format(&template_format); |
| 2403 | } |
| 2404 | |
| 2405 | /* |
| 2406 | * If the git_dir is not directly inside the working tree, then git will not |
no test coverage detected