2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
6 #define USE_THE_REPOSITORY_VARIABLE
9 #include "environment.h"
13 #include "cache-tree.h"
14 #include "parse-options.h"
16 static const char * const write_tree_usage
[] = {
17 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
21 int cmd_write_tree(int argc
,
23 const char *cmd_prefix
,
24 struct repository
*repo UNUSED
)
27 const char *tree_prefix
= NULL
;
29 const char *me
= "git-write-tree";
30 struct option write_tree_options
[] = {
31 OPT_BIT(0, "missing-ok", &flags
, N_("allow missing objects"),
32 WRITE_TREE_MISSING_OK
),
33 OPT_STRING(0, "prefix", &tree_prefix
, N_("<prefix>/"),
34 N_("write tree object for a subdirectory <prefix>")),
37 .long_name
= "ignore-cache-tree",
39 .precision
= sizeof(flags
),
40 .help
= N_("only useful for debugging"),
41 .flags
= PARSE_OPT_HIDDEN
| PARSE_OPT_NOARG
,
42 .defval
= WRITE_TREE_IGNORE_CACHE_TREE
,
47 repo_config(the_repository
, git_default_config
, NULL
);
48 argc
= parse_options(argc
, argv
, cmd_prefix
, write_tree_options
,
51 prepare_repo_settings(the_repository
);
52 the_repository
->settings
.command_requires_full_index
= 0;
54 ret
= write_index_as_tree(&oid
, the_repository
->index
,
55 repo_get_index_file(the_repository
),
59 printf("%s\n", oid_to_hex(&oid
));
61 case WRITE_TREE_UNREADABLE_INDEX
:
62 die("%s: error reading the index", me
);
64 case WRITE_TREE_UNMERGED_INDEX
:
65 die("%s: error building trees", me
);
67 case WRITE_TREE_PREFIX_ERROR
:
68 die("%s: prefix %s not found", me
, tree_prefix
);