2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_INDEX_VARIABLE
11 #include "cache-tree.h"
12 #include "parse-options.h"
14 static const char * const write_tree_usage
[] = {
15 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
19 int cmd_write_tree(int argc
, const char **argv
, const char *cmd_prefix
)
22 const char *tree_prefix
= NULL
;
24 const char *me
= "git-write-tree";
25 struct option write_tree_options
[] = {
26 OPT_BIT(0, "missing-ok", &flags
, N_("allow missing objects"),
27 WRITE_TREE_MISSING_OK
),
28 OPT_STRING(0, "prefix", &tree_prefix
, N_("<prefix>/"),
29 N_("write tree object for a subdirectory <prefix>")),
30 { OPTION_BIT
, 0, "ignore-cache-tree", &flags
, NULL
,
31 N_("only useful for debugging"),
32 PARSE_OPT_HIDDEN
| PARSE_OPT_NOARG
, NULL
,
33 WRITE_TREE_IGNORE_CACHE_TREE
},
37 git_config(git_default_config
, NULL
);
38 argc
= parse_options(argc
, argv
, cmd_prefix
, write_tree_options
,
41 ret
= write_index_as_tree(&oid
, &the_index
, get_index_file(), flags
,
45 printf("%s\n", oid_to_hex(&oid
));
47 case WRITE_TREE_UNREADABLE_INDEX
:
48 die("%s: error reading the index", me
);
50 case WRITE_TREE_UNMERGED_INDEX
:
51 die("%s: error building trees", me
);
53 case WRITE_TREE_PREFIX_ERROR
:
54 die("%s: prefix %s not found", me
, tree_prefix
);