9
#include "environment.h"
13
#include "cache-tree.h"
14
#include "parse-options.h"
15
#include "repository.h"
17
static const char * const write_tree_usage[] = {
18
N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
22
int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
25
const char *tree_prefix = NULL;
27
const char *me = "git-write-tree";
28
struct option write_tree_options[] = {
29
OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
30
WRITE_TREE_MISSING_OK),
31
OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
32
N_("write tree object for a subdirectory <prefix>")),
33
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
34
N_("only useful for debugging"),
35
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
36
WRITE_TREE_IGNORE_CACHE_TREE },
40
git_config(git_default_config, NULL);
41
argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
44
prepare_repo_settings(the_repository);
45
the_repository->settings.command_requires_full_index = 0;
47
ret = write_index_as_tree(&oid, the_repository->index, get_index_file(),
51
printf("%s\n", oid_to_hex(&oid));
53
case WRITE_TREE_UNREADABLE_INDEX:
54
die("%s: error reading the index", me);
56
case WRITE_TREE_UNMERGED_INDEX:
57
die("%s: error building trees", me);
59
case WRITE_TREE_PREFIX_ERROR:
60
die("%s: prefix %s not found", me, tree_prefix);