* Try to commit without forking 'git commit'. In some cases we need * to run 'git commit' to display an error message * * Returns: * -1 - error unable to commit * 0 - success * 1 - run 'git commit' */
| 1527 | * 1 - run 'git commit' |
| 1528 | */ |
| 1529 | static int try_to_commit(struct repository *r, |
| 1530 | struct strbuf *msg, const char *author, |
| 1531 | const char *reflog_action, |
| 1532 | struct replay_opts *opts, unsigned int flags, |
| 1533 | struct object_id *oid) |
| 1534 | { |
| 1535 | struct object_id tree; |
| 1536 | struct commit *current_head = NULL; |
| 1537 | struct commit_list *parents = NULL; |
| 1538 | struct commit_extra_header *extra = NULL; |
| 1539 | struct strbuf err = STRBUF_INIT; |
| 1540 | struct strbuf commit_msg = STRBUF_INIT; |
| 1541 | char *amend_author = NULL; |
| 1542 | const char *committer = NULL; |
| 1543 | const char *hook_commit = NULL; |
| 1544 | enum commit_msg_cleanup_mode cleanup; |
| 1545 | int res = 0; |
| 1546 | |
| 1547 | if (parse_head(r, ¤t_head)) |
| 1548 | return -1; |
| 1549 | |
| 1550 | if (flags & AMEND_MSG) { |
| 1551 | const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL }; |
| 1552 | const char *out_enc = get_commit_output_encoding(); |
| 1553 | const char *message = repo_logmsg_reencode(r, current_head, |
| 1554 | NULL, out_enc); |
| 1555 | |
| 1556 | if (!msg) { |
| 1557 | const char *orig_message = NULL; |
| 1558 | |
| 1559 | find_commit_subject(message, &orig_message); |
| 1560 | msg = &commit_msg; |
| 1561 | strbuf_addstr(msg, orig_message); |
| 1562 | hook_commit = "HEAD"; |
| 1563 | } |
| 1564 | author = amend_author = get_author(message); |
| 1565 | repo_unuse_commit_buffer(r, current_head, |
| 1566 | message); |
| 1567 | if (!author) { |
| 1568 | res = error(_("unable to parse commit author")); |
| 1569 | goto out; |
| 1570 | } |
| 1571 | parents = commit_list_copy(current_head->parents); |
| 1572 | extra = read_commit_extra_headers(current_head, exclude_gpgsig); |
| 1573 | } else if (current_head && |
| 1574 | (!(flags & CREATE_ROOT_COMMIT) || (flags & AMEND_MSG))) { |
| 1575 | commit_list_insert(current_head, &parents); |
| 1576 | } |
| 1577 | |
| 1578 | if (write_index_as_tree(&tree, r->index, r->index_file, 0, NULL)) { |
| 1579 | res = error(_("git write-tree failed to write a tree")); |
| 1580 | goto out; |
| 1581 | } |
| 1582 | |
| 1583 | if (!(flags & ALLOW_EMPTY)) { |
| 1584 | struct commit *first_parent = current_head; |
| 1585 | |
| 1586 | if (flags & AMEND_MSG) { |
no test coverage detected