pack-objects: fix --no-keep-true-parents
[git/debian.git] / builtin / write-tree.c
blob84b83318c967d1401792a99ca85ca433812e6885
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 "cache.h"
9 #include "config.h"
10 #include "environment.h"
11 #include "gettext.h"
12 #include "hex.h"
13 #include "tree.h"
14 #include "cache-tree.h"
15 #include "parse-options.h"
16 #include "repository.h"
18 static const char * const write_tree_usage[] = {
19 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
20 NULL
23 int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
25 int flags = 0, ret;
26 const char *tree_prefix = NULL;
27 struct object_id oid;
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>")),
34 { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
35 N_("only useful for debugging"),
36 PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
37 WRITE_TREE_IGNORE_CACHE_TREE },
38 OPT_END()
41 git_config(git_default_config, NULL);
42 argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
43 write_tree_usage, 0);
45 prepare_repo_settings(the_repository);
46 the_repository->settings.command_requires_full_index = 0;
48 ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
49 tree_prefix);
50 switch (ret) {
51 case 0:
52 printf("%s\n", oid_to_hex(&oid));
53 break;
54 case WRITE_TREE_UNREADABLE_INDEX:
55 die("%s: error reading the index", me);
56 break;
57 case WRITE_TREE_UNMERGED_INDEX:
58 die("%s: error building trees", me);
59 break;
60 case WRITE_TREE_PREFIX_ERROR:
61 die("%s: prefix %s not found", me, tree_prefix);
62 break;
64 return ret;