cache.h: remove this no-longer-used header
[alt-git.git] / builtin / write-tree.c
blob66e83d0ecba04c90d1e12a2529cc40210808035c
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #define USE_THE_INDEX_VARIABLE
7 #include "builtin.h"
8 #include "config.h"
9 #include "environment.h"
10 #include "gettext.h"
11 #include "hex.h"
12 #include "tree.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>/]"),
19 NULL
22 int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
24 int flags = 0, ret;
25 const char *tree_prefix = NULL;
26 struct object_id oid;
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 },
37 OPT_END()
40 git_config(git_default_config, NULL);
41 argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
42 write_tree_usage, 0);
44 prepare_repo_settings(the_repository);
45 the_repository->settings.command_requires_full_index = 0;
47 ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
48 tree_prefix);
49 switch (ret) {
50 case 0:
51 printf("%s\n", oid_to_hex(&oid));
52 break;
53 case WRITE_TREE_UNREADABLE_INDEX:
54 die("%s: error reading the index", me);
55 break;
56 case WRITE_TREE_UNMERGED_INDEX:
57 die("%s: error building trees", me);
58 break;
59 case WRITE_TREE_PREFIX_ERROR:
60 die("%s: prefix %s not found", me, tree_prefix);
61 break;
63 return ret;