config.c: make git_env_bool() static
[git/mingw/4msysgit.git] / builtin-write-tree.c
blobc2187997447df64948577d8a9a78f4462239b369
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "builtin.h"
7 #include "cache.h"
8 #include "tree.h"
9 #include "cache-tree.h"
11 static const char write_tree_usage[] =
12 "git-write-tree [--missing-ok] [--prefix=<prefix>/]";
14 int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
16 int missing_ok = 0, ret;
17 const char *prefix = NULL;
18 unsigned char sha1[20];
19 const char *me = "git-write-tree";
21 git_config(git_default_config, NULL);
22 while (1 < argc) {
23 const char *arg = argv[1];
24 if (!strcmp(arg, "--missing-ok"))
25 missing_ok = 1;
26 else if (!prefixcmp(arg, "--prefix="))
27 prefix = arg + 9;
28 else
29 usage(write_tree_usage);
30 argc--; argv++;
33 if (argc > 2)
34 die("too many options");
36 ret = write_cache_as_tree(sha1, missing_ok, prefix);
37 switch (ret) {
38 case 0:
39 printf("%s\n", sha1_to_hex(sha1));
40 break;
41 case WRITE_TREE_UNREADABLE_INDEX:
42 die("%s: error reading the index", me);
43 break;
44 case WRITE_TREE_UNMERGED_INDEX:
45 die("%s: error building trees; the index is unmerged?", me);
46 break;
47 case WRITE_TREE_PREFIX_ERROR:
48 die("%s: prefix %s not found", me, prefix);
49 break;
51 return ret;