]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/write-tree.c
Merge branch 'rj/add-i-leak-fix'
[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 */
99370863 6#define USE_THE_INDEX_VARIABLE
8ed05fb5 7#include "builtin.h"
b2141fc1 8#include "config.h"
32a8f510 9#include "environment.h"
f394e093 10#include "gettext.h"
41771fa4 11#include "hex.h"
8e440259 12#include "tree.h"
a52139b4 13#include "cache-tree.h"
404d42e5 14#include "parse-options.h"
ccd12a3d 15#include "repository.h"
e83c5163 16
404d42e5 17static const char * const write_tree_usage[] = {
b5625d07 18 N_("git write-tree [--missing-ok] [--prefix=<prefix>/]"),
404d42e5
SB
19 NULL
20};
75a46f6b 21
76a7bc09 22int cmd_write_tree(int argc, const char **argv, const char *cmd_prefix)
8ed05fb5 23{
d11b8d34 24 int flags = 0, ret;
76a7bc09 25 const char *tree_prefix = NULL;
38b471fa 26 struct object_id oid;
45525bd0 27 const char *me = "git-write-tree";
404d42e5 28 struct option write_tree_options[] = {
b5625d07 29 OPT_BIT(0, "missing-ok", &flags, N_("allow missing objects"),
404d42e5 30 WRITE_TREE_MISSING_OK),
76a7bc09 31 OPT_STRING(0, "prefix", &tree_prefix, N_("<prefix>/"),
5f0df44c 32 N_("write tree object for a subdirectory <prefix>")),
404d42e5 33 { OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
b5625d07 34 N_("only useful for debugging"),
404d42e5
SB
35 PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
36 WRITE_TREE_IGNORE_CACHE_TREE },
37 OPT_END()
38 };
8ed05fb5 39
ef90d6d4 40 git_config(git_default_config, NULL);
76a7bc09 41 argc = parse_options(argc, argv, cmd_prefix, write_tree_options,
404d42e5 42 write_tree_usage, 0);
8ed05fb5 43
1a65b41b
SL
44 prepare_repo_settings(the_repository);
45 the_repository->settings.command_requires_full_index = 0;
46
99370863
ÆAB
47 ret = write_index_as_tree(&oid, &the_index, get_index_file(), flags,
48 tree_prefix);
45525bd0
JH
49 switch (ret) {
50 case 0:
38b471fa 51 printf("%s\n", oid_to_hex(&oid));
45525bd0
JH
52 break;
53 case WRITE_TREE_UNREADABLE_INDEX:
54 die("%s: error reading the index", me);
55 break;
56 case WRITE_TREE_UNMERGED_INDEX:
331fcb59 57 die("%s: error building trees", me);
45525bd0
JH
58 break;
59 case WRITE_TREE_PREFIX_ERROR:
76a7bc09 60 die("%s: prefix %s not found", me, tree_prefix);
45525bd0
JH
61 break;
62 }
8ed05fb5
LS
63 return ret;
64}