/src/git/builtin/write-tree.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * GIT - The information manager from hell |
3 | | * |
4 | | * Copyright (C) Linus Torvalds, 2005 |
5 | | */ |
6 | | |
7 | | #include "builtin.h" |
8 | | #include "config.h" |
9 | | #include "environment.h" |
10 | | #include "gettext.h" |
11 | | #include "hex.h" |
12 | | #include "tree.h" |
13 | | #include "cache-tree.h" |
14 | | #include "parse-options.h" |
15 | | #include "repository.h" |
16 | | |
17 | | static const char * const write_tree_usage[] = { |
18 | | N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"), |
19 | | NULL |
20 | | }; |
21 | | |
22 | | int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix) |
23 | 0 | { |
24 | 0 | int flags = 0, ret; |
25 | 0 | const char *tree_prefix = NULL; |
26 | 0 | struct object_id oid; |
27 | 0 | const char *me = "git-write-tree"; |
28 | 0 | struct option write_tree_options[] = { |
29 | 0 | OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"), |
30 | 0 | WRITE_TREE_MISSING_OK), |
31 | 0 | OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"), |
32 | 0 | N_("write tree object for a subdirectory <prefix>")), |
33 | 0 | { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL, |
34 | 0 | N_("only useful for debugging"), |
35 | 0 | PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL, |
36 | 0 | WRITE_TREE_IGNORE_CACHE_TREE }, |
37 | 0 | OPT_END() |
38 | 0 | }; |
39 | |
|
40 | 0 | git_config(git_default_config, NULL); |
41 | 0 | argc = parse_options(argc, argv, cmd_prefix, write_tree_options, |
42 | 0 | write_tree_usage, 0); |
43 | |
|
44 | 0 | prepare_repo_settings(the_repository); |
45 | 0 | the_repository->settings.command_requires_full_index = 0; |
46 | |
|
47 | 0 | ret = write_index_as_tree(&oid, the_repository->index, get_index_file(), |
48 | 0 | flags, tree_prefix); |
49 | 0 | switch (ret) { |
50 | 0 | case 0: |
51 | 0 | printf("%s\n", oid_to_hex(&oid)); |
52 | 0 | break; |
53 | 0 | case WRITE_TREE_UNREADABLE_INDEX: |
54 | 0 | die("%s: error reading the index", me); |
55 | 0 | break; |
56 | 0 | case WRITE_TREE_UNMERGED_INDEX: |
57 | 0 | die("%s: error building trees", me); |
58 | 0 | break; |
59 | 0 | case WRITE_TREE_PREFIX_ERROR: |
60 | 0 | die("%s: prefix %s not found", me, tree_prefix); |
61 | 0 | break; |
62 | 0 | } |
63 | 0 | return ret; |
64 | 0 | } |