]>
Commit | Line | Data |
---|---|---|
f5bbc322 KH |
1 | /* |
2 | * Builtin "git commit" | |
3 | * | |
4 | * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com> | |
5 | * Based on git-commit.sh by Junio C Hamano and Linus Torvalds | |
6 | */ | |
7 | ||
8 | #include "cache.h" | |
9 | #include "cache-tree.h" | |
6b2f2d98 | 10 | #include "color.h" |
2888605c | 11 | #include "dir.h" |
f5bbc322 KH |
12 | #include "builtin.h" |
13 | #include "diff.h" | |
14 | #include "diffcore.h" | |
15 | #include "commit.h" | |
16 | #include "revision.h" | |
17 | #include "wt-status.h" | |
18 | #include "run-command.h" | |
19 | #include "refs.h" | |
20 | #include "log-tree.h" | |
21 | #include "strbuf.h" | |
22 | #include "utf8.h" | |
23 | #include "parse-options.h" | |
2888605c | 24 | #include "path-list.h" |
fa9dcf80 | 25 | #include "unpack-trees.h" |
f5bbc322 KH |
26 | |
27 | static const char * const builtin_commit_usage[] = { | |
28 | "git-commit [options] [--] <filepattern>...", | |
29 | NULL | |
30 | }; | |
31 | ||
2f02b25f SB |
32 | static const char * const builtin_status_usage[] = { |
33 | "git-status [options] [--] <filepattern>...", | |
34 | NULL | |
35 | }; | |
36 | ||
f5bbc322 KH |
37 | static unsigned char head_sha1[20], merge_head_sha1[20]; |
38 | static char *use_message_buffer; | |
39 | static const char commit_editmsg[] = "COMMIT_EDITMSG"; | |
2888605c JH |
40 | static struct lock_file index_lock; /* real index */ |
41 | static struct lock_file false_lock; /* used only for partial commits */ | |
42 | static enum { | |
43 | COMMIT_AS_IS = 1, | |
44 | COMMIT_NORMAL, | |
45 | COMMIT_PARTIAL, | |
46 | } commit_style; | |
f5bbc322 | 47 | |
f9568530 | 48 | static char *logfile, *force_author, *template_file; |
f5bbc322 | 49 | static char *edit_message, *use_message; |
e83dbe80 | 50 | static char *author_name, *author_email, *author_date; |
f5bbc322 | 51 | static int all, edit_flag, also, interactive, only, amend, signoff; |
5241b6bf | 52 | static int quiet, verbose, untracked_files, no_verify, allow_empty; |
5f065737 AR |
53 | /* |
54 | * The default commit message cleanup mode will remove the lines | |
55 | * beginning with # (shell comments) and leading and trailing | |
56 | * whitespaces (empty lines or containing only whitespaces) | |
57 | * if editor is used, and only the whitespaces if the message | |
58 | * is specified explicitly. | |
59 | */ | |
60 | static enum { | |
61 | CLEANUP_SPACE, | |
62 | CLEANUP_NONE, | |
63 | CLEANUP_ALL, | |
64 | } cleanup_mode; | |
65 | static char *cleanup_arg; | |
f5bbc322 | 66 | |
4803466f | 67 | static int use_editor = 1, initial_commit, in_merge; |
f5bbc322 | 68 | const char *only_include_assumed; |
f9568530 JS |
69 | struct strbuf message; |
70 | ||
71 | static int opt_parse_m(const struct option *opt, const char *arg, int unset) | |
72 | { | |
73 | struct strbuf *buf = opt->value; | |
74 | if (unset) | |
75 | strbuf_setlen(buf, 0); | |
76 | else { | |
77 | strbuf_addstr(buf, arg); | |
78 | strbuf_addch(buf, '\n'); | |
79 | strbuf_addch(buf, '\n'); | |
80 | } | |
81 | return 0; | |
82 | } | |
f5bbc322 KH |
83 | |
84 | static struct option builtin_commit_options[] = { | |
85 | OPT__QUIET(&quiet), | |
86 | OPT__VERBOSE(&verbose), | |
87 | OPT_GROUP("Commit message options"), | |
88 | ||
89 | OPT_STRING('F', "file", &logfile, "FILE", "read log from file"), | |
90 | OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"), | |
f9568530 | 91 | OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m), |
f5bbc322 KH |
92 | OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit "), |
93 | OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"), | |
362b0dd5 | 94 | OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"), |
f5bbc322 KH |
95 | OPT_STRING('t', "template", &template_file, "FILE", "use specified template file"), |
96 | OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"), | |
97 | ||
98 | OPT_GROUP("Commit contents options"), | |
99 | OPT_BOOLEAN('a', "all", &all, "commit all changed files"), | |
100 | OPT_BOOLEAN('i', "include", &also, "add specified files to index for commit"), | |
101 | OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"), | |
d4ba07ca | 102 | OPT_BOOLEAN('o', "only", &only, "commit only specified files"), |
f5bbc322 KH |
103 | OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"), |
104 | OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"), | |
e1645901 | 105 | OPT_BOOLEAN('u', "untracked-files", &untracked_files, "show all untracked files"), |
5241b6bf | 106 | OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"), |
5f065737 | 107 | OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"), |
f5bbc322 KH |
108 | |
109 | OPT_END() | |
110 | }; | |
111 | ||
2888605c JH |
112 | static void rollback_index_files(void) |
113 | { | |
114 | switch (commit_style) { | |
115 | case COMMIT_AS_IS: | |
116 | break; /* nothing to do */ | |
117 | case COMMIT_NORMAL: | |
118 | rollback_lock_file(&index_lock); | |
119 | break; | |
120 | case COMMIT_PARTIAL: | |
121 | rollback_lock_file(&index_lock); | |
122 | rollback_lock_file(&false_lock); | |
123 | break; | |
124 | } | |
125 | } | |
126 | ||
5a9dd399 | 127 | static int commit_index_files(void) |
2888605c | 128 | { |
5a9dd399 BC |
129 | int err = 0; |
130 | ||
2888605c JH |
131 | switch (commit_style) { |
132 | case COMMIT_AS_IS: | |
133 | break; /* nothing to do */ | |
134 | case COMMIT_NORMAL: | |
5a9dd399 | 135 | err = commit_lock_file(&index_lock); |
2888605c JH |
136 | break; |
137 | case COMMIT_PARTIAL: | |
5a9dd399 | 138 | err = commit_lock_file(&index_lock); |
2888605c JH |
139 | rollback_lock_file(&false_lock); |
140 | break; | |
141 | } | |
5a9dd399 BC |
142 | |
143 | return err; | |
2888605c JH |
144 | } |
145 | ||
146 | /* | |
147 | * Take a union of paths in the index and the named tree (typically, "HEAD"), | |
148 | * and return the paths that match the given pattern in list. | |
149 | */ | |
150 | static int list_paths(struct path_list *list, const char *with_tree, | |
151 | const char *prefix, const char **pattern) | |
152 | { | |
153 | int i; | |
154 | char *m; | |
155 | ||
156 | for (i = 0; pattern[i]; i++) | |
157 | ; | |
158 | m = xcalloc(1, i); | |
159 | ||
160 | if (with_tree) | |
161 | overlay_tree_on_cache(with_tree, prefix); | |
162 | ||
163 | for (i = 0; i < active_nr; i++) { | |
164 | struct cache_entry *ce = active_cache[i]; | |
7a51ed66 | 165 | if (ce->ce_flags & CE_UPDATE) |
e87e22d0 | 166 | continue; |
2888605c JH |
167 | if (!pathspec_match(pattern, m, ce->name, 0)) |
168 | continue; | |
169 | path_list_insert(ce->name, list); | |
170 | } | |
171 | ||
172 | return report_path_error(m, pattern, prefix ? strlen(prefix) : 0); | |
173 | } | |
174 | ||
175 | static void add_remove_files(struct path_list *list) | |
176 | { | |
177 | int i; | |
178 | for (i = 0; i < list->nr; i++) { | |
d177cab0 | 179 | struct stat st; |
2888605c | 180 | struct path_list_item *p = &(list->items[i]); |
d177cab0 | 181 | |
960b8ad1 AR |
182 | if (!lstat(p->path, &st)) { |
183 | if (add_to_cache(p->path, &st, 0)) | |
184 | die("updating files failed"); | |
185 | } else | |
2888605c JH |
186 | remove_file_from_cache(p->path); |
187 | } | |
188 | } | |
189 | ||
fa9dcf80 LT |
190 | static void create_base_index(void) |
191 | { | |
192 | struct tree *tree; | |
193 | struct unpack_trees_options opts; | |
194 | struct tree_desc t; | |
195 | ||
196 | if (initial_commit) { | |
197 | discard_cache(); | |
198 | return; | |
199 | } | |
200 | ||
201 | memset(&opts, 0, sizeof(opts)); | |
202 | opts.head_idx = 1; | |
203 | opts.index_only = 1; | |
204 | opts.merge = 1; | |
34110cd4 LT |
205 | opts.src_index = &the_index; |
206 | opts.dst_index = &the_index; | |
fa9dcf80 LT |
207 | |
208 | opts.fn = oneway_merge; | |
209 | tree = parse_tree_indirect(head_sha1); | |
210 | if (!tree) | |
211 | die("failed to unpack HEAD tree object"); | |
212 | parse_tree(tree); | |
213 | init_tree_desc(&t, tree->buffer, tree->size); | |
203a2fe1 DB |
214 | if (unpack_trees(1, &t, &opts)) |
215 | exit(128); /* We've already reported the error, finish dying */ | |
fa9dcf80 LT |
216 | } |
217 | ||
f64fe7b4 | 218 | static char *prepare_index(int argc, const char **argv, const char *prefix) |
f5bbc322 KH |
219 | { |
220 | int fd; | |
2888605c JH |
221 | struct path_list partial; |
222 | const char **pathspec = NULL; | |
f5bbc322 KH |
223 | |
224 | if (interactive) { | |
3f061887 | 225 | interactive_add(argc, argv, prefix); |
d5350fd2 GP |
226 | if (read_cache() < 0) |
227 | die("index file corrupt"); | |
2888605c | 228 | commit_style = COMMIT_AS_IS; |
f5bbc322 KH |
229 | return get_index_file(); |
230 | } | |
231 | ||
f5bbc322 KH |
232 | if (read_cache() < 0) |
233 | die("index file corrupt"); | |
234 | ||
f64fe7b4 JH |
235 | if (*argv) |
236 | pathspec = get_pathspec(prefix, argv); | |
2888605c JH |
237 | |
238 | /* | |
239 | * Non partial, non as-is commit. | |
240 | * | |
241 | * (1) get the real index; | |
242 | * (2) update the_index as necessary; | |
243 | * (3) write the_index out to the real index (still locked); | |
244 | * (4) return the name of the locked index file. | |
245 | * | |
246 | * The caller should run hooks on the locked real index, and | |
247 | * (A) if all goes well, commit the real index; | |
248 | * (B) on failure, rollback the real index. | |
249 | */ | |
250 | if (all || (also && pathspec && *pathspec)) { | |
251 | int fd = hold_locked_index(&index_lock, 1); | |
7ae02a30 | 252 | add_files_to_cache(also ? prefix : NULL, pathspec, 0); |
d37d3203 | 253 | refresh_cache(REFRESH_QUIET); |
4ed7cd3a BC |
254 | if (write_cache(fd, active_cache, active_nr) || |
255 | close_lock_file(&index_lock)) | |
f5bbc322 | 256 | die("unable to write new_index file"); |
2888605c JH |
257 | commit_style = COMMIT_NORMAL; |
258 | return index_lock.filename; | |
f5bbc322 KH |
259 | } |
260 | ||
2888605c JH |
261 | /* |
262 | * As-is commit. | |
263 | * | |
264 | * (1) return the name of the real index file. | |
265 | * | |
266 | * The caller should run hooks on the real index, and run | |
267 | * hooks on the real index, and create commit from the_index. | |
268 | * We still need to refresh the index here. | |
269 | */ | |
270 | if (!pathspec || !*pathspec) { | |
271 | fd = hold_locked_index(&index_lock, 1); | |
272 | refresh_cache(REFRESH_QUIET); | |
273 | if (write_cache(fd, active_cache, active_nr) || | |
4439751d | 274 | commit_locked_index(&index_lock)) |
2888605c JH |
275 | die("unable to write new_index file"); |
276 | commit_style = COMMIT_AS_IS; | |
f5bbc322 KH |
277 | return get_index_file(); |
278 | } | |
279 | ||
2888605c JH |
280 | /* |
281 | * A partial commit. | |
282 | * | |
283 | * (0) find the set of affected paths; | |
284 | * (1) get lock on the real index file; | |
285 | * (2) update the_index with the given paths; | |
286 | * (3) write the_index out to the real index (still locked); | |
287 | * (4) get lock on the false index file; | |
288 | * (5) reset the_index from HEAD; | |
289 | * (6) update the_index the same way as (2); | |
290 | * (7) write the_index out to the false index file; | |
291 | * (8) return the name of the false index file (still locked); | |
292 | * | |
293 | * The caller should run hooks on the locked false index, and | |
294 | * create commit from it. Then | |
295 | * (A) if all goes well, commit the real index; | |
296 | * (B) on failure, rollback the real index; | |
297 | * In either case, rollback the false index. | |
298 | */ | |
299 | commit_style = COMMIT_PARTIAL; | |
300 | ||
301 | if (file_exists(git_path("MERGE_HEAD"))) | |
302 | die("cannot do a partial commit during a merge."); | |
303 | ||
304 | memset(&partial, 0, sizeof(partial)); | |
305 | partial.strdup_paths = 1; | |
306 | if (list_paths(&partial, initial_commit ? NULL : "HEAD", prefix, pathspec)) | |
307 | exit(1); | |
308 | ||
309 | discard_cache(); | |
310 | if (read_cache() < 0) | |
311 | die("cannot read the index"); | |
312 | ||
313 | fd = hold_locked_index(&index_lock, 1); | |
314 | add_remove_files(&partial); | |
ef12b50d | 315 | refresh_cache(REFRESH_QUIET); |
4ed7cd3a BC |
316 | if (write_cache(fd, active_cache, active_nr) || |
317 | close_lock_file(&index_lock)) | |
f5bbc322 KH |
318 | die("unable to write new_index file"); |
319 | ||
2888605c JH |
320 | fd = hold_lock_file_for_update(&false_lock, |
321 | git_path("next-index-%d", getpid()), 1); | |
fa9dcf80 LT |
322 | |
323 | create_base_index(); | |
2888605c | 324 | add_remove_files(&partial); |
d37d3203 | 325 | refresh_cache(REFRESH_QUIET); |
f5bbc322 | 326 | |
4ed7cd3a BC |
327 | if (write_cache(fd, active_cache, active_nr) || |
328 | close_lock_file(&false_lock)) | |
2888605c | 329 | die("unable to write temporary index file"); |
959ba670 JK |
330 | |
331 | discard_cache(); | |
332 | read_cache_from(false_lock.filename); | |
333 | ||
2888605c | 334 | return false_lock.filename; |
f5bbc322 KH |
335 | } |
336 | ||
37d07f8f | 337 | static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn) |
f5bbc322 KH |
338 | { |
339 | struct wt_status s; | |
340 | ||
341 | wt_status_prepare(&s); | |
46f721c8 JK |
342 | if (wt_status_relative_paths) |
343 | s.prefix = prefix; | |
f5bbc322 KH |
344 | |
345 | if (amend) { | |
346 | s.amend = 1; | |
347 | s.reference = "HEAD^1"; | |
348 | } | |
349 | s.verbose = verbose; | |
350 | s.untracked = untracked_files; | |
351 | s.index_file = index_file; | |
352 | s.fp = fp; | |
37d07f8f | 353 | s.nowarn = nowarn; |
f5bbc322 KH |
354 | |
355 | wt_status_print(&s); | |
356 | ||
357 | return s.commitable; | |
358 | } | |
359 | ||
3473f303 PB |
360 | static int run_hook(const char *index_file, const char *name, ...) |
361 | { | |
362 | struct child_process hook; | |
363 | const char *argv[10], *env[2]; | |
364 | char index[PATH_MAX]; | |
365 | va_list args; | |
366 | int i; | |
367 | ||
368 | va_start(args, name); | |
369 | argv[0] = git_path("hooks/%s", name); | |
370 | i = 0; | |
371 | do { | |
372 | if (++i >= ARRAY_SIZE(argv)) | |
373 | die ("run_hook(): too many arguments"); | |
374 | argv[i] = va_arg(args, const char *); | |
375 | } while (argv[i]); | |
376 | va_end(args); | |
377 | ||
378 | snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); | |
379 | env[0] = index; | |
380 | env[1] = NULL; | |
381 | ||
382 | if (access(argv[0], X_OK) < 0) | |
383 | return 0; | |
384 | ||
385 | memset(&hook, 0, sizeof(hook)); | |
386 | hook.argv = argv; | |
387 | hook.no_stdin = 1; | |
388 | hook.stdout_to_stderr = 1; | |
389 | hook.env = env; | |
390 | ||
391 | return run_command(&hook); | |
392 | } | |
393 | ||
ec84bd00 PB |
394 | static int is_a_merge(const unsigned char *sha1) |
395 | { | |
396 | struct commit *commit = lookup_commit(sha1); | |
397 | if (!commit || parse_commit(commit)) | |
398 | die("could not parse HEAD commit"); | |
399 | return !!(commit->parents && commit->parents->next); | |
400 | } | |
401 | ||
f5bbc322 KH |
402 | static const char sign_off_header[] = "Signed-off-by: "; |
403 | ||
e83dbe80 | 404 | static void determine_author_info(void) |
a45d46ba SB |
405 | { |
406 | char *name, *email, *date; | |
407 | ||
408 | name = getenv("GIT_AUTHOR_NAME"); | |
409 | email = getenv("GIT_AUTHOR_EMAIL"); | |
410 | date = getenv("GIT_AUTHOR_DATE"); | |
411 | ||
412 | if (use_message) { | |
413 | const char *a, *lb, *rb, *eol; | |
414 | ||
415 | a = strstr(use_message_buffer, "\nauthor "); | |
416 | if (!a) | |
417 | die("invalid commit: %s", use_message); | |
418 | ||
419 | lb = strstr(a + 8, " <"); | |
420 | rb = strstr(a + 8, "> "); | |
421 | eol = strchr(a + 8, '\n'); | |
422 | if (!lb || !rb || !eol) | |
423 | die("invalid commit: %s", use_message); | |
424 | ||
425 | name = xstrndup(a + 8, lb - (a + 8)); | |
426 | email = xstrndup(lb + 2, rb - (lb + 2)); | |
427 | date = xstrndup(rb + 2, eol - (rb + 2)); | |
428 | } | |
429 | ||
430 | if (force_author) { | |
431 | const char *lb = strstr(force_author, " <"); | |
432 | const char *rb = strchr(force_author, '>'); | |
433 | ||
434 | if (!lb || !rb) | |
435 | die("malformed --author parameter"); | |
436 | name = xstrndup(force_author, lb - force_author); | |
437 | email = xstrndup(lb + 2, rb - (lb + 2)); | |
438 | } | |
439 | ||
e83dbe80 SB |
440 | author_name = name; |
441 | author_email = email; | |
442 | author_date = date; | |
a45d46ba SB |
443 | } |
444 | ||
ec84bd00 | 445 | static int prepare_to_commit(const char *index_file, const char *prefix) |
f5bbc322 KH |
446 | { |
447 | struct stat statbuf; | |
bc5d248a | 448 | int commitable, saved_color_setting; |
f5bbc322 KH |
449 | struct strbuf sb; |
450 | char *buffer; | |
451 | FILE *fp; | |
8089c85b PB |
452 | const char *hook_arg1 = NULL; |
453 | const char *hook_arg2 = NULL; | |
bb1ae3f6 | 454 | int ident_shown = 0; |
f5bbc322 | 455 | |
ec84bd00 PB |
456 | if (!no_verify && run_hook(index_file, "pre-commit", NULL)) |
457 | return 0; | |
f5bbc322 KH |
458 | |
459 | strbuf_init(&sb, 0); | |
f9568530 JS |
460 | if (message.len) { |
461 | strbuf_addbuf(&sb, &message); | |
8089c85b | 462 | hook_arg1 = "message"; |
f5bbc322 KH |
463 | } else if (logfile && !strcmp(logfile, "-")) { |
464 | if (isatty(0)) | |
465 | fprintf(stderr, "(reading log message from standard input)\n"); | |
466 | if (strbuf_read(&sb, 0, 0) < 0) | |
467 | die("could not read log from standard input"); | |
8089c85b | 468 | hook_arg1 = "message"; |
f5bbc322 KH |
469 | } else if (logfile) { |
470 | if (strbuf_read_file(&sb, logfile, 0) < 0) | |
471 | die("could not read log file '%s': %s", | |
472 | logfile, strerror(errno)); | |
8089c85b | 473 | hook_arg1 = "message"; |
f5bbc322 KH |
474 | } else if (use_message) { |
475 | buffer = strstr(use_message_buffer, "\n\n"); | |
476 | if (!buffer || buffer[2] == '\0') | |
477 | die("commit has empty message"); | |
478 | strbuf_add(&sb, buffer + 2, strlen(buffer + 2)); | |
8089c85b PB |
479 | hook_arg1 = "commit"; |
480 | hook_arg2 = use_message; | |
f5bbc322 KH |
481 | } else if (!stat(git_path("MERGE_MSG"), &statbuf)) { |
482 | if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0) | |
483 | die("could not read MERGE_MSG: %s", strerror(errno)); | |
8089c85b | 484 | hook_arg1 = "merge"; |
f5bbc322 KH |
485 | } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) { |
486 | if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0) | |
487 | die("could not read SQUASH_MSG: %s", strerror(errno)); | |
8089c85b | 488 | hook_arg1 = "squash"; |
f5bbc322 KH |
489 | } else if (template_file && !stat(template_file, &statbuf)) { |
490 | if (strbuf_read_file(&sb, template_file, 0) < 0) | |
491 | die("could not read %s: %s", | |
492 | template_file, strerror(errno)); | |
8089c85b | 493 | hook_arg1 = "template"; |
f5bbc322 KH |
494 | } |
495 | ||
8089c85b PB |
496 | /* |
497 | * This final case does not modify the template message, | |
498 | * it just sets the argument to the prepare-commit-msg hook. | |
499 | */ | |
500 | else if (in_merge) | |
501 | hook_arg1 = "merge"; | |
502 | ||
f5bbc322 KH |
503 | fp = fopen(git_path(commit_editmsg), "w"); |
504 | if (fp == NULL) | |
b5b644a9 | 505 | die("could not open %s", git_path(commit_editmsg)); |
f5bbc322 | 506 | |
5f065737 AR |
507 | if (cleanup_mode != CLEANUP_NONE) |
508 | stripspace(&sb, 0); | |
f5bbc322 KH |
509 | |
510 | if (signoff) { | |
13208572 JS |
511 | struct strbuf sob; |
512 | int i; | |
513 | ||
514 | strbuf_init(&sob, 0); | |
515 | strbuf_addstr(&sob, sign_off_header); | |
d9ccfe77 JH |
516 | strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"), |
517 | getenv("GIT_COMMITTER_EMAIL"))); | |
13208572 | 518 | strbuf_addch(&sob, '\n'); |
13208572 JS |
519 | for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--) |
520 | ; /* do nothing */ | |
2150554b JS |
521 | if (prefixcmp(sb.buf + i, sob.buf)) { |
522 | if (prefixcmp(sb.buf + i, sign_off_header)) | |
523 | strbuf_addch(&sb, '\n'); | |
13208572 | 524 | strbuf_addbuf(&sb, &sob); |
2150554b | 525 | } |
13208572 | 526 | strbuf_release(&sob); |
f5bbc322 KH |
527 | } |
528 | ||
13208572 | 529 | if (fwrite(sb.buf, 1, sb.len, fp) < sb.len) |
b5b644a9 | 530 | die("could not write commit template: %s", strerror(errno)); |
13208572 | 531 | |
f5bbc322 KH |
532 | strbuf_release(&sb); |
533 | ||
e83dbe80 SB |
534 | determine_author_info(); |
535 | ||
bb1ae3f6 SB |
536 | /* This checks if committer ident is explicitly given */ |
537 | git_committer_info(0); | |
ec84bd00 | 538 | if (use_editor) { |
e83dbe80 SB |
539 | char *author_ident; |
540 | const char *committer_ident; | |
541 | ||
ec84bd00 PB |
542 | if (in_merge) |
543 | fprintf(fp, | |
544 | "#\n" | |
545 | "# It looks like you may be committing a MERGE.\n" | |
546 | "# If this is not correct, please remove the file\n" | |
547 | "# %s\n" | |
548 | "# and try again.\n" | |
549 | "#\n", | |
550 | git_path("MERGE_HEAD")); | |
551 | ||
552 | fprintf(fp, | |
553 | "\n" | |
554 | "# Please enter the commit message for your changes.\n" | |
555 | "# (Comment lines starting with '#' will "); | |
556 | if (cleanup_mode == CLEANUP_ALL) | |
557 | fprintf(fp, "not be included)\n"); | |
558 | else /* CLEANUP_SPACE, that is. */ | |
559 | fprintf(fp, "be kept.\n" | |
560 | "# You can remove them yourself if you want to)\n"); | |
561 | if (only_include_assumed) | |
562 | fprintf(fp, "# %s\n", only_include_assumed); | |
563 | ||
e83dbe80 SB |
564 | author_ident = xstrdup(fmt_name(author_name, author_email)); |
565 | committer_ident = fmt_name(getenv("GIT_COMMITTER_NAME"), | |
566 | getenv("GIT_COMMITTER_EMAIL")); | |
567 | if (strcmp(author_ident, committer_ident)) | |
568 | fprintf(fp, | |
bb1ae3f6 SB |
569 | "%s" |
570 | "# Author: %s\n", | |
571 | ident_shown++ ? "" : "#\n", | |
e83dbe80 SB |
572 | author_ident); |
573 | free(author_ident); | |
574 | ||
bb1ae3f6 SB |
575 | if (!user_ident_explicitly_given) |
576 | fprintf(fp, | |
577 | "%s" | |
578 | "# Committer: %s\n", | |
579 | ident_shown++ ? "" : "#\n", | |
580 | committer_ident); | |
581 | ||
582 | if (ident_shown) | |
583 | fprintf(fp, "#\n"); | |
584 | ||
ec84bd00 PB |
585 | saved_color_setting = wt_status_use_color; |
586 | wt_status_use_color = 0; | |
587 | commitable = run_status(fp, index_file, prefix, 1); | |
588 | wt_status_use_color = saved_color_setting; | |
589 | } else { | |
7168624c | 590 | struct rev_info rev; |
d616a239 | 591 | unsigned char sha1[20]; |
fbcf1184 | 592 | const char *parent = "HEAD"; |
7168624c | 593 | |
7168624c AR |
594 | if (!active_nr && read_cache() < 0) |
595 | die("Cannot read index"); | |
596 | ||
fbcf1184 JH |
597 | if (amend) |
598 | parent = "HEAD^1"; | |
599 | ||
d616a239 | 600 | if (get_sha1(parent, sha1)) |
ec84bd00 PB |
601 | commitable = !!active_nr; |
602 | else { | |
603 | init_revisions(&rev, ""); | |
604 | rev.abbrev = 0; | |
605 | setup_revisions(0, NULL, &rev, parent); | |
606 | DIFF_OPT_SET(&rev.diffopt, QUIET); | |
607 | DIFF_OPT_SET(&rev.diffopt, EXIT_WITH_STATUS); | |
608 | run_diff_index(&rev, 1 /* cached */); | |
609 | ||
610 | commitable = !!DIFF_OPT_TST(&rev.diffopt, HAS_CHANGES); | |
611 | } | |
612 | } | |
d616a239 | 613 | |
ec84bd00 | 614 | fclose(fp); |
7168624c | 615 | |
ec84bd00 PB |
616 | if (!commitable && !in_merge && !allow_empty && |
617 | !(amend && is_a_merge(head_sha1))) { | |
618 | run_status(stdout, index_file, prefix, 0); | |
619 | unlink(commit_editmsg); | |
620 | return 0; | |
7168624c AR |
621 | } |
622 | ||
ec84bd00 PB |
623 | /* |
624 | * Re-read the index as pre-commit hook could have updated it, | |
625 | * and write it out as a tree. We must do this before we invoke | |
626 | * the editor and after we invoke run_status above. | |
627 | */ | |
628 | discard_cache(); | |
629 | read_cache_from(index_file); | |
630 | if (!active_cache_tree) | |
631 | active_cache_tree = cache_tree(); | |
632 | if (cache_tree_update(active_cache_tree, | |
633 | active_cache, active_nr, 0, 0) < 0) { | |
634 | error("Error building trees"); | |
635 | return 0; | |
7168624c | 636 | } |
f5bbc322 | 637 | |
8089c85b PB |
638 | if (run_hook(index_file, "prepare-commit-msg", |
639 | git_path(commit_editmsg), hook_arg1, hook_arg2, NULL)) | |
640 | return 0; | |
f5bbc322 | 641 | |
ec84bd00 PB |
642 | if (use_editor) { |
643 | char index[PATH_MAX]; | |
644 | const char *env[2] = { index, NULL }; | |
645 | snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file); | |
646 | launch_editor(git_path(commit_editmsg), NULL, env); | |
647 | } | |
f5bbc322 | 648 | |
ec84bd00 PB |
649 | if (!no_verify && |
650 | run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) { | |
651 | return 0; | |
652 | } | |
f5bbc322 | 653 | |
ec84bd00 | 654 | return 1; |
f5bbc322 KH |
655 | } |
656 | ||
657 | /* | |
658 | * Find out if the message starting at position 'start' in the strbuf | |
659 | * contains only whitespace and Signed-off-by lines. | |
660 | */ | |
661 | static int message_is_empty(struct strbuf *sb, int start) | |
662 | { | |
663 | struct strbuf tmpl; | |
664 | const char *nl; | |
665 | int eol, i; | |
666 | ||
5f065737 AR |
667 | if (cleanup_mode == CLEANUP_NONE && sb->len) |
668 | return 0; | |
669 | ||
f5bbc322 KH |
670 | /* See if the template is just a prefix of the message. */ |
671 | strbuf_init(&tmpl, 0); | |
672 | if (template_file && strbuf_read_file(&tmpl, template_file, 0) > 0) { | |
5f065737 | 673 | stripspace(&tmpl, cleanup_mode == CLEANUP_ALL); |
f5bbc322 KH |
674 | if (start + tmpl.len <= sb->len && |
675 | memcmp(tmpl.buf, sb->buf + start, tmpl.len) == 0) | |
676 | start += tmpl.len; | |
677 | } | |
678 | strbuf_release(&tmpl); | |
679 | ||
680 | /* Check if the rest is just whitespace and Signed-of-by's. */ | |
681 | for (i = start; i < sb->len; i++) { | |
682 | nl = memchr(sb->buf + i, '\n', sb->len - i); | |
683 | if (nl) | |
684 | eol = nl - sb->buf; | |
685 | else | |
686 | eol = sb->len; | |
687 | ||
688 | if (strlen(sign_off_header) <= eol - i && | |
689 | !prefixcmp(sb->buf + i, sign_off_header)) { | |
690 | i = eol; | |
691 | continue; | |
692 | } | |
693 | while (i < eol) | |
694 | if (!isspace(sb->buf[i++])) | |
695 | return 0; | |
696 | } | |
697 | ||
698 | return 1; | |
699 | } | |
700 | ||
2f02b25f SB |
701 | static int parse_and_validate_options(int argc, const char *argv[], |
702 | const char * const usage[]) | |
f5bbc322 KH |
703 | { |
704 | int f = 0; | |
705 | ||
2f02b25f | 706 | argc = parse_options(argc, argv, builtin_commit_options, usage, 0); |
f5bbc322 | 707 | |
f9568530 | 708 | if (logfile || message.len || use_message) |
4803466f | 709 | use_editor = 0; |
f5bbc322 | 710 | if (edit_flag) |
4803466f | 711 | use_editor = 1; |
406400ce PB |
712 | if (!use_editor) |
713 | setenv("GIT_EDITOR", ":", 1); | |
f5bbc322 KH |
714 | |
715 | if (get_sha1("HEAD", head_sha1)) | |
716 | initial_commit = 1; | |
717 | ||
718 | if (!get_sha1("MERGE_HEAD", merge_head_sha1)) | |
719 | in_merge = 1; | |
720 | ||
721 | /* Sanity check options */ | |
722 | if (amend && initial_commit) | |
723 | die("You have nothing to amend."); | |
724 | if (amend && in_merge) | |
b5b644a9 | 725 | die("You are in the middle of a merge -- cannot amend."); |
f5bbc322 KH |
726 | |
727 | if (use_message) | |
728 | f++; | |
729 | if (edit_message) | |
730 | f++; | |
731 | if (logfile) | |
732 | f++; | |
733 | if (f > 1) | |
734 | die("Only one of -c/-C/-F can be used."); | |
f9568530 | 735 | if (message.len && f > 0) |
f5bbc322 KH |
736 | die("Option -m cannot be combined with -c/-C/-F."); |
737 | if (edit_message) | |
738 | use_message = edit_message; | |
1eb1e9ee | 739 | if (amend && !use_message) |
f5bbc322 KH |
740 | use_message = "HEAD"; |
741 | if (use_message) { | |
742 | unsigned char sha1[20]; | |
743 | static char utf8[] = "UTF-8"; | |
744 | const char *out_enc; | |
745 | char *enc, *end; | |
746 | struct commit *commit; | |
747 | ||
748 | if (get_sha1(use_message, sha1)) | |
749 | die("could not lookup commit %s", use_message); | |
8a2f8733 | 750 | commit = lookup_commit_reference(sha1); |
f5bbc322 KH |
751 | if (!commit || parse_commit(commit)) |
752 | die("could not parse commit %s", use_message); | |
753 | ||
754 | enc = strstr(commit->buffer, "\nencoding"); | |
755 | if (enc) { | |
756 | end = strchr(enc + 10, '\n'); | |
757 | enc = xstrndup(enc + 10, end - (enc + 10)); | |
758 | } else { | |
759 | enc = utf8; | |
760 | } | |
761 | out_enc = git_commit_encoding ? git_commit_encoding : utf8; | |
762 | ||
763 | if (strcmp(out_enc, enc)) | |
764 | use_message_buffer = | |
765 | reencode_string(commit->buffer, out_enc, enc); | |
766 | ||
767 | /* | |
768 | * If we failed to reencode the buffer, just copy it | |
769 | * byte for byte so the user can try to fix it up. | |
770 | * This also handles the case where input and output | |
771 | * encodings are identical. | |
772 | */ | |
773 | if (use_message_buffer == NULL) | |
774 | use_message_buffer = xstrdup(commit->buffer); | |
775 | if (enc != utf8) | |
776 | free(enc); | |
777 | } | |
778 | ||
779 | if (!!also + !!only + !!all + !!interactive > 1) | |
780 | die("Only one of --include/--only/--all/--interactive can be used."); | |
781 | if (argc == 0 && (also || (only && !amend))) | |
782 | die("No paths with --include/--only does not make sense."); | |
783 | if (argc == 0 && only && amend) | |
784 | only_include_assumed = "Clever... amending the last one with dirty index."; | |
3c5283f8 | 785 | if (argc > 0 && !also && !only) |
f5bbc322 | 786 | only_include_assumed = "Explicit paths specified without -i nor -o; assuming --only paths..."; |
5f065737 AR |
787 | if (!cleanup_arg || !strcmp(cleanup_arg, "default")) |
788 | cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE; | |
789 | else if (!strcmp(cleanup_arg, "verbatim")) | |
790 | cleanup_mode = CLEANUP_NONE; | |
791 | else if (!strcmp(cleanup_arg, "whitespace")) | |
792 | cleanup_mode = CLEANUP_SPACE; | |
793 | else if (!strcmp(cleanup_arg, "strip")) | |
794 | cleanup_mode = CLEANUP_ALL; | |
795 | else | |
796 | die("Invalid cleanup mode %s", cleanup_arg); | |
f5bbc322 KH |
797 | |
798 | if (all && argc > 0) | |
799 | die("Paths with -a does not make sense."); | |
800 | else if (interactive && argc > 0) | |
801 | die("Paths with --interactive does not make sense."); | |
802 | ||
803 | return argc; | |
804 | } | |
805 | ||
806 | int cmd_status(int argc, const char **argv, const char *prefix) | |
807 | { | |
808 | const char *index_file; | |
809 | int commitable; | |
810 | ||
ef90d6d4 | 811 | git_config(git_status_config, NULL); |
f5bbc322 | 812 | |
6b2f2d98 MK |
813 | if (wt_status_use_color == -1) |
814 | wt_status_use_color = git_use_color_default; | |
815 | ||
2f02b25f | 816 | argc = parse_and_validate_options(argc, argv, builtin_status_usage); |
f5bbc322 | 817 | |
f64fe7b4 | 818 | index_file = prepare_index(argc, argv, prefix); |
f5bbc322 | 819 | |
37d07f8f | 820 | commitable = run_status(stdout, index_file, prefix, 0); |
f5bbc322 | 821 | |
2888605c | 822 | rollback_index_files(); |
f5bbc322 KH |
823 | |
824 | return commitable ? 0 : 1; | |
825 | } | |
826 | ||
f5bbc322 KH |
827 | static void print_summary(const char *prefix, const unsigned char *sha1) |
828 | { | |
829 | struct rev_info rev; | |
830 | struct commit *commit; | |
831 | ||
832 | commit = lookup_commit(sha1); | |
833 | if (!commit) | |
b5b644a9 | 834 | die("couldn't look up newly created commit"); |
f5bbc322 KH |
835 | if (!commit || parse_commit(commit)) |
836 | die("could not parse newly created commit"); | |
837 | ||
838 | init_revisions(&rev, prefix); | |
839 | setup_revisions(0, NULL, &rev, NULL); | |
840 | ||
841 | rev.abbrev = 0; | |
842 | rev.diff = 1; | |
843 | rev.diffopt.output_format = | |
844 | DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY; | |
845 | ||
846 | rev.verbose_header = 1; | |
847 | rev.show_root_diff = 1; | |
4da45bef | 848 | get_commit_format("format:%h: %s", &rev); |
bf82a150 | 849 | rev.always_show_header = 0; |
3eb2a15e JH |
850 | rev.diffopt.detect_rename = 1; |
851 | rev.diffopt.rename_limit = 100; | |
852 | rev.diffopt.break_opt = 0; | |
15964563 | 853 | diff_setup_done(&rev.diffopt); |
f5bbc322 KH |
854 | |
855 | printf("Created %scommit ", initial_commit ? "initial " : ""); | |
856 | ||
bf82a150 JH |
857 | if (!log_tree_commit(&rev, commit)) { |
858 | struct strbuf buf = STRBUF_INIT; | |
859 | format_commit_message(commit, "%h: %s", &buf); | |
860 | printf("%s\n", buf.buf); | |
861 | strbuf_release(&buf); | |
862 | } | |
f5bbc322 KH |
863 | } |
864 | ||
ef90d6d4 | 865 | int git_commit_config(const char *k, const char *v, void *cb) |
f5bbc322 KH |
866 | { |
867 | if (!strcmp(k, "commit.template")) { | |
d865eb2a JH |
868 | if (!v) |
869 | return config_error_nonbool(v); | |
f5bbc322 KH |
870 | template_file = xstrdup(v); |
871 | return 0; | |
872 | } | |
873 | ||
ef90d6d4 | 874 | return git_status_config(k, v, cb); |
f5bbc322 KH |
875 | } |
876 | ||
877 | static const char commit_utf8_warn[] = | |
878 | "Warning: commit message does not conform to UTF-8.\n" | |
879 | "You may want to amend it after fixing the message, or set the config\n" | |
880 | "variable i18n.commitencoding to the encoding your project uses.\n"; | |
881 | ||
7c3fd25d LT |
882 | static void add_parent(struct strbuf *sb, const unsigned char *sha1) |
883 | { | |
884 | struct object *obj = parse_object(sha1); | |
885 | const char *parent = sha1_to_hex(sha1); | |
67bfc030 JH |
886 | const char *cp; |
887 | ||
7c3fd25d LT |
888 | if (!obj) |
889 | die("Unable to find commit parent %s", parent); | |
890 | if (obj->type != OBJ_COMMIT) | |
891 | die("Parent %s isn't a proper commit", parent); | |
67bfc030 JH |
892 | |
893 | for (cp = sb->buf; cp && (cp = strstr(cp, "\nparent ")); cp += 8) { | |
894 | if (!memcmp(cp + 8, parent, 40) && cp[48] == '\n') { | |
895 | error("duplicate parent %s ignored", parent); | |
896 | return; | |
897 | } | |
898 | } | |
7c3fd25d LT |
899 | strbuf_addf(sb, "parent %s\n", parent); |
900 | } | |
901 | ||
f5bbc322 KH |
902 | int cmd_commit(int argc, const char **argv, const char *prefix) |
903 | { | |
18abc2db | 904 | int header_len; |
f5bbc322 KH |
905 | struct strbuf sb; |
906 | const char *index_file, *reflog_msg; | |
99a12694 | 907 | char *nl, *p; |
f5bbc322 KH |
908 | unsigned char commit_sha1[20]; |
909 | struct ref_lock *ref_lock; | |
910 | ||
ef90d6d4 | 911 | git_config(git_commit_config, NULL); |
f5bbc322 | 912 | |
2f02b25f | 913 | argc = parse_and_validate_options(argc, argv, builtin_commit_usage); |
f5bbc322 | 914 | |
f64fe7b4 | 915 | index_file = prepare_index(argc, argv, prefix); |
f5bbc322 | 916 | |
ec84bd00 PB |
917 | /* Set up everything for writing the commit object. This includes |
918 | running hooks, writing the trees, and interacting with the user. */ | |
919 | if (!prepare_to_commit(index_file, prefix)) { | |
2888605c | 920 | rollback_index_files(); |
f5bbc322 KH |
921 | return 1; |
922 | } | |
923 | ||
2888605c JH |
924 | /* |
925 | * The commit object | |
926 | */ | |
927 | strbuf_init(&sb, 0); | |
f5bbc322 KH |
928 | strbuf_addf(&sb, "tree %s\n", |
929 | sha1_to_hex(active_cache_tree->sha1)); | |
930 | ||
931 | /* Determine parents */ | |
932 | if (initial_commit) { | |
933 | reflog_msg = "commit (initial)"; | |
f5bbc322 KH |
934 | } else if (amend) { |
935 | struct commit_list *c; | |
936 | struct commit *commit; | |
937 | ||
938 | reflog_msg = "commit (amend)"; | |
939 | commit = lookup_commit(head_sha1); | |
940 | if (!commit || parse_commit(commit)) | |
941 | die("could not parse HEAD commit"); | |
942 | ||
943 | for (c = commit->parents; c; c = c->next) | |
7c3fd25d | 944 | add_parent(&sb, c->item->object.sha1); |
f5bbc322 KH |
945 | } else if (in_merge) { |
946 | struct strbuf m; | |
947 | FILE *fp; | |
948 | ||
949 | reflog_msg = "commit (merge)"; | |
7c3fd25d | 950 | add_parent(&sb, head_sha1); |
f5bbc322 KH |
951 | strbuf_init(&m, 0); |
952 | fp = fopen(git_path("MERGE_HEAD"), "r"); | |
953 | if (fp == NULL) | |
954 | die("could not open %s for reading: %s", | |
955 | git_path("MERGE_HEAD"), strerror(errno)); | |
7c3fd25d LT |
956 | while (strbuf_getline(&m, fp, '\n') != EOF) { |
957 | unsigned char sha1[20]; | |
958 | if (get_sha1_hex(m.buf, sha1) < 0) | |
959 | die("Corrupt MERGE_HEAD file (%s)", m.buf); | |
960 | add_parent(&sb, sha1); | |
961 | } | |
f5bbc322 KH |
962 | fclose(fp); |
963 | strbuf_release(&m); | |
964 | } else { | |
965 | reflog_msg = "commit"; | |
966 | strbuf_addf(&sb, "parent %s\n", sha1_to_hex(head_sha1)); | |
967 | } | |
968 | ||
e83dbe80 SB |
969 | strbuf_addf(&sb, "author %s\n", |
970 | fmt_ident(author_name, author_email, author_date, IDENT_ERROR_ON_NO_NAME)); | |
774751a8 | 971 | strbuf_addf(&sb, "committer %s\n", git_committer_info(IDENT_ERROR_ON_NO_NAME)); |
f5bbc322 KH |
972 | if (!is_encoding_utf8(git_commit_encoding)) |
973 | strbuf_addf(&sb, "encoding %s\n", git_commit_encoding); | |
974 | strbuf_addch(&sb, '\n'); | |
975 | ||
ec84bd00 | 976 | /* Finally, get the commit message */ |
f5bbc322 | 977 | header_len = sb.len; |
740001a5 JH |
978 | if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) { |
979 | rollback_index_files(); | |
980 | die("could not read commit message"); | |
981 | } | |
99a12694 KH |
982 | |
983 | /* Truncate the message just before the diff, if any. */ | |
984 | p = strstr(sb.buf, "\ndiff --git a/"); | |
985 | if (p != NULL) | |
a98b8191 | 986 | strbuf_setlen(&sb, p - sb.buf + 1); |
99a12694 | 987 | |
5f065737 AR |
988 | if (cleanup_mode != CLEANUP_NONE) |
989 | stripspace(&sb, cleanup_mode == CLEANUP_ALL); | |
2888605c JH |
990 | if (sb.len < header_len || message_is_empty(&sb, header_len)) { |
991 | rollback_index_files(); | |
b5b644a9 | 992 | die("no commit message? aborting commit."); |
2888605c | 993 | } |
f5bbc322 KH |
994 | strbuf_addch(&sb, '\0'); |
995 | if (is_encoding_utf8(git_commit_encoding) && !is_utf8(sb.buf)) | |
996 | fprintf(stderr, commit_utf8_warn); | |
997 | ||
2888605c JH |
998 | if (write_sha1_file(sb.buf, sb.len - 1, commit_type, commit_sha1)) { |
999 | rollback_index_files(); | |
f5bbc322 | 1000 | die("failed to write commit object"); |
2888605c | 1001 | } |
f5bbc322 KH |
1002 | |
1003 | ref_lock = lock_any_ref_for_update("HEAD", | |
1004 | initial_commit ? NULL : head_sha1, | |
1005 | 0); | |
1006 | ||
1007 | nl = strchr(sb.buf + header_len, '\n'); | |
741707b1 JS |
1008 | if (nl) |
1009 | strbuf_setlen(&sb, nl + 1 - sb.buf); | |
1010 | else | |
1011 | strbuf_addch(&sb, '\n'); | |
1012 | strbuf_remove(&sb, 0, header_len); | |
1013 | strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg)); | |
1014 | strbuf_insert(&sb, strlen(reflog_msg), ": ", 2); | |
f5bbc322 | 1015 | |
2888605c JH |
1016 | if (!ref_lock) { |
1017 | rollback_index_files(); | |
f5bbc322 | 1018 | die("cannot lock HEAD ref"); |
2888605c JH |
1019 | } |
1020 | if (write_ref_sha1(ref_lock, commit_sha1, sb.buf) < 0) { | |
1021 | rollback_index_files(); | |
f5bbc322 | 1022 | die("cannot update HEAD ref"); |
2888605c | 1023 | } |
f5bbc322 KH |
1024 | |
1025 | unlink(git_path("MERGE_HEAD")); | |
1026 | unlink(git_path("MERGE_MSG")); | |
5a95b855 | 1027 | unlink(git_path("SQUASH_MSG")); |
f5bbc322 | 1028 | |
5a9dd399 BC |
1029 | if (commit_index_files()) |
1030 | die ("Repository has been updated, but unable to write\n" | |
1031 | "new_index file. Check that disk is not full or quota is\n" | |
1032 | "not exceeded, and then \"git reset HEAD\" to recover."); | |
f5bbc322 KH |
1033 | |
1034 | rerere(); | |
2888605c | 1035 | run_hook(get_index_file(), "post-commit", NULL); |
f5bbc322 KH |
1036 | if (!quiet) |
1037 | print_summary(prefix, commit_sha1); | |
1038 | ||
1039 | return 0; | |
1040 | } |