|
9 | 9 | #include "builtin.h"
|
10 | 10 | #include "utf8.h"
|
11 | 11 |
|
12 |
| -static const char commit_tree_usage[] = "git commit-tree <sha1> [(-p <sha1>)...] < changelog"; |
| 12 | +static const char commit_tree_usage[] = "git commit-tree [(-p <sha1>)...] [-m <message>] [-F <file>] <sha1> <changelog"; |
13 | 13 |
|
14 | 14 | static void new_parent(struct commit *parent, struct commit_list **parents_p)
|
15 | 15 | {
|
@@ -51,15 +51,52 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)
|
51 | 51 | continue;
|
52 | 52 | }
|
53 | 53 |
|
| 54 | + if (!strcmp(arg, "-m")) { |
| 55 | + if (argc <= ++i) |
| 56 | + usage(commit_tree_usage); |
| 57 | + if (buffer.len) |
| 58 | + strbuf_addch(&buffer, '\n'); |
| 59 | + strbuf_addstr(&buffer, argv[i]); |
| 60 | + strbuf_complete_line(&buffer); |
| 61 | + continue; |
| 62 | + } |
| 63 | + |
| 64 | + if (!strcmp(arg, "-F")) { |
| 65 | + int fd; |
| 66 | + |
| 67 | + if (argc <= ++i) |
| 68 | + usage(commit_tree_usage); |
| 69 | + if (buffer.len) |
| 70 | + strbuf_addch(&buffer, '\n'); |
| 71 | + if (!strcmp(argv[i], "-")) |
| 72 | + fd = 0; |
| 73 | + else { |
| 74 | + fd = open(argv[i], O_RDONLY); |
| 75 | + if (fd < 0) |
| 76 | + die_errno("git commit-tree: failed to open '%s'", |
| 77 | + argv[i]); |
| 78 | + } |
| 79 | + if (strbuf_read(&buffer, fd, 0) < 0) |
| 80 | + die_errno("git commit-tree: failed to read '%s'", |
| 81 | + argv[i]); |
| 82 | + if (fd && close(fd)) |
| 83 | + die_errno("git commit-tree: failed to close '%s'", |
| 84 | + argv[i]); |
| 85 | + strbuf_complete_line(&buffer); |
| 86 | + continue; |
| 87 | + } |
| 88 | + |
54 | 89 | if (get_sha1(arg, tree_sha1))
|
55 | 90 | die("Not a valid object name %s", arg);
|
56 | 91 | if (got_tree)
|
57 | 92 | die("Cannot give more than one trees");
|
58 | 93 | got_tree = 1;
|
59 | 94 | }
|
60 | 95 |
|
61 |
| - if (strbuf_read(&buffer, 0, 0) < 0) |
62 |
| - die_errno("git commit-tree: failed to read"); |
| 96 | + if (!buffer.len) { |
| 97 | + if (strbuf_read(&buffer, 0, 0) < 0) |
| 98 | + die_errno("git commit-tree: failed to read"); |
| 99 | + } |
63 | 100 |
|
64 | 101 | if (commit_tree(buffer.buf, tree_sha1, parents, commit_sha1, NULL)) {
|
65 | 102 | strbuf_release(&buffer);
|
|
0 commit comments