]> git.ipfire.org Git - thirdparty/git.git/blame_incremental - builtin/write-tree.c
The ninth batch
[thirdparty/git.git] / builtin / write-tree.c
... / ...
CommitLineData
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
6#define USE_THE_REPOSITORY_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
16static const char * const write_tree_usage[] = {
17 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
18 NULL
19};
20
21int cmd_write_tree(int argc,
22 const char **argv,
23 const char *cmd_prefix,
24 struct repository *repo UNUSED)
25{
26 int flags = 0, ret;
27 const char *tree_prefix = NULL;
28 struct object_id oid;
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>")),
35 {
36 .type = OPTION_BIT,
37 .long_name = "ignore-cache-tree",
38 .value = &flags,
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,
43 },
44 OPT_END()
45 };
46
47 repo_config(the_repository, git_default_config, NULL);
48 argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
49 write_tree_usage, 0);
50
51 prepare_repo_settings(the_repository);
52 the_repository->settings.command_requires_full_index = 0;
53
54 ret = write_index_as_tree(&oid, the_repository->index,
55 repo_get_index_file(the_repository),
56 flags, tree_prefix);
57 switch (ret) {
58 case 0:
59 printf("%s\n", oid_to_hex(&oid));
60 break;
61 case WRITE_TREE_UNREADABLE_INDEX:
62 die("%s: error reading the index", me);
63 break;
64 case WRITE_TREE_UNMERGED_INDEX:
65 die("%s: error building trees", me);
66 break;
67 case WRITE_TREE_PREFIX_ERROR:
68 die("%s: prefix %s not found", me, tree_prefix);
69 break;
70 }
71 return ret;
72}