From: "Pat Notz" <patnotz@gmail.com>
To: git@vger.kernel.org
Subject: [PATCHv2 1/4] commit: --fixup option for use with rebase --autosquash
Date: Tue, 21 Sep 2010 14:25:00 -0600 [thread overview]
Message-ID: <1285100703-49087-2-git-send-email-patnotz@gmail.com> (raw)
In-Reply-To: <1284687596-236-1-git-send-email-patnotz@gmail.com>
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>
---
Documentation/git-commit.txt | 13 +++++++++----
builtin/commit.c | 23 +++++++++++++++++++----
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 42fb1f5..3367f8f 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -9,10 +9,10 @@ SYNOPSIS
--------
[verse]
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
- [(-c | -C) <commit>] [-F <file> | -m <msg>] [--reset-author]
- [--allow-empty] [--allow-empty-message] [--no-verify] [-e] [--author=<author>]
- [--date=<date>] [--cleanup=<mode>] [--status | --no-status] [--]
- [[-i | -o ]<file>...]
+ [(-c | -C | --fixup) <commit>] [-F <file> | -m <msg>]
+ [--reset-author] [--allow-empty] [--allow-empty-message] [--no-verify]
+ [-e] [--author=<author>] [--date=<date>] [--cleanup=<mode>]
+ [--status | --no-status] [--] [[-i | -o ]<file>...]
DESCRIPTION
-----------
@@ -70,6 +70,11 @@ OPTIONS
Like '-C', but with '-c' the editor is invoked, so that
the user can further edit the commit message.
+--fixup=<commit>::
+ Construct a commit message for use with `rebase --autosquash`.
+ The commit message will be the subject line from the specified
+ commit with a prefix of "fixup! ".
+
--reset-author::
When used with -C/-c/--amend options, declare that the
authorship of the resulting commit now belongs of the committer.
diff --git a/builtin/commit.c b/builtin/commit.c
index 66fdd22..0901616 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -69,6 +69,7 @@ static enum {
static const char *logfile, *force_author;
static const char *template_file;
static char *edit_message, *use_message;
+static char *fixup_message;
static char *author_name, *author_email, *author_date;
static int all, edit_flag, also, interactive, only, amend, signoff;
static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
@@ -124,6 +125,7 @@ static struct option builtin_commit_options[] = {
OPT_CALLBACK('m', "message", &message, "MESSAGE", "specify commit message", opt_parse_m),
OPT_STRING('c', "reedit-message", &edit_message, "COMMIT", "reuse and edit message from specified commit"),
OPT_STRING('C', "reuse-message", &use_message, "COMMIT", "reuse message from specified commit"),
+ OPT_STRING(0, "fixup", &fixup_message, "COMMIT", "use autosquash formatted message to fixup specified commit"),
OPT_BOOLEAN(0, "reset-author", &renew_authorship, "the commit is authored by me now (used with -C-c/--amend)"),
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
@@ -586,6 +588,17 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
hook_arg1 = "commit";
hook_arg2 = use_message;
+ } else if (fixup_message) {
+ unsigned char sha1[20];
+ struct commit *commit;
+ struct pretty_print_context ctx = {0};
+ if (get_sha1(fixup_message, sha1))
+ die("could not lookup commit %s", fixup_message);
+ commit = lookup_commit_reference(sha1);
+ if (!commit || parse_commit(commit))
+ die("could not parse commit %s", fixup_message);
+ format_commit_message(commit, "fixup! %s\n\n", &sb, &ctx);
+ hook_arg1 = "message";
} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
die_errno("could not read MERGE_MSG");
@@ -863,7 +876,7 @@ static int parse_and_validate_options(int argc, const char *argv[],
if (force_author && renew_authorship)
die("Using both --reset-author and --author does not make sense");
- if (logfile || message.len || use_message)
+ if (logfile || message.len || use_message || fixup_message)
use_editor = 0;
if (edit_flag)
use_editor = 1;
@@ -883,15 +896,17 @@ static int parse_and_validate_options(int argc, const char *argv[],
f++;
if (edit_message)
f++;
+ if (fixup_message)
+ f++;
if (logfile)
f++;
if (f > 1)
- die("Only one of -c/-C/-F can be used.");
+ die("Only one of -c/-C/-F/--fixup can be used.");
if (message.len && f > 0)
- die("Option -m cannot be combined with -c/-C/-F.");
+ die("Option -m cannot be combined with -c/-C/-F/--fixup.");
if (edit_message)
use_message = edit_message;
- if (amend && !use_message)
+ if (amend && !use_message && !fixup_message)
use_message = "HEAD";
if (!use_message && renew_authorship)
die("--reset-author can be used only with -C, -c or --amend.");
--
1.7.3
next prev parent reply other threads:[~2010-09-21 20:25 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-17 1:39 [PATCH 0/2] Add commit message options for rebase --autosquash Pat Notz
2010-09-17 1:39 ` [PATCH 1/2] commit: add " Pat Notz
2010-09-17 8:36 ` Stephen Boyd
2010-09-17 15:34 ` Pat Notz
2010-09-17 16:14 ` Bryan Drewery
2010-09-17 17:07 ` Stephen Boyd
2010-09-17 17:47 ` Bryan Drewery
2010-09-17 18:21 ` Junio C Hamano
2010-09-17 1:39 ` [PATCH 2/2] t7500: add tests of commit --fixup/--squash Pat Notz
2010-09-21 20:24 ` [PATCHv2 0/4] Add commit message options for rebase --autosquash Pat Notz
2010-09-21 20:25 ` Pat Notz [this message]
2010-09-21 20:35 ` [PATCHv2 1/4] commit: --fixup option for use with " Sverre Rabbelier
2010-09-22 18:01 ` Pat Notz
2010-09-21 20:25 ` [PATCHv2 2/4] t7500: add tests of commit --fixup Pat Notz
2010-09-21 20:25 ` [PATCHv2 3/4] commit: --squash option for use with rebase --autosquash Pat Notz
2010-09-22 18:02 ` Pat Notz
2010-09-21 20:25 ` [PATCHv2 4/4] t7500: add tests of commit --squash Pat Notz
2010-09-21 20:36 ` Ævar Arnfjörð Bjarmason
2010-09-22 17:59 ` Pat Notz
2010-09-22 18:12 ` Ævar Arnfjörð Bjarmason
2010-09-22 18:16 ` Pat Notz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1285100703-49087-2-git-send-email-patnotz@gmail.com \
--to=patnotz@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).