4 * Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
5 * Based on git-commit.sh by Junio C Hamano and Linus Torvalds
9 #include "cache-tree.h"
17 #include "wt-status.h"
18 #include "run-command.h"
23 #include "parse-options.h"
24 #include "string-list.h"
26 #include "unpack-trees.h"
28 #include "submodule.h"
29 #include "gpg-interface.h"
32 static const char * const builtin_commit_usage[] = {
33 "git commit [options] [--] <filepattern>...",
37 static const char * const builtin_status_usage[] = {
38 "git status [options] [--] <filepattern>...",
42 static const char implicit_ident_advice[] =
43 N_("Your name and email address were configured automatically based\n"
44 "on your username and hostname. Please check that they are accurate.\n"
45 "You can suppress this message by setting them explicitly:\n"
47 " git config --global user.name \"Your Name\"\n"
48 " git config --global user.email you@example.com\n"
50 "After doing this, you may fix the identity used for this commit with:\n"
52 " git commit --amend --reset-author\n");
54 static const char empty_amend_advice[] =
55 N_("You asked to amend the most recent commit, but doing so would make\n"
56 "it empty. You can repeat your command with --allow-empty, or you can\n"
57 "remove the commit entirely with \"git reset HEAD^\".\n");
59 static const char empty_cherry_pick_advice[] =
60 N_("The previous cherry-pick is now empty, possibly due to conflict resolution.\n"
61 "If you wish to commit it anyway, use:\n"
63 " git commit --allow-empty\n"
65 "Otherwise, please use 'git reset'\n");
67 static const char *use_message_buffer;
68 static const char commit_editmsg[] = "COMMIT_EDITMSG";
69 static struct lock_file index_lock; /* real index */
70 static struct lock_file false_lock; /* used only for partial commits */
77 static const char *logfile, *force_author;
78 static const char *template_file;
80 * The _message variables are commit names from which to take
81 * the commit message and/or authorship.
83 static const char *author_message, *author_message_buffer;
84 static char *edit_message, *use_message;
85 static char *fixup_message, *squash_message;
86 static int all, also, interactive, patch_interactive, only, amend, signoff;
87 static int edit_flag = -1; /* unspecified */
88 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
89 static int no_post_rewrite, allow_empty_message;
90 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
91 static char *sign_commit;
94 * The default commit message cleanup mode will remove the lines
95 * beginning with # (shell comments) and leading and trailing
96 * whitespaces (empty lines or containing only whitespaces)
97 * if editor is used, and only the whitespaces if the message
98 * is specified explicitly.
105 static char *cleanup_arg;
107 static enum commit_whence whence;
108 static int use_editor = 1, include_status = 1;
109 static int show_ignored_in_status;
110 static const char *only_include_assumed;
111 static struct strbuf message = STRBUF_INIT;
116 STATUS_FORMAT_PORCELAIN
117 } status_format = STATUS_FORMAT_LONG;
119 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
121 struct strbuf *buf = opt->value;
123 strbuf_setlen(buf, 0);
125 strbuf_addstr(buf, arg);
126 strbuf_addstr(buf, "\n\n");
131 static void determine_whence(struct wt_status *s)
133 if (file_exists(git_path("MERGE_HEAD")))
135 else if (file_exists(git_path("CHERRY_PICK_HEAD")))
136 whence = FROM_CHERRY_PICK;
138 whence = FROM_COMMIT;
143 static void rollback_index_files(void)
145 switch (commit_style) {
147 break; /* nothing to do */
149 rollback_lock_file(&index_lock);
152 rollback_lock_file(&index_lock);
153 rollback_lock_file(&false_lock);
158 static int commit_index_files(void)
162 switch (commit_style) {
164 break; /* nothing to do */
166 err = commit_lock_file(&index_lock);
169 err = commit_lock_file(&index_lock);
170 rollback_lock_file(&false_lock);
178 * Take a union of paths in the index and the named tree (typically, "HEAD"),
179 * and return the paths that match the given pattern in list.
181 static int list_paths(struct string_list *list, const char *with_tree,
182 const char *prefix, const char **pattern)
190 for (i = 0; pattern[i]; i++)
195 char *max_prefix = common_prefix(pattern);
196 overlay_tree_on_cache(with_tree, max_prefix ? max_prefix : prefix);
200 for (i = 0; i < active_nr; i++) {
201 struct cache_entry *ce = active_cache[i];
202 struct string_list_item *item;
204 if (ce->ce_flags & CE_UPDATE)
206 if (!match_pathspec(pattern, ce->name, ce_namelen(ce), 0, m))
208 item = string_list_insert(list, ce->name);
209 if (ce_skip_worktree(ce))
210 item->util = item; /* better a valid pointer than a fake one */
213 return report_path_error(m, pattern, prefix);
216 static void add_remove_files(struct string_list *list)
219 for (i = 0; i < list->nr; i++) {
221 struct string_list_item *p = &(list->items[i]);
223 /* p->util is skip-worktree */
227 if (!lstat(p->string, &st)) {
228 if (add_to_cache(p->string, &st, 0))
229 die(_("updating files failed"));
231 remove_file_from_cache(p->string);
235 static void create_base_index(const struct commit *current_head)
238 struct unpack_trees_options opts;
246 memset(&opts, 0, sizeof(opts));
250 opts.src_index = &the_index;
251 opts.dst_index = &the_index;
253 opts.fn = oneway_merge;
254 tree = parse_tree_indirect(current_head->object.sha1);
256 die(_("failed to unpack HEAD tree object"));
258 init_tree_desc(&t, tree->buffer, tree->size);
259 if (unpack_trees(1, &t, &opts))
260 exit(128); /* We've already reported the error, finish dying */
263 static void refresh_cache_or_die(int refresh_flags)
266 * refresh_flags contains REFRESH_QUIET, so the only errors
267 * are for unmerged entries.
269 if (refresh_cache(refresh_flags | REFRESH_IN_PORCELAIN))
270 die_resolve_conflict("commit");
273 static char *prepare_index(int argc, const char **argv, const char *prefix,
274 const struct commit *current_head, int is_status)
277 struct string_list partial;
278 const char **pathspec = NULL;
279 char *old_index_env = NULL;
280 int refresh_flags = REFRESH_QUIET;
283 refresh_flags |= REFRESH_UNMERGED;
286 pathspec = get_pathspec(prefix, argv);
288 if (read_cache_preload(pathspec) < 0)
289 die(_("index file corrupt"));
292 fd = hold_locked_index(&index_lock, 1);
294 refresh_cache_or_die(refresh_flags);
296 if (write_cache(fd, active_cache, active_nr) ||
297 close_lock_file(&index_lock))
298 die(_("unable to create temporary index"));
300 old_index_env = getenv(INDEX_ENVIRONMENT);
301 setenv(INDEX_ENVIRONMENT, index_lock.filename, 1);
303 if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
304 die(_("interactive add failed"));
306 if (old_index_env && *old_index_env)
307 setenv(INDEX_ENVIRONMENT, old_index_env, 1);
309 unsetenv(INDEX_ENVIRONMENT);
312 read_cache_from(index_lock.filename);
314 commit_style = COMMIT_NORMAL;
315 return index_lock.filename;
319 * Non partial, non as-is commit.
321 * (1) get the real index;
322 * (2) update the_index as necessary;
323 * (3) write the_index out to the real index (still locked);
324 * (4) return the name of the locked index file.
326 * The caller should run hooks on the locked real index, and
327 * (A) if all goes well, commit the real index;
328 * (B) on failure, rollback the real index.
330 if (all || (also && pathspec && *pathspec)) {
331 fd = hold_locked_index(&index_lock, 1);
332 add_files_to_cache(also ? prefix : NULL, pathspec, 0);
333 refresh_cache_or_die(refresh_flags);
334 update_main_cache_tree(WRITE_TREE_SILENT);
335 if (write_cache(fd, active_cache, active_nr) ||
336 close_lock_file(&index_lock))
337 die(_("unable to write new_index file"));
338 commit_style = COMMIT_NORMAL;
339 return index_lock.filename;
345 * (1) return the name of the real index file.
347 * The caller should run hooks on the real index,
348 * and create commit from the_index.
349 * We still need to refresh the index here.
351 if (!only && (!pathspec || !*pathspec)) {
352 fd = hold_locked_index(&index_lock, 1);
353 refresh_cache_or_die(refresh_flags);
354 if (active_cache_changed) {
355 update_main_cache_tree(WRITE_TREE_SILENT);
356 if (write_cache(fd, active_cache, active_nr) ||
357 commit_locked_index(&index_lock))
358 die(_("unable to write new_index file"));
360 rollback_lock_file(&index_lock);
362 commit_style = COMMIT_AS_IS;
363 return get_index_file();
369 * (0) find the set of affected paths;
370 * (1) get lock on the real index file;
371 * (2) update the_index with the given paths;
372 * (3) write the_index out to the real index (still locked);
373 * (4) get lock on the false index file;
374 * (5) reset the_index from HEAD;
375 * (6) update the_index the same way as (2);
376 * (7) write the_index out to the false index file;
377 * (8) return the name of the false index file (still locked);
379 * The caller should run hooks on the locked false index, and
380 * create commit from it. Then
381 * (A) if all goes well, commit the real index;
382 * (B) on failure, rollback the real index;
383 * In either case, rollback the false index.
385 commit_style = COMMIT_PARTIAL;
387 if (whence != FROM_COMMIT) {
388 if (whence == FROM_MERGE)
389 die(_("cannot do a partial commit during a merge."));
390 else if (whence == FROM_CHERRY_PICK)
391 die(_("cannot do a partial commit during a cherry-pick."));
394 memset(&partial, 0, sizeof(partial));
395 partial.strdup_strings = 1;
396 if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, pathspec))
400 if (read_cache() < 0)
401 die(_("cannot read the index"));
403 fd = hold_locked_index(&index_lock, 1);
404 add_remove_files(&partial);
405 refresh_cache(REFRESH_QUIET);
406 if (write_cache(fd, active_cache, active_nr) ||
407 close_lock_file(&index_lock))
408 die(_("unable to write new_index file"));
410 fd = hold_lock_file_for_update(&false_lock,
411 git_path("next-index-%"PRIuMAX,
412 (uintmax_t) getpid()),
415 create_base_index(current_head);
416 add_remove_files(&partial);
417 refresh_cache(REFRESH_QUIET);
419 if (write_cache(fd, active_cache, active_nr) ||
420 close_lock_file(&false_lock))
421 die(_("unable to write temporary index file"));
424 read_cache_from(false_lock.filename);
426 return false_lock.filename;
429 static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,
432 unsigned char sha1[20];
434 if (s->relative_paths)
439 s->reference = "HEAD^1";
441 s->verbose = verbose;
442 s->index_file = index_file;
445 s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
447 wt_status_collect(s);
449 switch (status_format) {
450 case STATUS_FORMAT_SHORT:
451 wt_shortstatus_print(s);
453 case STATUS_FORMAT_PORCELAIN:
454 wt_porcelain_print(s);
456 case STATUS_FORMAT_LONG:
461 return s->commitable;
464 static int is_a_merge(const struct commit *current_head)
466 return !!(current_head->parents && current_head->parents->next);
469 static const char sign_off_header[] = "Signed-off-by: ";
471 static void export_one(const char *var, const char *s, const char *e, int hack)
473 struct strbuf buf = STRBUF_INIT;
475 strbuf_addch(&buf, hack);
476 strbuf_addf(&buf, "%.*s", (int)(e - s), s);
477 setenv(var, buf.buf, 1);
478 strbuf_release(&buf);
481 static int sane_ident_split(struct ident_split *person)
483 if (!person->name_begin || !person->name_end ||
484 person->name_begin == person->name_end)
485 return 0; /* no human readable name */
486 if (!person->mail_begin || !person->mail_end ||
487 person->mail_begin == person->mail_end)
488 return 0; /* no usable mail */
489 if (!person->date_begin || !person->date_end ||
490 !person->tz_begin || !person->tz_end)
495 static void determine_author_info(struct strbuf *author_ident)
497 char *name, *email, *date;
498 struct ident_split author;
500 name = getenv("GIT_AUTHOR_NAME");
501 email = getenv("GIT_AUTHOR_EMAIL");
502 date = getenv("GIT_AUTHOR_DATE");
504 if (author_message) {
505 const char *a, *lb, *rb, *eol;
508 a = strstr(author_message_buffer, "\nauthor ");
510 die(_("invalid commit: %s"), author_message);
512 lb = strchrnul(a + strlen("\nauthor "), '<');
513 rb = strchrnul(lb, '>');
514 eol = strchrnul(rb, '\n');
515 if (!*lb || !*rb || !*eol)
516 die(_("invalid commit: %s"), author_message);
518 if (lb == a + strlen("\nauthor "))
519 /* \nauthor <foo@example.com> */
520 name = xcalloc(1, 1);
522 name = xmemdupz(a + strlen("\nauthor "),
524 (a + strlen("\nauthor "))));
525 email = xmemdupz(lb + strlen("<"), rb - (lb + strlen("<")));
526 date = xmemdupz(rb + strlen("> "), eol - (rb + strlen("> ")));
527 len = eol - (rb + strlen("> "));
528 date = xmalloc(len + 2);
530 memcpy(date + 1, rb + strlen("> "), len);
531 date[len + 1] = '\0';
535 const char *lb = strstr(force_author, " <");
536 const char *rb = strchr(force_author, '>');
539 die(_("malformed --author parameter"));
540 name = xstrndup(force_author, lb - force_author);
541 email = xstrndup(lb + 2, rb - (lb + 2));
546 strbuf_addstr(author_ident, fmt_ident(name, email, date, IDENT_STRICT));
547 if (!split_ident_line(&author, author_ident->buf, author_ident->len) &&
548 sane_ident_split(&author)) {
549 export_one("GIT_AUTHOR_NAME", author.name_begin, author.name_end, 0);
550 export_one("GIT_AUTHOR_EMAIL", author.mail_begin, author.mail_end, 0);
551 export_one("GIT_AUTHOR_DATE", author.date_begin, author.tz_end, '@');
555 static int ends_rfc2822_footer(struct strbuf *sb)
562 const char *buf = sb->buf;
564 for (i = len - 1; i > 0; i--) {
565 if (hit && buf[i] == '\n')
567 hit = (buf[i] == '\n');
570 while (i < len - 1 && buf[i] == '\n')
573 for (; i < len; i = k) {
574 for (k = i; k < len && buf[k] != '\n'; k++)
578 if ((buf[k] == ' ' || buf[k] == '\t') && !first)
583 for (j = 0; i + j < len; j++) {
596 static char *cut_ident_timestamp_part(char *string)
598 char *ket = strrchr(string, '>');
599 if (!ket || ket[1] != ' ')
600 die(_("Malformed ident string: '%s'"), string);
605 static int prepare_to_commit(const char *index_file, const char *prefix,
606 struct commit *current_head,
608 struct strbuf *author_ident)
611 struct strbuf committer_ident = STRBUF_INIT;
612 int commitable, saved_color_setting;
613 struct strbuf sb = STRBUF_INIT;
615 const char *hook_arg1 = NULL;
616 const char *hook_arg2 = NULL;
618 int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
620 /* This checks and barfs if author is badly specified */
621 determine_author_info(author_ident);
623 if (!no_verify && run_hook(index_file, "pre-commit", NULL))
626 if (squash_message) {
628 * Insert the proper subject line before other commit
629 * message options add their content.
631 if (use_message && !strcmp(use_message, squash_message))
632 strbuf_addstr(&sb, "squash! ");
634 struct pretty_print_context ctx = {0};
636 c = lookup_commit_reference_by_name(squash_message);
638 die(_("could not lookup commit %s"), squash_message);
639 ctx.output_encoding = get_commit_output_encoding();
640 format_commit_message(c, "squash! %s\n\n", &sb,
646 strbuf_addbuf(&sb, &message);
647 hook_arg1 = "message";
648 } else if (logfile && !strcmp(logfile, "-")) {
650 fprintf(stderr, _("(reading log message from standard input)\n"));
651 if (strbuf_read(&sb, 0, 0) < 0)
652 die_errno(_("could not read log from standard input"));
653 hook_arg1 = "message";
654 } else if (logfile) {
655 if (strbuf_read_file(&sb, logfile, 0) < 0)
656 die_errno(_("could not read log file '%s'"),
658 hook_arg1 = "message";
659 } else if (use_message) {
660 buffer = strstr(use_message_buffer, "\n\n");
661 if (!use_editor && (!buffer || buffer[2] == '\0'))
662 die(_("commit has empty message"));
663 strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
664 hook_arg1 = "commit";
665 hook_arg2 = use_message;
666 } else if (fixup_message) {
667 struct pretty_print_context ctx = {0};
668 struct commit *commit;
669 commit = lookup_commit_reference_by_name(fixup_message);
671 die(_("could not lookup commit %s"), fixup_message);
672 ctx.output_encoding = get_commit_output_encoding();
673 format_commit_message(commit, "fixup! %s\n\n",
675 hook_arg1 = "message";
676 } else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
677 if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
678 die_errno(_("could not read MERGE_MSG"));
680 } else if (!stat(git_path("SQUASH_MSG"), &statbuf)) {
681 if (strbuf_read_file(&sb, git_path("SQUASH_MSG"), 0) < 0)
682 die_errno(_("could not read SQUASH_MSG"));
683 hook_arg1 = "squash";
684 } else if (template_file) {
685 if (strbuf_read_file(&sb, template_file, 0) < 0)
686 die_errno(_("could not read '%s'"), template_file);
687 hook_arg1 = "template";
688 clean_message_contents = 0;
692 * The remaining cases don't modify the template message, but
693 * just set the argument(s) to the prepare-commit-msg hook.
695 else if (whence == FROM_MERGE)
697 else if (whence == FROM_CHERRY_PICK) {
698 hook_arg1 = "commit";
699 hook_arg2 = "CHERRY_PICK_HEAD";
702 if (squash_message) {
704 * If squash_commit was used for the commit subject,
705 * then we're possibly hijacking other commit log options.
706 * Reset the hook args to tell the real story.
708 hook_arg1 = "message";
712 s->fp = fopen(git_path(commit_editmsg), "w");
714 die_errno(_("could not open '%s'"), git_path(commit_editmsg));
716 if (clean_message_contents)
720 struct strbuf sob = STRBUF_INIT;
723 strbuf_addstr(&sob, sign_off_header);
724 strbuf_addstr(&sob, fmt_name(getenv("GIT_COMMITTER_NAME"),
725 getenv("GIT_COMMITTER_EMAIL")));
726 strbuf_addch(&sob, '\n');
727 for (i = sb.len - 1; i > 0 && sb.buf[i - 1] != '\n'; i--)
729 if (prefixcmp(sb.buf + i, sob.buf)) {
730 if (!i || !ends_rfc2822_footer(&sb))
731 strbuf_addch(&sb, '\n');
732 strbuf_addbuf(&sb, &sob);
734 strbuf_release(&sob);
737 if (fwrite(sb.buf, 1, sb.len, s->fp) < sb.len)
738 die_errno(_("could not write commit template"));
742 /* This checks if committer ident is explicitly given */
743 strbuf_addstr(&committer_ident, git_committer_info(IDENT_STRICT));
744 if (use_editor && include_status) {
745 char *ai_tmp, *ci_tmp;
746 if (whence != FROM_COMMIT)
747 status_printf_ln(s, GIT_COLOR_NORMAL,
750 "It looks like you may be committing a merge.\n"
751 "If this is not correct, please remove the file\n"
755 "It looks like you may be committing a cherry-pick.\n"
756 "If this is not correct, please remove the file\n"
759 git_path(whence == FROM_MERGE
761 : "CHERRY_PICK_HEAD"));
763 fprintf(s->fp, "\n");
764 if (cleanup_mode == CLEANUP_ALL)
765 status_printf(s, GIT_COLOR_NORMAL,
766 _("Please enter the commit message for your changes."
767 " Lines starting\nwith '#' will be ignored, and an empty"
768 " message aborts the commit.\n"));
769 else /* CLEANUP_SPACE, that is. */
770 status_printf(s, GIT_COLOR_NORMAL,
771 _("Please enter the commit message for your changes."
773 "with '#' will be kept; you may remove them"
774 " yourself if you want to.\n"
775 "An empty message aborts the commit.\n"));
776 if (only_include_assumed)
777 status_printf_ln(s, GIT_COLOR_NORMAL,
778 "%s", only_include_assumed);
780 ai_tmp = cut_ident_timestamp_part(author_ident->buf);
781 ci_tmp = cut_ident_timestamp_part(committer_ident.buf);
782 if (strcmp(author_ident->buf, committer_ident.buf))
783 status_printf_ln(s, GIT_COLOR_NORMAL,
786 ident_shown++ ? "" : "\n",
789 if (!user_ident_sufficiently_given())
790 status_printf_ln(s, GIT_COLOR_NORMAL,
793 ident_shown++ ? "" : "\n",
794 committer_ident.buf);
797 status_printf_ln(s, GIT_COLOR_NORMAL, "");
799 saved_color_setting = s->use_color;
801 commitable = run_status(s->fp, index_file, prefix, 1, s);
802 s->use_color = saved_color_setting;
807 unsigned char sha1[20];
808 const char *parent = "HEAD";
810 if (!active_nr && read_cache() < 0)
811 die(_("Cannot read index"));
816 if (get_sha1(parent, sha1))
817 commitable = !!active_nr;
819 commitable = index_differs_from(parent, 0);
821 strbuf_release(&committer_ident);
826 * Reject an attempt to record a non-merge empty commit without
827 * explicit --allow-empty. In the cherry-pick case, it may be
828 * empty due to conflict resolution, which the user should okay.
830 if (!commitable && whence != FROM_MERGE && !allow_empty &&
831 !(amend && is_a_merge(current_head))) {
832 run_status(stdout, index_file, prefix, 0, s);
834 fputs(_(empty_amend_advice), stderr);
835 else if (whence == FROM_CHERRY_PICK)
836 fputs(_(empty_cherry_pick_advice), stderr);
841 * Re-read the index as pre-commit hook could have updated it,
842 * and write it out as a tree. We must do this before we invoke
843 * the editor and after we invoke run_status above.
846 read_cache_from(index_file);
847 if (update_main_cache_tree(0)) {
848 error(_("Error building trees"));
852 if (run_hook(index_file, "prepare-commit-msg",
853 git_path(commit_editmsg), hook_arg1, hook_arg2, NULL))
857 char index[PATH_MAX];
858 const char *env[2] = { NULL };
860 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", index_file);
861 if (launch_editor(git_path(commit_editmsg), NULL, env)) {
863 _("Please supply the message using either -m or -F option.\n"));
869 run_hook(index_file, "commit-msg", git_path(commit_editmsg), NULL)) {
876 static int rest_is_empty(struct strbuf *sb, int start)
881 /* Check if the rest is just whitespace and Signed-of-by's. */
882 for (i = start; i < sb->len; i++) {
883 nl = memchr(sb->buf + i, '\n', sb->len - i);
889 if (strlen(sign_off_header) <= eol - i &&
890 !prefixcmp(sb->buf + i, sign_off_header)) {
895 if (!isspace(sb->buf[i++]))
903 * Find out if the message in the strbuf contains only whitespace and
904 * Signed-off-by lines.
906 static int message_is_empty(struct strbuf *sb)
908 if (cleanup_mode == CLEANUP_NONE && sb->len)
910 return rest_is_empty(sb, 0);
914 * See if the user edited the message in the editor or left what
915 * was in the template intact
917 static int template_untouched(struct strbuf *sb)
919 struct strbuf tmpl = STRBUF_INIT;
922 if (cleanup_mode == CLEANUP_NONE && sb->len)
925 if (!template_file || strbuf_read_file(&tmpl, template_file, 0) <= 0)
928 stripspace(&tmpl, cleanup_mode == CLEANUP_ALL);
929 start = (char *)skip_prefix(sb->buf, tmpl.buf);
932 strbuf_release(&tmpl);
933 return rest_is_empty(sb, start - sb->buf);
936 static const char *find_author_by_nickname(const char *name)
938 struct rev_info revs;
939 struct commit *commit;
940 struct strbuf buf = STRBUF_INIT;
944 init_revisions(&revs, NULL);
945 strbuf_addf(&buf, "--author=%s", name);
950 setup_revisions(ac, av, &revs, NULL);
951 prepare_revision_walk(&revs);
952 commit = get_revision(&revs);
954 struct pretty_print_context ctx = {0};
955 ctx.date_mode = DATE_NORMAL;
956 strbuf_release(&buf);
957 format_commit_message(commit, "%an <%ae>", &buf, &ctx);
958 return strbuf_detach(&buf, NULL);
960 die(_("No existing author found with '%s'"), name);
964 static void handle_untracked_files_arg(struct wt_status *s)
966 if (!untracked_files_arg)
967 ; /* default already initialized */
968 else if (!strcmp(untracked_files_arg, "no"))
969 s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
970 else if (!strcmp(untracked_files_arg, "normal"))
971 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
972 else if (!strcmp(untracked_files_arg, "all"))
973 s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
975 die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
978 static const char *read_commit_message(const char *name)
980 const char *out_enc, *out;
981 struct commit *commit;
983 commit = lookup_commit_reference_by_name(name);
985 die(_("could not lookup commit %s"), name);
986 out_enc = get_commit_output_encoding();
987 out = logmsg_reencode(commit, out_enc);
990 * If we failed to reencode the buffer, just copy it
991 * byte for byte so the user can try to fix it up.
992 * This also handles the case where input and output
993 * encodings are identical.
996 out = xstrdup(commit->buffer);
1000 static int parse_and_validate_options(int argc, const char *argv[],
1001 const struct option *options,
1002 const char * const usage[],
1004 struct commit *current_head,
1005 struct wt_status *s)
1009 argc = parse_options(argc, argv, prefix, options, usage, 0);
1011 if (force_author && !strchr(force_author, '>'))
1012 force_author = find_author_by_nickname(force_author);
1014 if (force_author && renew_authorship)
1015 die(_("Using both --reset-author and --author does not make sense"));
1017 if (logfile || message.len || use_message || fixup_message)
1020 use_editor = edit_flag;
1022 setenv("GIT_EDITOR", ":", 1);
1024 /* Sanity check options */
1025 if (amend && !current_head)
1026 die(_("You have nothing to amend."));
1027 if (amend && whence != FROM_COMMIT) {
1028 if (whence == FROM_MERGE)
1029 die(_("You are in the middle of a merge -- cannot amend."));
1030 else if (whence == FROM_CHERRY_PICK)
1031 die(_("You are in the middle of a cherry-pick -- cannot amend."));
1033 if (fixup_message && squash_message)
1034 die(_("Options --squash and --fixup cannot be used together"));
1044 die(_("Only one of -c/-C/-F/--fixup can be used."));
1045 if (message.len && f > 0)
1046 die((_("Option -m cannot be combined with -c/-C/-F/--fixup.")));
1047 if (f || message.len)
1048 template_file = NULL;
1050 use_message = edit_message;
1051 if (amend && !use_message && !fixup_message)
1052 use_message = "HEAD";
1053 if (!use_message && whence != FROM_CHERRY_PICK && renew_authorship)
1054 die(_("--reset-author can be used only with -C, -c or --amend."));
1056 use_message_buffer = read_commit_message(use_message);
1057 if (!renew_authorship) {
1058 author_message = use_message;
1059 author_message_buffer = use_message_buffer;
1062 if (whence == FROM_CHERRY_PICK && !renew_authorship) {
1063 author_message = "CHERRY_PICK_HEAD";
1064 author_message_buffer = read_commit_message(author_message);
1067 if (patch_interactive)
1070 if (!!also + !!only + !!all + !!interactive > 1)
1071 die(_("Only one of --include/--only/--all/--interactive/--patch can be used."));
1072 if (argc == 0 && (also || (only && !amend)))
1073 die(_("No paths with --include/--only does not make sense."));
1074 if (argc == 0 && only && amend)
1075 only_include_assumed = _("Clever... amending the last one with dirty index.");
1076 if (argc > 0 && !also && !only)
1077 only_include_assumed = _("Explicit paths specified without -i nor -o; assuming --only paths...");
1078 if (!cleanup_arg || !strcmp(cleanup_arg, "default"))
1079 cleanup_mode = use_editor ? CLEANUP_ALL : CLEANUP_SPACE;
1080 else if (!strcmp(cleanup_arg, "verbatim"))
1081 cleanup_mode = CLEANUP_NONE;
1082 else if (!strcmp(cleanup_arg, "whitespace"))
1083 cleanup_mode = CLEANUP_SPACE;
1084 else if (!strcmp(cleanup_arg, "strip"))
1085 cleanup_mode = CLEANUP_ALL;
1087 die(_("Invalid cleanup mode %s"), cleanup_arg);
1089 handle_untracked_files_arg(s);
1091 if (all && argc > 0)
1092 die(_("Paths with -a does not make sense."));
1094 if (s->null_termination && status_format == STATUS_FORMAT_LONG)
1095 status_format = STATUS_FORMAT_PORCELAIN;
1096 if (status_format != STATUS_FORMAT_LONG)
1102 static int dry_run_commit(int argc, const char **argv, const char *prefix,
1103 const struct commit *current_head, struct wt_status *s)
1106 const char *index_file;
1108 index_file = prepare_index(argc, argv, prefix, current_head, 1);
1109 commitable = run_status(stdout, index_file, prefix, 0, s);
1110 rollback_index_files();
1112 return commitable ? 0 : 1;
1115 static int parse_status_slot(const char *var, int offset)
1117 if (!strcasecmp(var+offset, "header"))
1118 return WT_STATUS_HEADER;
1119 if (!strcasecmp(var+offset, "branch"))
1120 return WT_STATUS_ONBRANCH;
1121 if (!strcasecmp(var+offset, "updated")
1122 || !strcasecmp(var+offset, "added"))
1123 return WT_STATUS_UPDATED;
1124 if (!strcasecmp(var+offset, "changed"))
1125 return WT_STATUS_CHANGED;
1126 if (!strcasecmp(var+offset, "untracked"))
1127 return WT_STATUS_UNTRACKED;
1128 if (!strcasecmp(var+offset, "nobranch"))
1129 return WT_STATUS_NOBRANCH;
1130 if (!strcasecmp(var+offset, "unmerged"))
1131 return WT_STATUS_UNMERGED;
1135 static int git_status_config(const char *k, const char *v, void *cb)
1137 struct wt_status *s = cb;
1139 if (!prefixcmp(k, "column."))
1140 return git_column_config(k, v, "status", &s->colopts);
1141 if (!strcmp(k, "status.submodulesummary")) {
1143 s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
1144 if (is_bool && s->submodule_summary)
1145 s->submodule_summary = -1;
1148 if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
1149 s->use_color = git_config_colorbool(k, v);
1152 if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
1153 int slot = parse_status_slot(k, 13);
1157 return config_error_nonbool(k);
1158 color_parse(v, k, s->color_palette[slot]);
1161 if (!strcmp(k, "status.relativepaths")) {
1162 s->relative_paths = git_config_bool(k, v);
1165 if (!strcmp(k, "status.showuntrackedfiles")) {
1167 return config_error_nonbool(k);
1168 else if (!strcmp(v, "no"))
1169 s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
1170 else if (!strcmp(v, "normal"))
1171 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
1172 else if (!strcmp(v, "all"))
1173 s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
1175 return error(_("Invalid untracked files mode '%s'"), v);
1178 return git_diff_ui_config(k, v, NULL);
1181 int cmd_status(int argc, const char **argv, const char *prefix)
1183 static struct wt_status s;
1185 unsigned char sha1[20];
1186 static struct option builtin_status_options[] = {
1187 OPT__VERBOSE(&verbose, "be verbose"),
1188 OPT_SET_INT('s', "short", &status_format,
1189 "show status concisely", STATUS_FORMAT_SHORT),
1190 OPT_BOOLEAN('b', "branch", &s.show_branch,
1191 "show branch information"),
1192 OPT_SET_INT(0, "porcelain", &status_format,
1193 "machine-readable output",
1194 STATUS_FORMAT_PORCELAIN),
1195 OPT_BOOLEAN('z', "null", &s.null_termination,
1196 "terminate entries with NUL"),
1197 { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
1199 "show untracked files, optional modes: all, normal, no. (Default: all)",
1200 PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1201 OPT_BOOLEAN(0, "ignored", &show_ignored_in_status,
1202 "show ignored files"),
1203 { OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
1204 "ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
1205 PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1206 OPT_COLUMN(0, "column", &s.colopts, "list untracked files in columns"),
1210 if (argc == 2 && !strcmp(argv[1], "-h"))
1211 usage_with_options(builtin_status_usage, builtin_status_options);
1213 wt_status_prepare(&s);
1214 gitmodules_config();
1215 git_config(git_status_config, &s);
1216 determine_whence(&s);
1217 argc = parse_options(argc, argv, prefix,
1218 builtin_status_options,
1219 builtin_status_usage, 0);
1220 finalize_colopts(&s.colopts, -1);
1222 if (s.null_termination && status_format == STATUS_FORMAT_LONG)
1223 status_format = STATUS_FORMAT_PORCELAIN;
1225 handle_untracked_files_arg(&s);
1226 if (show_ignored_in_status)
1227 s.show_ignored_files = 1;
1229 s.pathspec = get_pathspec(prefix, argv);
1231 read_cache_preload(s.pathspec);
1232 refresh_index(&the_index, REFRESH_QUIET|REFRESH_UNMERGED, s.pathspec, NULL, NULL);
1234 fd = hold_locked_index(&index_lock, 0);
1236 update_index_if_able(&the_index, &index_lock);
1238 s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
1239 s.ignore_submodule_arg = ignore_submodule_arg;
1240 wt_status_collect(&s);
1242 if (s.relative_paths)
1245 switch (status_format) {
1246 case STATUS_FORMAT_SHORT:
1247 wt_shortstatus_print(&s);
1249 case STATUS_FORMAT_PORCELAIN:
1250 wt_porcelain_print(&s);
1252 case STATUS_FORMAT_LONG:
1253 s.verbose = verbose;
1254 s.ignore_submodule_arg = ignore_submodule_arg;
1255 wt_status_print(&s);
1261 static void print_summary(const char *prefix, const unsigned char *sha1,
1264 struct rev_info rev;
1265 struct commit *commit;
1266 struct strbuf format = STRBUF_INIT;
1267 unsigned char junk_sha1[20];
1269 struct pretty_print_context pctx = {0};
1270 struct strbuf author_ident = STRBUF_INIT;
1271 struct strbuf committer_ident = STRBUF_INIT;
1273 commit = lookup_commit(sha1);
1275 die(_("couldn't look up newly created commit"));
1276 if (!commit || parse_commit(commit))
1277 die(_("could not parse newly created commit"));
1279 strbuf_addstr(&format, "format:%h] %s");
1281 format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
1282 format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
1283 if (strbuf_cmp(&author_ident, &committer_ident)) {
1284 strbuf_addstr(&format, "\n Author: ");
1285 strbuf_addbuf_percentquote(&format, &author_ident);
1287 if (!user_ident_sufficiently_given()) {
1288 strbuf_addstr(&format, "\n Committer: ");
1289 strbuf_addbuf_percentquote(&format, &committer_ident);
1290 if (advice_implicit_identity) {
1291 strbuf_addch(&format, '\n');
1292 strbuf_addstr(&format, _(implicit_ident_advice));
1295 strbuf_release(&author_ident);
1296 strbuf_release(&committer_ident);
1298 init_revisions(&rev, prefix);
1299 setup_revisions(0, NULL, &rev, NULL);
1302 rev.diffopt.output_format =
1303 DIFF_FORMAT_SHORTSTAT | DIFF_FORMAT_SUMMARY;
1305 rev.verbose_header = 1;
1306 rev.show_root_diff = 1;
1307 get_commit_format(format.buf, &rev);
1308 rev.always_show_header = 0;
1309 rev.diffopt.detect_rename = 1;
1310 rev.diffopt.break_opt = 0;
1311 diff_setup_done(&rev.diffopt);
1313 head = resolve_ref_unsafe("HEAD", junk_sha1, 0, NULL);
1315 !prefixcmp(head, "refs/heads/") ?
1317 !strcmp(head, "HEAD") ?
1318 _("detached HEAD") :
1320 initial_commit ? _(" (root-commit)") : "");
1322 if (!log_tree_commit(&rev, commit)) {
1323 rev.always_show_header = 1;
1324 rev.use_terminator = 1;
1325 log_tree_commit(&rev, commit);
1328 strbuf_release(&format);
1331 static int git_commit_config(const char *k, const char *v, void *cb)
1333 struct wt_status *s = cb;
1336 if (!strcmp(k, "commit.template"))
1337 return git_config_pathname(&template_file, k, v);
1338 if (!strcmp(k, "commit.status")) {
1339 include_status = git_config_bool(k, v);
1343 status = git_gpg_config(k, v, NULL);
1346 return git_status_config(k, v, s);
1349 static const char post_rewrite_hook[] = "hooks/post-rewrite";
1351 static int run_rewrite_hook(const unsigned char *oldsha1,
1352 const unsigned char *newsha1)
1354 /* oldsha1 SP newsha1 LF NUL */
1355 static char buf[2*40 + 3];
1356 struct child_process proc;
1357 const char *argv[3];
1361 if (access(git_path(post_rewrite_hook), X_OK) < 0)
1364 argv[0] = git_path(post_rewrite_hook);
1368 memset(&proc, 0, sizeof(proc));
1371 proc.stdout_to_stderr = 1;
1373 code = start_command(&proc);
1376 n = snprintf(buf, sizeof(buf), "%s %s\n",
1377 sha1_to_hex(oldsha1), sha1_to_hex(newsha1));
1378 write_in_full(proc.in, buf, n);
1380 return finish_command(&proc);
1383 int cmd_commit(int argc, const char **argv, const char *prefix)
1385 static struct wt_status s;
1386 static struct option builtin_commit_options[] = {
1387 OPT__QUIET(&quiet, "suppress summary after successful commit"),
1388 OPT__VERBOSE(&verbose, "show diff in commit message template"),
1390 OPT_GROUP("Commit message options"),
1391 OPT_FILENAME('F', "file", &logfile, "read message from file"),
1392 OPT_STRING(0, "author", &force_author, "author", "override author for commit"),
1393 OPT_STRING(0, "date", &force_date, "date", "override date for commit"),
1394 OPT_CALLBACK('m', "message", &message, "message", "commit message", opt_parse_m),
1395 OPT_STRING('c', "reedit-message", &edit_message, "commit", "reuse and edit message from specified commit"),
1396 OPT_STRING('C', "reuse-message", &use_message, "commit", "reuse message from specified commit"),
1397 OPT_STRING(0, "fixup", &fixup_message, "commit", "use autosquash formatted message to fixup specified commit"),
1398 OPT_STRING(0, "squash", &squash_message, "commit", "use autosquash formatted message to squash specified commit"),
1399 OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C/-c/--amend)"),
1400 OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
1401 OPT_FILENAME('t', "template", &template_file, "use specified template file"),
1402 OPT_BOOL('e', "edit", &edit_flag, "force edit of commit"),
1403 OPT_STRING(0, "cleanup", &cleanup_arg, "default", "how to strip spaces and #comments from message"),
1404 OPT_BOOLEAN(0, "status", &include_status, "include status in commit message template"),
1405 { OPTION_STRING, 'S', "gpg-sign", &sign_commit, "key id",
1406 "GPG sign commit", PARSE_OPT_OPTARG, NULL, (intptr_t) "" },
1407 /* end commit message options */
1409 OPT_GROUP("Commit contents options"),
1410 OPT_BOOLEAN('a', "all", &all, "commit all changed files"),
1411 OPT_BOOLEAN('i', "include", &also, "add specified files to index for commit"),
1412 OPT_BOOLEAN(0, "interactive", &interactive, "interactively add files"),
1413 OPT_BOOLEAN('p', "patch", &patch_interactive, "interactively add changes"),
1414 OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
1415 OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
1416 OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
1417 OPT_SET_INT(0, "short", &status_format, "show status concisely",
1418 STATUS_FORMAT_SHORT),
1419 OPT_BOOLEAN(0, "branch", &s.show_branch, "show branch information"),
1420 OPT_SET_INT(0, "porcelain", &status_format,
1421 "machine-readable output", STATUS_FORMAT_PORCELAIN),
1422 OPT_BOOLEAN('z', "null", &s.null_termination,
1423 "terminate entries with NUL"),
1424 OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
1425 OPT_BOOLEAN(0, "no-post-rewrite", &no_post_rewrite, "bypass post-rewrite hook"),
1426 { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1427 /* end commit contents options */
1429 { OPTION_BOOLEAN, 0, "allow-empty", &allow_empty, NULL,
1430 "ok to record an empty change",
1431 PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1432 { OPTION_BOOLEAN, 0, "allow-empty-message", &allow_empty_message, NULL,
1433 "ok to record a change with an empty message",
1434 PARSE_OPT_NOARG | PARSE_OPT_HIDDEN },
1439 struct strbuf sb = STRBUF_INIT;
1440 struct strbuf author_ident = STRBUF_INIT;
1441 const char *index_file, *reflog_msg;
1443 unsigned char sha1[20];
1444 struct ref_lock *ref_lock;
1445 struct commit_list *parents = NULL, **pptr = &parents;
1446 struct stat statbuf;
1447 int allow_fast_forward = 1;
1448 struct commit *current_head = NULL;
1449 struct commit_extra_header *extra = NULL;
1451 if (argc == 2 && !strcmp(argv[1], "-h"))
1452 usage_with_options(builtin_commit_usage, builtin_commit_options);
1454 wt_status_prepare(&s);
1455 git_config(git_commit_config, &s);
1456 determine_whence(&s);
1459 if (get_sha1("HEAD", sha1))
1460 current_head = NULL;
1462 current_head = lookup_commit_or_die(sha1, "HEAD");
1463 if (!current_head || parse_commit(current_head))
1464 die(_("could not parse HEAD commit"));
1466 argc = parse_and_validate_options(argc, argv, builtin_commit_options,
1467 builtin_commit_usage,
1468 prefix, current_head, &s);
1470 return dry_run_commit(argc, argv, prefix, current_head, &s);
1471 index_file = prepare_index(argc, argv, prefix, current_head, 0);
1473 /* Set up everything for writing the commit object. This includes
1474 running hooks, writing the trees, and interacting with the user. */
1475 if (!prepare_to_commit(index_file, prefix,
1476 current_head, &s, &author_ident)) {
1477 rollback_index_files();
1481 /* Determine parents */
1482 reflog_msg = getenv("GIT_REFLOG_ACTION");
1483 if (!current_head) {
1485 reflog_msg = "commit (initial)";
1487 struct commit_list *c;
1490 reflog_msg = "commit (amend)";
1491 for (c = current_head->parents; c; c = c->next)
1492 pptr = &commit_list_insert(c->item, pptr)->next;
1493 } else if (whence == FROM_MERGE) {
1494 struct strbuf m = STRBUF_INIT;
1498 reflog_msg = "commit (merge)";
1499 pptr = &commit_list_insert(current_head, pptr)->next;
1500 fp = fopen(git_path("MERGE_HEAD"), "r");
1502 die_errno(_("could not open '%s' for reading"),
1503 git_path("MERGE_HEAD"));
1504 while (strbuf_getline(&m, fp, '\n') != EOF) {
1505 struct commit *parent;
1507 parent = get_merge_parent(m.buf);
1509 die(_("Corrupt MERGE_HEAD file (%s)"), m.buf);
1510 pptr = &commit_list_insert(parent, pptr)->next;
1514 if (!stat(git_path("MERGE_MODE"), &statbuf)) {
1515 if (strbuf_read_file(&sb, git_path("MERGE_MODE"), 0) < 0)
1516 die_errno(_("could not read MERGE_MODE"));
1517 if (!strcmp(sb.buf, "no-ff"))
1518 allow_fast_forward = 0;
1520 if (allow_fast_forward)
1521 parents = reduce_heads(parents);
1524 reflog_msg = (whence == FROM_CHERRY_PICK)
1525 ? "commit (cherry-pick)"
1527 pptr = &commit_list_insert(current_head, pptr)->next;
1530 /* Finally, get the commit message */
1532 if (strbuf_read_file(&sb, git_path(commit_editmsg), 0) < 0) {
1533 int saved_errno = errno;
1534 rollback_index_files();
1535 die(_("could not read commit message: %s"), strerror(saved_errno));
1538 /* Truncate the message just before the diff, if any. */
1540 p = strstr(sb.buf, "\ndiff --git ");
1542 strbuf_setlen(&sb, p - sb.buf + 1);
1545 if (cleanup_mode != CLEANUP_NONE)
1546 stripspace(&sb, cleanup_mode == CLEANUP_ALL);
1547 if (template_untouched(&sb) && !allow_empty_message) {
1548 rollback_index_files();
1549 fprintf(stderr, _("Aborting commit; you did not edit the message.\n"));
1552 if (message_is_empty(&sb) && !allow_empty_message) {
1553 rollback_index_files();
1554 fprintf(stderr, _("Aborting commit due to empty commit message.\n"));
1559 const char *exclude_gpgsig[2] = { "gpgsig", NULL };
1560 extra = read_commit_extra_headers(current_head, exclude_gpgsig);
1562 struct commit_extra_header **tail = &extra;
1563 append_merge_tag_headers(parents, &tail);
1566 if (commit_tree_extended(&sb, active_cache_tree->sha1, parents, sha1,
1567 author_ident.buf, sign_commit, extra)) {
1568 rollback_index_files();
1569 die(_("failed to write commit object"));
1571 strbuf_release(&author_ident);
1572 free_commit_extra_headers(extra);
1574 ref_lock = lock_any_ref_for_update("HEAD",
1577 : current_head->object.sha1,
1580 nl = strchr(sb.buf, '\n');
1582 strbuf_setlen(&sb, nl + 1 - sb.buf);
1584 strbuf_addch(&sb, '\n');
1585 strbuf_insert(&sb, 0, reflog_msg, strlen(reflog_msg));
1586 strbuf_insert(&sb, strlen(reflog_msg), ": ", 2);
1589 rollback_index_files();
1590 die(_("cannot lock HEAD ref"));
1592 if (write_ref_sha1(ref_lock, sha1, sb.buf) < 0) {
1593 rollback_index_files();
1594 die(_("cannot update HEAD ref"));
1597 unlink(git_path("CHERRY_PICK_HEAD"));
1598 unlink(git_path("REVERT_HEAD"));
1599 unlink(git_path("MERGE_HEAD"));
1600 unlink(git_path("MERGE_MSG"));
1601 unlink(git_path("MERGE_MODE"));
1602 unlink(git_path("SQUASH_MSG"));
1604 if (commit_index_files())
1605 die (_("Repository has been updated, but unable to write\n"
1606 "new_index file. Check that disk is not full or quota is\n"
1607 "not exceeded, and then \"git reset HEAD\" to recover."));
1610 run_hook(get_index_file(), "post-commit", NULL);
1611 if (amend && !no_post_rewrite) {
1612 struct notes_rewrite_cfg *cfg;
1613 cfg = init_copy_notes_for_rewrite("amend");
1615 /* we are amending, so current_head is not NULL */
1616 copy_note_for_rewrite(cfg, current_head->object.sha1, sha1);
1617 finish_copy_notes_for_rewrite(cfg);
1619 run_rewrite_hook(current_head->object.sha1, sha1);
1622 print_summary(prefix, sha1, !current_head);