* [PATCH] commit -c/-C/--amend: reset timestamp and authorship to committer with --mine
2009-11-01 23:14 [PATCH] commit -c/-C/--amend: acquire authorship and restamp time with --claim Erick Mattos
@ 2009-11-02 0:44 ` Erick Mattos
0 siblings, 0 replies; 2+ messages in thread
From: Erick Mattos @ 2009-11-02 0:44 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Erick Mattos
When we use one of the options above we are normally trying to do mainly
two things: one is using the source as a template and second is to
recreate a commit with corrections.
When they are used, the authorship and timestamp recorded in the newly
created commit is always taken from the original commit. And they
should not when we are using it as a template.
The new --mine option is meant to solve this need by regenerating the
timestamp and setting as new author the committer or the one specified
on --author option.
Signed-off-by: Erick Mattos <erick.mattos@gmail.com>
---
Documentation/git-commit.txt | 8 +++-
builtin-commit.c | 9 +++-
t/t7509-commit.sh | 98 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 111 insertions(+), 4 deletions(-)
create mode 100755 t/t7509-commit.sh
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 0578a40..eae5bf4 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -9,7 +9,7 @@ SYNOPSIS
--------
[verse]
'git commit' [-a | --interactive] [-s] [-v] [-u<mode>] [--amend] [--dry-run]
- [(-c | -C) <commit>] [-F <file> | -m <msg>]
+ [(-c | -C) <commit>] [-F <file> | -m <msg>] [--mine]
[--allow-empty] [--no-verify] [-e] [--author=<author>]
[--cleanup=<mode>] [--] [[-i | -o ]<file>...]
@@ -69,6 +69,12 @@ OPTIONS
Like '-C', but with '-c' the editor is invoked, so that
the user can further edit the commit message.
+--mine::
+ When used with -C/-c/--amend options, declare that the
+ authorship of the resulting commit now belongs of the committer.
+ This also renews the author timestamp. Therefore this option
+ sets the use of only the message from the original commit.
+
-F <file>::
--file=<file>::
Take the commit message from the given file. Use '-' to
diff --git a/builtin-commit.c b/builtin-commit.c
index c395cbf..17a6794 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -51,7 +51,7 @@ static const char *template_file;
static char *edit_message, *use_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;
+static int quiet, verbose, no_verify, allow_empty, dry_run, mine;
static char *untracked_files_arg;
/*
* The default commit message cleanup mode will remove the lines
@@ -91,8 +91,9 @@ static struct option builtin_commit_options[] = {
OPT_FILENAME('F', "file", &logfile, "read log from file"),
OPT_STRING(0, "author", &force_author, "AUTHOR", "override author for commit"),
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', "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_BOOLEAN(0, "mine", &mine, "reset timestamp and authorship to committer"),
OPT_BOOLEAN('s', "signoff", &signoff, "add Signed-off-by:"),
OPT_FILENAME('t', "template", &template_file, "use specified template file"),
OPT_BOOLEAN('e', "edit", &edit_flag, "force edit of commit"),
@@ -381,7 +382,7 @@ static void determine_author_info(void)
email = getenv("GIT_AUTHOR_EMAIL");
date = getenv("GIT_AUTHOR_DATE");
- if (use_message) {
+ if (use_message && !mine) {
const char *a, *lb, *rb, *eol;
a = strstr(use_message_buffer, "\nauthor ");
@@ -778,6 +779,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
use_message = edit_message;
if (amend && !use_message)
use_message = "HEAD";
+ if (!use_message && mine)
+ die("Option --mine is used only with -C/-c/--amend.");
if (use_message) {
unsigned char sha1[20];
static char utf8[] = "UTF-8";
diff --git a/t/t7509-commit.sh b/t/t7509-commit.sh
new file mode 100755
index 0000000..514de6a
--- /dev/null
+++ b/t/t7509-commit.sh
@@ -0,0 +1,98 @@
+#!/bin/sh
+#
+# Copyright (c) 2009 Erick Mattos
+#
+
+test_description='git commit
+
+Tests for --mine option on a commit.'
+
+. ./test-lib.sh
+
+TEST_FILE=foo
+
+test_expect_success '-C without --mine uses the author from the old commit' '
+ echo "initial" > "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -m "Initial Commit" --author "Frigate <flying@over.world>" &&
+ test_tick &&
+ echo "Test 1" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -C HEAD &&
+ git cat-file -p HEAD^ | sed -e "/^parent/d" -e "/^tree/d" \
+ -e "/^committer/d" > commit_1 &&
+ git cat-file -p HEAD | sed -e "/^parent/d" -e "/^tree/d" \
+ -e "/^committer/d" > commit_2 &&
+ test_cmp commit_1 commit_2
+'
+
+test_expect_success '-C with --mine makes me the author' '
+ test_tick &&
+ echo "Test 2" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -C HEAD^ --mine &&
+ git cat-file -p HEAD^ | grep "^author" > commit_1 &&
+ git cat-file -p HEAD | grep "^author" > commit_2 &&
+ test "$(cat commit_1 | sed "s/.*> //")" !=\
+ "$(cat commit_2 | sed "s/.*> //")" &&
+ test "$(cat commit_2 | sed -e "s/author //" -e "s/>.*/>/")" =\
+ "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
+'
+
+test_expect_success '-c without --mine uses the author from the old commit' '
+ echo "Initial" > "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -m "Initial Commit" --author "Frigate <flying@over.world>" &&
+ test_tick &&
+ echo "Test 3" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -c HEAD <<EOF
+ "Changed"
+ EOF &&
+ git cat-file -p HEAD^ | grep "^author" > commit_1 &&
+ git cat-file -p HEAD | grep "^author" > commit_2 &&
+ test_cmp commit_1 commit_2
+'
+
+test_expect_success '-c with --mine makes me the author' '
+ test_tick &&
+ echo "Test 4" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -c HEAD^ --mine <<EOF
+ "Changed again"
+ EOF &&
+ git cat-file -p HEAD^ | grep "^author" > commit_1 &&
+ git cat-file -p HEAD | grep "^author" > commit_2 &&
+ test "$(cat commit_1 | sed "s/.*> //")" !=\
+ "$(cat commit_2 | sed "s/.*> //")" &&
+ test "$(cat commit_2 | sed -e "s/author //" -e "s/>.*/>/")" =\
+ "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
+'
+
+test_expect_success '--amend without --mine uses the author from the old commit' '
+ echo "Initial" > "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -m "Initial Commit" --author "Frigate <flying@over.world>" &&
+ echo "Test 5" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -m "--amend test" &&
+ git cat-file -p HEAD | grep "^author" > commit_1 &&
+ test_tick &&
+ git commit -m "Changed" --amend &&
+ git cat-file -p HEAD | grep "^author" > commit_2 &&
+ test_cmp commit_1 commit_2
+'
+
+test_expect_success '--amend with --mine makes me the author' '
+ test_tick &&
+ echo "Test 6" >> "$TEST_FILE" &&
+ git add "$TEST_FILE" &&
+ git commit -m "Changed again" --amend --mine &&
+ git cat-file -p HEAD | grep "^author" > commit_1 &&
+ test "$(cat commit_1 | sed "s/.*> //")" !=\
+ "$(cat commit_2 | sed "s/.*> //")" &&
+ test "$(cat commit_2 | sed -e "s/author //" -e "s/>.*/>/")" =\
+ "$GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>"
+'
+
+test_done
--
1.6.5.2.102.gdbd78.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] commit -c/-C/--amend: reset timestamp and authorship to committer with --mine
@ 2009-11-03 18:21 Erick Mattos
0 siblings, 0 replies; 2+ messages in thread
From: Erick Mattos @ 2009-11-03 18:21 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Please don't forget your comments down here wasn't about the last sent
patch. Please see it, in case you don't have it, at:
http://marc.info/?l=git&m=125712272606721&w=2
Anyway I am answering your comments down here:
2009/11/2 Junio C Hamano <gitster@pobox.com>:
> Erick Mattos <erick.mattos@gmail.com> writes:
>
>> 2009/11/1 Junio C Hamano <gitster@pobox.com>:
>>> Erick Mattos <erick.mattos@gmail.com> writes:
>>>
>>>>> % git commit --claim --author='Erick Mattos <eric@mattos>' -C HEAD
>>>>>
>>>>> Should you detect an error? Does your code do so? Do you have a test
>>>>> that catches this error?
>>>>
>>>> It works as intended. Both together.
>>>
>>> That does not make any sense. If you are saying this is yours and it is
>>> his at the same time, there can be no sane way to work "as intended", no?.
>>
>> I am adding a new option not changing the option --author already in
>> git. So it does work together.
>
> Somebody who says "this commit is mine, and its author is this other
> person" is not making any sense. The resulting commit can either have
> that person (i.e. the committer) as the author, which is what the "claim"
> option means, or it can have the person named with --author as the author,
> but both cannot be true at the same time.
>
> When you introduce a new option, sometimes it cannot sanely be used with
> an existing option. In such a case, two options (the new one and the
> existing one) are called mutually exclusive. And you add some code to
> catch an user error to use them together.
As --author text says: "override author for commit".
As I see, something that OVERRIDES supersedes everything else.
IMHO --author shouldn't be blocked by the new option. Probably your
point is about "mine" name.
Cutting --author away would make impossible for someone to force a new
author with a new timestamp in case he is templating. Of course he
can be using the --author because he is doing a change in a computer
not his own or something alike. So I would not wipe "author" out from
the new option.
Please don't forget that I am just being a small contributor. I am
just suggesting things. You have the final word.
>>>>>> + git commit -c HEAD <<EOF
>>>>>> + "Changed"
>>>>>> + EOF &&
>>>>>
>>>>> What editor is reading this "Changed"?
>>>>
>>>> Nobody cares... Just a text to change the file.
>>>
>>> I actually care. Who uses that Changed string, and where does it end up
>>> with? At the end of the log message? At the beginning? What "file"?
>>
>> I didn't get it. -c option does not accept -m option and starts an
>> editor to change the message. The text "Changed is just a forced
>> message. I can not use an editor in interactive mode in a script...
>
> How are the existing tests that try "commit -c" do this? I do not think
> there is any here-text redirect into "git commit".
Sorry, it was automatic for me. Just supposing a here-text... :-)
I am going to fix it.
> It is sometimes easier to show by example than by giving nudging words
> that only show direction, so here is a suggested rewrite on top of your
> patch. I am not very happy with the option name "mine" either, but at
> least I think this gets the semantics right.
We could call it --reset-author. What do you think?
> + if (force_author && renew_authorship)
> + die("Using both --mine and --author does not make sense");
> +
As previously said up there.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-11-03 18:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-11-03 18:21 [PATCH] commit -c/-C/--amend: reset timestamp and authorship to committer with --mine Erick Mattos
-- strict thread matches above, loose matches on Subject: below --
2009-11-01 23:14 [PATCH] commit -c/-C/--amend: acquire authorship and restamp time with --claim Erick Mattos
2009-11-02 0:44 ` [PATCH] commit -c/-C/--amend: reset timestamp and authorship to committer with --mine Erick Mattos
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).