]>
Commit | Line | Data |
---|---|---|
8bc9a0c7 LT |
1 | /* |
2 | * GIT - The information manager from hell | |
3 | * | |
4 | * Copyright (C) Linus Torvalds, 2005 | |
5 | */ | |
8ed05fb5 | 6 | #include "builtin.h" |
e83c5163 | 7 | #include "cache.h" |
b2141fc1 | 8 | #include "config.h" |
8e440259 | 9 | #include "tree.h" |
a52139b4 | 10 | #include "cache-tree.h" |
404d42e5 | 11 | #include "parse-options.h" |
e83c5163 | 12 | |
404d42e5 | 13 | static const char * const write_tree_usage[] = { |
b5625d07 | 14 | N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"), |
404d42e5 SB |
15 | NULL |
16 | }; | |
75a46f6b | 17 | |
a633fca0 | 18 | int cmd_write_tree(int argc, const char **argv, const char *unused_prefix) |
8ed05fb5 | 19 | { |
d11b8d34 | 20 | int flags = 0, ret; |
8ed05fb5 | 21 | const char *prefix = NULL; |
38b471fa | 22 | struct object_id oid; |
45525bd0 | 23 | const char *me = "git-write-tree"; |
404d42e5 | 24 | struct option write_tree_options[] = { |
b5625d07 | 25 | OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"), |
404d42e5 | 26 | WRITE_TREE_MISSING_OK), |
b5625d07 NTND |
27 | { OPTION_STRING, 0, "prefix", &prefix, N_("<prefix>/"), |
28 | N_("write tree object for a subdirectory <prefix>") , | |
404d42e5 SB |
29 | PARSE_OPT_LITERAL_ARGHELP }, |
30 | { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL, | |
b5625d07 | 31 | N_("only useful for debugging"), |
404d42e5 SB |
32 | PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL, |
33 | WRITE_TREE_IGNORE_CACHE_TREE }, | |
34 | OPT_END() | |
35 | }; | |
8ed05fb5 | 36 | |
ef90d6d4 | 37 | git_config(git_default_config, NULL); |
404d42e5 SB |
38 | argc = parse_options(argc, argv, unused_prefix, write_tree_options, |
39 | write_tree_usage, 0); | |
8ed05fb5 | 40 | |
fc5cb99f | 41 | ret = write_cache_as_tree(&oid, flags, prefix); |
45525bd0 JH |
42 | switch (ret) { |
43 | case 0: | |
38b471fa | 44 | printf("%s\n", oid_to_hex(&oid)); |
45525bd0 JH |
45 | break; |
46 | case WRITE_TREE_UNREADABLE_INDEX: | |
47 | die("%s: error reading the index", me); | |
48 | break; | |
49 | case WRITE_TREE_UNMERGED_INDEX: | |
331fcb59 | 50 | die("%s: error building trees", me); |
45525bd0 JH |
51 | break; |
52 | case WRITE_TREE_PREFIX_ERROR: | |
53 | die("%s: prefix %s not found", me, prefix); | |
54 | break; | |
55 | } | |
8ed05fb5 LS |
56 | return ret; |
57 | } |