]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/write-tree.c
The sixth batch
[thirdparty/git.git] / builtin / write-tree.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
03eae9af 6#define USE_THE_REPOSITORY_VARIABLE
8ed05fb5 7#include "builtin.h"
b2141fc1 8#include "config.h"
f394e093 9#include "gettext.h"
41771fa4 10#include "hex.h"
8e440259 11#include "tree.h"
a52139b4 12#include "cache-tree.h"
404d42e5 13#include "parse-options.h"
e83c5163 14
404d42e5 15static const char * const write_tree_usage[] = {
b5625d07 16 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
404d42e5
SB
17 NULL
18};
75a46f6b 19
9b1cb507
JC
20int cmd_write_tree(int argc,
21 const char **argv,
22 const char *cmd_prefix,
23 struct repository *repo UNUSED)
8ed05fb5 24{
d11b8d34 25 int flags = 0, ret;
76a7bc09 26 const char *tree_prefix = NULL;
38b471fa 27 struct object_id oid;
45525bd0 28 const char *me = "git-write-tree";
404d42e5 29 struct option write_tree_options[] = {
b5625d07 30 OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
404d42e5 31 WRITE_TREE_MISSING_OK),
76a7bc09 32 OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
5f0df44c 33 N_("write tree object for a subdirectory <prefix>")),
d012ceb5
PS
34 {
35 .type = OPTION_BIT,
36 .long_name = "ignore-cache-tree",
37 .value = &flags,
38 .help = N_("only useful for debugging"),
39 .flags = PARSE_OPT_HIDDEN | PARSE_OPT_NOARG,
40 .defval = WRITE_TREE_IGNORE_CACHE_TREE,
41 },
404d42e5
SB
42 OPT_END()
43 };
8ed05fb5 44
ef90d6d4 45 git_config(git_default_config, NULL);
76a7bc09 46 argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
404d42e5 47 write_tree_usage, 0);
8ed05fb5 48
1a65b41b
SL
49 prepare_repo_settings(the_repository);
50 the_repository->settings.command_requires_full_index = 0;
51
1dc4ec21
PS
52 ret = write_index_as_tree(&oid, the_repository->index,
53 repo_get_index_file(the_repository),
f59aa5e0 54 flags, tree_prefix);
45525bd0
JH
55 switch (ret) {
56 case 0:
38b471fa 57 printf("%s\n", oid_to_hex(&oid));
45525bd0
JH
58 break;
59 case WRITE_TREE_UNREADABLE_INDEX:
60 die("%s: error reading the index", me);
61 break;
62 case WRITE_TREE_UNMERGED_INDEX:
331fcb59 63 die("%s: error building trees", me);
45525bd0
JH
64 break;
65 case WRITE_TREE_PREFIX_ERROR:
76a7bc09 66 die("%s: prefix %s not found", me, tree_prefix);
45525bd0
JH
67 break;
68 }
8ed05fb5
LS
69 return ret;
70}