@matheusbsbs / matheus-bagliano / commits / d71b8ba7c9
Fork 0

commit: --fixup option for use with rebase --autosquash

This option makes it convenient to construct commit messages for use with 'rebase --autosquash'. The resulting commit message will be "fixup! ..." where "..." is the subject line of the specified commit message. Example usage: $ git commit --fixup HEAD~2 Signed-off-by: Pat Notz <patnotz@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pat Notz committed Nov 2, 2010 at 13:59 UTC d71b8ba7c959e414d36974af890e3e2cbd2acbb9
2 files changed +28 -8
Documentation/git-commit.txt
+10 -4
@@ -9,10 +9,10 @@ SYNOPSIS
9 --------
10 [verse]
11 'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
12 - [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
13 - [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
14 - [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
15 - [[-i | -o ]<file>...]
12 + [(-c | -C | --fixup) <commit>] [-F <file> | -m <msg>]
13 + [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]
14 + [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]
15 + [--status | --no-status] [--] [[-i | -o ]<file>...]
16
17 DESCRIPTION
18 -----------
@@ -70,6 +70,12 @@ OPTIONS
70 Like '-C', but with '-c' the editor is invoked, so that
71 the user can further edit the commit message.
72
73 +--fixup=<commit>::
74 + Construct a commit message for use with `rebase --autosquash`.
75 + The commit message will be the subject line from the specified
76 + commit with a prefix of "fixup! ". See linkgit:git-rebase[1]
77 + for details.
78 +
79 --reset-author::
80 When used with -C/-c/--amend options, declare that the
81 authorship of the resulting commit now belongs of the committer.
builtin/commit.c
+18 -4
@@ -69,6 +69,7 @@ static enum {
69 static const char *logfile, *force_author;
70 static const char *template_file;
71 static char *edit_message, *use_message;
72 +static char *fixup_message;
73 static char *author_name, *author_email, *author_date;
74 static int all, edit_flag, also, interactive, only, amend, signoff;
75 static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
@@ -124,6 +125,7 @@ static struct option builtin_commit_options[] = {
125 OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
126 OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
127 OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
128 + OPT_STRING(0, "fixup", &fixup_message, "COMMIT", "use autosquash formatted message to fixup specified commit"),
129 OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C-c/--amend)"),
130 OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
131 OPT_FILENAME('t', "template", &template_file, "use specified template file"),
@@ -586,6 +588,16 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
588 strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
589 hook_arg1 = "commit";
590 hook_arg2 = use_message;
591 + } else if (fixup_message) {
592 + struct pretty_print_context ctx = {0};
593 + struct commit *commit;
594 + commit = lookup_commit_reference_by_name(fixup_message);
595 + if (!commit)
596 + die("could not lookup commit %s", fixup_message);
597 + ctx.output_encoding = get_commit_output_encoding();
598 + format_commit_message(commit, "fixup! %s\n\n",
599 + &sb, &ctx);
600 + hook_arg1 = "message";
601 } else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
602 if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
603 die_errno("could not read MERGE_MSG");
@@ -863,7 +875,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
875 if (force_author && renew_authorship)
876 die("Using both --reset-author and --author does not make sense");
877
866 - if (logfile || message.len || use_message)
878 + if (logfile || message.len || use_message || fixup_message)
879 use_editor = 0;
880 if (edit_flag)
881 use_editor = 1;
@@ -883,15 +895,17 @@ static int parse_and_validate_options(int argc, const char *argv[],
895 f++;
896 if (edit_message)
897 f++;
898 + if (fixup_message)
899 + f++;
900 if (logfile)
901 f++;
902 if (f > 1)
889 - die("Only one of -c/-C/-F can be used.");
903 + die("Only one of -c/-C/-F/--fixup can be used.");
904 if (message.len && f > 0)
891 - die("Option -m cannot be combined with -c/-C/-F.");
905 + die("Option -m cannot be combined with -c/-C/-F/--fixup.");
906 if (edit_message)
907 use_message = edit_message;
894 - if (amend && !use_message)
908 + if (amend && !use_message && !fixup_message)
909 use_message = "HEAD";
910 if (!use_message && renew_authorship)
911 die("--reset-author can be used only with -C, -c or --amend.");