2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_REPOSITORY_VARIABLE
12 #include "cache-tree.h"
13 #include "parse-options.h"
15 static const char * const write_tree_usage
[] = {
16 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
20 int cmd_write_tree(int argc
,
22 const char *cmd_prefix
,
23 struct repository
*repo UNUSED
)
26 const char *tree_prefix
= NULL
;
28 const char *me
= "git-write-tree";
29 struct option write_tree_options
[] = {
30 OPT_BIT(0, "missing-ok", &flags
, N_("allow missing objects"),
31 WRITE_TREE_MISSING_OK
),
32 OPT_STRING(0, "prefix", &tree_prefix
, N_("<prefix>/"),
33 N_("write tree object for a subdirectory <prefix>")),
36 .long_name
= "ignore-cache-tree",
38 .help
= N_("only useful for debugging"),
39 .flags
= PARSE_OPT_HIDDEN
| PARSE_OPT_NOARG
,
40 .defval
= WRITE_TREE_IGNORE_CACHE_TREE
,
45 git_config(git_default_config
, NULL
);
46 argc
= parse_options(argc
, argv
, cmd_prefix
, write_tree_options
,
49 prepare_repo_settings(the_repository
);
50 the_repository
->settings
.command_requires_full_index
= 0;
52 ret
= write_index_as_tree(&oid
, the_repository
->index
,
53 repo_get_index_file(the_repository
),
57 printf("%s\n", oid_to_hex(&oid
));
59 case WRITE_TREE_UNREADABLE_INDEX
:
60 die("%s: error reading the index", me
);
62 case WRITE_TREE_UNMERGED_INDEX
:
63 die("%s: error building trees", me
);
65 case WRITE_TREE_PREFIX_ERROR
:
66 die("%s: prefix %s not found", me
, tree_prefix
);