2007-07-23 06:17:42 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Steven Grimm
|
|
|
|
#
|
|
|
|
|
2008-09-03 10:59:33 +02:00
|
|
|
test_description='git commit
|
2007-07-23 06:17:42 +02:00
|
|
|
|
2018-10-23 05:53:40 +02:00
|
|
|
Tests for template, signoff, squash and -F functions.'
|
2007-07-23 06:17:42 +02:00
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2021-03-15 08:54:34 +01:00
|
|
|
. "$TEST_DIRECTORY"/lib-rebase.sh
|
|
|
|
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is () {
|
2011-02-19 19:29:09 +01:00
|
|
|
expect=commit_msg_is.expect
|
|
|
|
actual=commit_msg_is.actual
|
|
|
|
|
2013-07-01 18:20:36 +02:00
|
|
|
printf "%s" "$(git log --pretty=format:%s%b -1)" >"$actual" &&
|
|
|
|
printf "%s" "$1" >"$expect" &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp "$expect" "$actual"
|
2007-07-23 06:17:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# A sanity check to see if commit is working at all.
|
|
|
|
test_expect_success 'a basic commit in an empty tree should succeed' '
|
|
|
|
echo content > foo &&
|
|
|
|
git add foo &&
|
|
|
|
git commit -m "initial commit"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'nonexistent template file should return error' '
|
|
|
|
echo changes >> foo &&
|
|
|
|
git add foo &&
|
2011-02-25 10:07:57 +01:00
|
|
|
(
|
|
|
|
GIT_EDITOR="echo hello >\"\$1\"" &&
|
|
|
|
export GIT_EDITOR &&
|
|
|
|
test_must_fail git commit --template "$PWD"/notexist
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'nonexistent template file in config should return error' '
|
2013-03-24 22:06:09 +01:00
|
|
|
test_config commit.template "$PWD"/notexist &&
|
2011-02-25 10:07:57 +01:00
|
|
|
(
|
|
|
|
GIT_EDITOR="echo hello >\"\$1\"" &&
|
|
|
|
export GIT_EDITOR &&
|
|
|
|
test_must_fail git commit
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
# From now on we'll use a template file that exists.
|
|
|
|
TEMPLATE="$PWD"/template
|
|
|
|
|
|
|
|
test_expect_success 'unedited template should not commit' '
|
|
|
|
echo "template line" > "$TEMPLATE" &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'unedited template with comments should not commit' '
|
|
|
|
echo "# comment in template" >> "$TEMPLATE" &&
|
2008-07-12 17:47:52 +02:00
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'a Signed-off-by line by itself should not commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-signed-off &&
|
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'adding comments to a template should not commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-comments &&
|
|
|
|
test_must_fail git commit --template "$TEMPLATE"
|
|
|
|
)
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
2011-04-13 01:48:35 +02:00
|
|
|
test_expect_success 'adding real content to a template should commit' '
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit --template "$TEMPLATE"
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is "template linecommit message"
|
|
|
|
'
|
|
|
|
|
2011-04-13 01:48:35 +02:00
|
|
|
test_expect_success '-t option should be short for --template' '
|
2007-07-23 06:17:42 +02:00
|
|
|
echo "short template" > "$TEMPLATE" &&
|
|
|
|
echo "new content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit -t "$TEMPLATE"
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is "short templatecommit message"
|
|
|
|
'
|
|
|
|
|
2011-04-13 01:48:35 +02:00
|
|
|
test_expect_success 'config-specified template should commit' '
|
2007-07-23 06:17:42 +02:00
|
|
|
echo "new template" > "$TEMPLATE" &&
|
2013-03-24 22:06:09 +01:00
|
|
|
test_config commit.template "$TEMPLATE" &&
|
2007-07-23 06:17:42 +02:00
|
|
|
echo "more content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit
|
|
|
|
) &&
|
2007-07-23 06:17:42 +02:00
|
|
|
commit_msg_is "new templatecommit message"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'explicit commit message should override template' '
|
|
|
|
echo "still more content" >> foo &&
|
|
|
|
git add foo &&
|
2008-08-08 11:26:28 +02:00
|
|
|
GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-content git commit --template "$TEMPLATE" \
|
2007-07-23 06:17:42 +02:00
|
|
|
-m "command line msg" &&
|
2007-09-25 16:38:46 +02:00
|
|
|
commit_msg_is "command line msg"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit message from file should override template' '
|
|
|
|
echo "content galore" >> foo &&
|
|
|
|
git add foo &&
|
|
|
|
echo "standard input msg" |
|
2008-08-08 11:26:28 +02:00
|
|
|
(
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit --template "$TEMPLATE" --file -
|
|
|
|
) &&
|
2007-09-25 16:38:46 +02:00
|
|
|
commit_msg_is "standard input msg"
|
2007-07-23 06:17:42 +02:00
|
|
|
'
|
|
|
|
|
2011-05-08 12:31:02 +02:00
|
|
|
cat >"$TEMPLATE" <<\EOF
|
|
|
|
|
|
|
|
|
|
|
|
### template
|
|
|
|
|
|
|
|
EOF
|
|
|
|
test_expect_success 'commit message from template with whitespace issue' '
|
|
|
|
echo "content galore" >>foo &&
|
|
|
|
git add foo &&
|
2018-01-03 17:54:50 +01:00
|
|
|
GIT_EDITOR=\""$TEST_DIRECTORY"\"/t7500/add-whitespaced-content \
|
|
|
|
git commit --template "$TEMPLATE" &&
|
2011-05-08 12:31:02 +02:00
|
|
|
commit_msg_is "commit message"
|
|
|
|
'
|
|
|
|
|
2007-11-11 13:28:08 +01:00
|
|
|
test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
|
|
|
|
|
|
|
|
cp .git/index saved-index &&
|
|
|
|
(
|
|
|
|
echo some new content >file &&
|
|
|
|
GIT_INDEX_FILE=.git/another_index &&
|
|
|
|
export GIT_INDEX_FILE &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m "commit using another index" &&
|
|
|
|
git diff-index --exit-code HEAD &&
|
|
|
|
git diff-files --exit-code
|
|
|
|
) &&
|
|
|
|
cmp .git/index saved-index >/dev/null
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using alternate GIT_INDEX_FILE (2)' '
|
|
|
|
|
|
|
|
cp .git/index saved-index &&
|
|
|
|
(
|
|
|
|
rm -f .git/no-such-index &&
|
|
|
|
GIT_INDEX_FILE=.git/no-such-index &&
|
|
|
|
export GIT_INDEX_FILE &&
|
|
|
|
git commit -m "commit using nonexistent index" &&
|
|
|
|
test -z "$(git ls-files)" &&
|
|
|
|
test -z "$(git ls-tree HEAD)"
|
|
|
|
|
|
|
|
) &&
|
|
|
|
cmp .git/index saved-index >/dev/null
|
2007-11-11 18:35:58 +01:00
|
|
|
'
|
2007-11-11 13:28:08 +01:00
|
|
|
|
2007-11-11 18:35:58 +01:00
|
|
|
cat > expect << EOF
|
|
|
|
zort
|
2007-11-11 18:36:27 +01:00
|
|
|
|
2007-11-11 18:35:58 +01:00
|
|
|
Signed-off-by: C O Mitter <committer@example.com>
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success '--signoff' '
|
|
|
|
echo "yet another content *narf*" >> foo &&
|
2009-01-09 18:30:05 +01:00
|
|
|
echo "zort" | git commit -s -F - foo &&
|
2010-01-27 00:08:31 +01:00
|
|
|
git cat-file commit HEAD | sed "1,/^\$/d" > output &&
|
2008-08-08 11:26:28 +02:00
|
|
|
test_cmp expect output
|
2007-11-11 13:28:08 +01:00
|
|
|
'
|
|
|
|
|
2008-08-06 20:43:47 +02:00
|
|
|
test_expect_success 'commit message from file (1)' '
|
|
|
|
mkdir subdir &&
|
|
|
|
echo "Log in top directory" >log &&
|
|
|
|
echo "Log in sub directory" >subdir/log &&
|
|
|
|
(
|
|
|
|
cd subdir &&
|
|
|
|
git commit --allow-empty -F log
|
|
|
|
) &&
|
|
|
|
commit_msg_is "Log in sub directory"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit message from file (2)' '
|
|
|
|
rm -f log &&
|
|
|
|
echo "Log in sub directory" >subdir/log &&
|
|
|
|
(
|
|
|
|
cd subdir &&
|
|
|
|
git commit --allow-empty -F log
|
|
|
|
) &&
|
|
|
|
commit_msg_is "Log in sub directory"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit message from stdin' '
|
|
|
|
(
|
|
|
|
cd subdir &&
|
|
|
|
echo "Log with foo word" | git commit --allow-empty -F -
|
|
|
|
) &&
|
|
|
|
commit_msg_is "Log with foo word"
|
|
|
|
'
|
|
|
|
|
2009-05-23 20:53:10 +02:00
|
|
|
test_expect_success 'commit -F overrides -t' '
|
|
|
|
(
|
|
|
|
cd subdir &&
|
|
|
|
echo "-F log" > f.log &&
|
|
|
|
echo "-t template" > t.template &&
|
|
|
|
git commit --allow-empty -F f.log -t t.template
|
|
|
|
) &&
|
|
|
|
commit_msg_is "-F log"
|
|
|
|
'
|
|
|
|
|
2010-04-06 10:40:35 +02:00
|
|
|
test_expect_success 'Commit without message is allowed with --allow-empty-message' '
|
|
|
|
echo "more content" >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
>empty &&
|
|
|
|
git commit --allow-empty-message <empty &&
|
commit: do not complain of empty messages from -C
When we pick another commit's message, we die() immediately
if we find that it's empty and we are not going to run an
editor (i.e., when running "-C" instead of "-c"). However,
this check is redundant and harmful.
It's redundant because we will already notice the empty
message later, after we would have run the editor, and die
there (just as we would for a regular, not "-C" case, where
the user provided an empty message in the editor).
It's harmful for a few reasons:
1. It does not respect --allow-empty-message. As a result,
a "git rebase -i" cannot "pick" such a commit. So you
cannot even go back in time to fix it with a "reword"
or "edit" instruction.
2. It does not take into account other ways besides the
editor to modify the message. For example, "git commit
-C empty-commit -m foo" could take the author
information from empty-commit, but add a message to it.
There's more to do to make that work correctly (and
right now we explicitly forbid "-C with -m"), but this
removes one roadblock.
3. The existing check is not enough to prevent segfaults.
We try to find the "\n\n" header/body boundary in the
commit. If it is at the end of the string (i.e., no
body), _or_ if we cannot find it at all (i.e., a
truncated commit object), we consider the message
empty. With "-C", that's OK; we die in either case. But
with "-c", we continue on, and in the case of a
truncated commit may end up dereferencing NULL+2.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-04-26 01:11:15 +02:00
|
|
|
commit_msg_is "" &&
|
|
|
|
git tag empty-message-commit
|
2010-04-06 10:40:35 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Commit without message is no-no without --allow-empty-message' '
|
|
|
|
echo "more content" >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
>empty &&
|
|
|
|
test_must_fail git commit <empty
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Commit a message with --allow-empty-message' '
|
|
|
|
echo "even more content" >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
git commit --allow-empty-message -m"hello there" &&
|
|
|
|
commit_msg_is "hello there"
|
|
|
|
'
|
|
|
|
|
commit: do not complain of empty messages from -C
When we pick another commit's message, we die() immediately
if we find that it's empty and we are not going to run an
editor (i.e., when running "-C" instead of "-c"). However,
this check is redundant and harmful.
It's redundant because we will already notice the empty
message later, after we would have run the editor, and die
there (just as we would for a regular, not "-C" case, where
the user provided an empty message in the editor).
It's harmful for a few reasons:
1. It does not respect --allow-empty-message. As a result,
a "git rebase -i" cannot "pick" such a commit. So you
cannot even go back in time to fix it with a "reword"
or "edit" instruction.
2. It does not take into account other ways besides the
editor to modify the message. For example, "git commit
-C empty-commit -m foo" could take the author
information from empty-commit, but add a message to it.
There's more to do to make that work correctly (and
right now we explicitly forbid "-C with -m"), but this
removes one roadblock.
3. The existing check is not enough to prevent segfaults.
We try to find the "\n\n" header/body boundary in the
commit. If it is at the end of the string (i.e., no
body), _or_ if we cannot find it at all (i.e., a
truncated commit object), we consider the message
empty. With "-C", that's OK; we die in either case. But
with "-c", we continue on, and in the case of a
truncated commit may end up dereferencing NULL+2.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-04-26 01:11:15 +02:00
|
|
|
test_expect_success 'commit -C empty respects --allow-empty-message' '
|
|
|
|
echo more >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
test_must_fail git commit -C empty-message-commit &&
|
|
|
|
git commit -C empty-message-commit --allow-empty-message &&
|
|
|
|
commit_msg_is ""
|
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:10 +01:00
|
|
|
commit_for_rebase_autosquash_setup () {
|
|
|
|
echo "first content line" >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
cat >log <<EOF &&
|
|
|
|
target message subject line
|
|
|
|
|
|
|
|
target message body line 1
|
|
|
|
target message body line 2
|
|
|
|
EOF
|
|
|
|
git commit -F log &&
|
|
|
|
echo "second content line" >>foo &&
|
|
|
|
git add foo &&
|
|
|
|
git commit -m "intermediate commit" &&
|
|
|
|
echo "third content line" >>foo &&
|
|
|
|
git add foo
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'commit --fixup provides correct one-line commit message' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
2021-08-14 23:40:30 +02:00
|
|
|
EDITOR="echo ignored >>" git commit --fixup HEAD~1 &&
|
2010-11-02 20:59:10 +01:00
|
|
|
commit_msg_is "fixup! target message subject line"
|
|
|
|
'
|
|
|
|
|
commit: add support for --fixup <commit> -m"<extra message>"
Add support for supplying the -m option with --fixup. Doing so has
errored out ever since --fixup was introduced. Before this, the only
way to amend the fixup message while committing was to use --edit and
amend it in the editor.
The use-case for this feature is one of:
* Leaving a quick note to self when creating a --fixup commit when
it's not self-evident why the commit should be squashed without a
note into another one.
* (Ab)using the --fixup feature to "fix up" commits that have already
been pushed to a branch that doesn't allow non-fast-forwards,
i.e. just noting "this should have been part of that other commit",
and if the history ever got rewritten in the future the two should
be combined.
In such a case you might want to leave a small message,
e.g. "forgot this part, which broke XYZ".
With this, --fixup <commit> -m"More" -m"Details" will result in a
commit message like:
!fixup <subject of <commit>>
More
Details
The reason the test being added here seems to squash "More" at the end
of the subject line of the commit being fixed up is because the test
code is using "%s%b" so the body immediately follows the subject, it's
not a bug in this code, and other tests t7500-commit.sh do the same
thing.
When the --fixup option was initially added the "Option -m cannot be
combined" error was expanded from -c, -C and -F to also include
--fixup[1]
Those options could also support combining with -m, but given what
they do I can't think of a good use-case for doing that, so I have not
made the more invasive change of splitting up the logic in commit.c to
first act on those, and then on -m options.
1. d71b8ba7c9 ("commit: --fixup option for use with rebase
--autosquash", 2010-11-02)
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-12-22 21:41:52 +01:00
|
|
|
test_expect_success 'commit --fixup -m"something" -m"extra"' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
git commit --fixup HEAD~1 -m"something" -m"extra" &&
|
|
|
|
commit_msg_is "fixup! target message subject linesomething
|
|
|
|
|
|
|
|
extra"
|
|
|
|
'
|
2021-08-14 23:40:30 +02:00
|
|
|
test_expect_success 'commit --fixup --edit' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
EDITOR="printf \"something\nextra\" >>" git commit --fixup HEAD~1 --edit &&
|
|
|
|
commit_msg_is "fixup! target message subject linesomething
|
|
|
|
extra"
|
|
|
|
'
|
|
|
|
|
2021-03-15 08:54:34 +01:00
|
|
|
get_commit_msg () {
|
|
|
|
rev="$1" &&
|
|
|
|
git log -1 --pretty=format:"%B" "$rev"
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'commit --fixup=amend: creates amend! commit' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
amend! $(git log -1 --format=%s HEAD~)
|
|
|
|
|
|
|
|
$(get_commit_msg HEAD~)
|
|
|
|
|
|
|
|
edited
|
|
|
|
EOF
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_COMMIT_AMEND="edited" \
|
|
|
|
git commit --fixup=amend:HEAD~
|
|
|
|
) &&
|
|
|
|
get_commit_msg HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--fixup=amend: --only ignores staged changes' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
amend! $(git log -1 --format=%s HEAD~)
|
|
|
|
|
|
|
|
$(get_commit_msg HEAD~)
|
|
|
|
|
|
|
|
edited
|
|
|
|
EOF
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_COMMIT_AMEND="edited" \
|
|
|
|
git commit --fixup=amend:HEAD~ --only
|
|
|
|
) &&
|
|
|
|
get_commit_msg HEAD >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} &&
|
|
|
|
test_cmp_rev HEAD@{1} HEAD^ &&
|
|
|
|
test_expect_code 1 git diff --cached --exit-code &&
|
|
|
|
git cat-file blob :foo >actual &&
|
|
|
|
test_cmp foo actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--fixup=reword: ignores staged changes' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
amend! $(git log -1 --format=%s HEAD~)
|
|
|
|
|
|
|
|
$(get_commit_msg HEAD~)
|
|
|
|
|
|
|
|
edited
|
|
|
|
EOF
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_COMMIT_AMEND="edited" \
|
|
|
|
git commit --fixup=reword:HEAD~
|
|
|
|
) &&
|
|
|
|
get_commit_msg HEAD >actual &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
test_cmp_rev HEAD@{1}^{tree} HEAD^{tree} &&
|
|
|
|
test_cmp_rev HEAD@{1} HEAD^ &&
|
|
|
|
test_expect_code 1 git diff --cached --exit-code &&
|
|
|
|
git cat-file blob :foo >actual &&
|
|
|
|
test_cmp foo actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--fixup=reword: error out with -m option' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
2022-01-05 21:02:24 +01:00
|
|
|
echo "fatal: options '\''-m'\'' and '\''--fixup:reword'\'' cannot be used together" >expect &&
|
2021-03-15 08:54:34 +01:00
|
|
|
test_must_fail git commit --fixup=reword:HEAD~ -m "reword commit message" 2>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--fixup=amend: error out with -m option' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
2022-01-05 21:02:24 +01:00
|
|
|
echo "fatal: options '\''-m'\'' and '\''--fixup:amend'\'' cannot be used together" >expect &&
|
2021-03-15 08:54:34 +01:00
|
|
|
test_must_fail git commit --fixup=amend:HEAD~ -m "amend commit message" 2>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'consecutive amend! commits remove amend! line from commit msg body' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
amend! amend! $(git log -1 --format=%s HEAD~)
|
|
|
|
|
|
|
|
$(get_commit_msg HEAD~)
|
|
|
|
|
|
|
|
edited 1
|
|
|
|
|
|
|
|
edited 2
|
|
|
|
EOF
|
|
|
|
echo "reword new commit message" >actual &&
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_COMMIT_AMEND="edited 1" \
|
|
|
|
git commit --fixup=reword:HEAD~ &&
|
|
|
|
FAKE_COMMIT_AMEND="edited 2" \
|
|
|
|
git commit --fixup=reword:HEAD
|
|
|
|
) &&
|
|
|
|
get_commit_msg HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'deny to create amend! commit if its commit msg body is empty' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
echo "Aborting commit due to empty commit message body." >expected &&
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
test_must_fail env FAKE_COMMIT_MESSAGE="amend! target message subject line" \
|
|
|
|
git commit --fixup=amend:HEAD~ 2>actual
|
|
|
|
) &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'amend! commit allows empty commit msg body with --allow-empty-message' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
amend! $(git log -1 --format=%s HEAD~)
|
|
|
|
EOF
|
|
|
|
(
|
|
|
|
set_fake_editor &&
|
|
|
|
FAKE_COMMIT_MESSAGE="amend! target message subject line" \
|
|
|
|
git commit --fixup=amend:HEAD~ --allow-empty-message &&
|
|
|
|
get_commit_msg HEAD >actual
|
|
|
|
) &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_fixup_reword_opt () {
|
2021-05-17 17:12:22 +02:00
|
|
|
test_expect_success "--fixup=reword: incompatible with $1" "
|
2022-01-05 21:02:24 +01:00
|
|
|
echo 'fatal: reword option of '\''--fixup'\'' and' \
|
|
|
|
''\''--patch/--interactive/--all/--include/--only'\' \
|
|
|
|
'cannot be used together' >expect &&
|
2021-03-15 08:54:34 +01:00
|
|
|
test_must_fail git commit --fixup=reword:HEAD~ $1 2>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
for opt in --all --include --only --interactive --patch
|
|
|
|
do
|
|
|
|
test_fixup_reword_opt $opt
|
|
|
|
done
|
|
|
|
|
|
|
|
test_expect_success '--fixup=reword: give error with pathsec' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
2022-01-05 21:02:24 +01:00
|
|
|
echo "fatal: reword option of '\''--fixup'\'' and path '\''foo'\'' cannot be used together" >expect &&
|
2021-03-15 08:54:34 +01:00
|
|
|
test_must_fail git commit --fixup=reword:HEAD~ -- foo 2>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--fixup=reword: -F give error message' '
|
2022-01-31 23:07:46 +01:00
|
|
|
echo "fatal: options '\''-F'\'' and '\''--fixup'\'' cannot be used together" >expect &&
|
2021-03-15 08:54:34 +01:00
|
|
|
test_must_fail git commit --fixup=reword:HEAD~ -F msg 2>actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
commit: add support for --fixup <commit> -m"<extra message>"
Add support for supplying the -m option with --fixup. Doing so has
errored out ever since --fixup was introduced. Before this, the only
way to amend the fixup message while committing was to use --edit and
amend it in the editor.
The use-case for this feature is one of:
* Leaving a quick note to self when creating a --fixup commit when
it's not self-evident why the commit should be squashed without a
note into another one.
* (Ab)using the --fixup feature to "fix up" commits that have already
been pushed to a branch that doesn't allow non-fast-forwards,
i.e. just noting "this should have been part of that other commit",
and if the history ever got rewritten in the future the two should
be combined.
In such a case you might want to leave a small message,
e.g. "forgot this part, which broke XYZ".
With this, --fixup <commit> -m"More" -m"Details" will result in a
commit message like:
!fixup <subject of <commit>>
More
Details
The reason the test being added here seems to squash "More" at the end
of the subject line of the commit being fixed up is because the test
code is using "%s%b" so the body immediately follows the subject, it's
not a bug in this code, and other tests t7500-commit.sh do the same
thing.
When the --fixup option was initially added the "Option -m cannot be
combined" error was expanded from -c, -C and -F to also include
--fixup[1]
Those options could also support combining with -m, but given what
they do I can't think of a good use-case for doing that, so I have not
made the more invasive change of splitting up the logic in commit.c to
first act on those, and then on -m options.
1. d71b8ba7c9 ("commit: --fixup option for use with rebase
--autosquash", 2010-11-02)
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-12-22 21:41:52 +01:00
|
|
|
|
2010-11-02 20:59:12 +01:00
|
|
|
test_expect_success 'commit --squash works with -F' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
echo "log message from file" >msgfile &&
|
|
|
|
git commit --squash HEAD~1 -F msgfile &&
|
|
|
|
commit_msg_is "squash! target message subject linelog message from file"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --squash works with -m' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
git commit --squash HEAD~1 -m "foo bar\nbaz" &&
|
|
|
|
commit_msg_is "squash! target message subject linefoo bar\nbaz"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --squash works with -C' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
git commit --squash HEAD~1 -C HEAD &&
|
|
|
|
commit_msg_is "squash! target message subject lineintermediate commit"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --squash works with -c' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/edit-content &&
|
|
|
|
git commit --squash HEAD~1 -c HEAD &&
|
|
|
|
commit_msg_is "squash! target message subject lineedited commit"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --squash works with -C for same commit' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
git commit --squash HEAD -C HEAD &&
|
|
|
|
commit_msg_is "squash! intermediate commit"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --squash works with -c for same commit' '
|
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/edit-content &&
|
|
|
|
git commit --squash HEAD -c HEAD &&
|
|
|
|
commit_msg_is "squash! edited commit"
|
|
|
|
'
|
|
|
|
|
2011-04-13 01:48:35 +02:00
|
|
|
test_expect_success 'commit --squash works with editor' '
|
2010-11-02 20:59:12 +01:00
|
|
|
commit_for_rebase_autosquash_setup &&
|
|
|
|
test_set_editor "$TEST_DIRECTORY"/t7500/add-content &&
|
|
|
|
git commit --squash HEAD~1 &&
|
|
|
|
commit_msg_is "squash! target message subject linecommit message"
|
|
|
|
'
|
|
|
|
|
2010-11-02 20:59:10 +01:00
|
|
|
test_expect_success 'invalid message options when using --fixup' '
|
|
|
|
echo changes >>foo &&
|
|
|
|
echo "message" >log &&
|
|
|
|
git add foo &&
|
2010-11-02 20:59:12 +01:00
|
|
|
test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 &&
|
2010-11-02 20:59:10 +01:00
|
|
|
test_must_fail git commit --fixup HEAD~1 -C HEAD~2 &&
|
|
|
|
test_must_fail git commit --fixup HEAD~1 -c HEAD~2 &&
|
|
|
|
test_must_fail git commit --fixup HEAD~1 -F log
|
|
|
|
'
|
|
|
|
|
2017-06-30 14:12:21 +02:00
|
|
|
cat >expected-template <<EOF
|
|
|
|
|
|
|
|
# Please enter the commit message for your changes. Lines starting
|
2021-07-09 20:07:32 +02:00
|
|
|
# with '#' will be ignored.
|
2017-06-30 14:12:21 +02:00
|
|
|
#
|
|
|
|
# Author: A U Thor <author@example.com>
|
|
|
|
#
|
|
|
|
# On branch commit-template-check
|
|
|
|
# Changes to be committed:
|
|
|
|
# new file: commit-template-check
|
|
|
|
#
|
|
|
|
# Untracked files not listed
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_expect_success 'new line found before status message in commit template' '
|
|
|
|
git checkout -b commit-template-check &&
|
|
|
|
git reset --hard HEAD &&
|
|
|
|
touch commit-template-check &&
|
|
|
|
git add commit-template-check &&
|
|
|
|
GIT_EDITOR="cat >editor-input" git commit --untracked-files=no --allow-empty-message &&
|
2021-02-11 02:53:53 +01:00
|
|
|
test_cmp expected-template editor-input
|
2017-06-30 14:12:21 +02:00
|
|
|
'
|
|
|
|
|
commit: fix erroneous BUG, 'multiple renames on the same target? how?'
builtin/commit.c:prepare_to_commit() can call run_status() twice if
using the editor, including status, and the user attempts to record a
non-merge empty commit without explicit --allow-empty. If there is also
a rename involved as well (due to using 'git add -N'), then a BUG in
wt-status.c is triggered:
BUG: wt-status.c:476: multiple renames on the same target? how?
The reason we hit this bug is that both run_status() calls use the same
struct wt_status * (named s), and s->change is not freed between runs.
Changes are inserted into s with string_list_insert, which usually means
that the second run just recomputes all the same results and overwrites
what was computed the first time. However, ever since commit
176ea7479309 ("wt-status.c: handle worktree renames", 2017-12-27),
wt-status started checking for renames and copies but also added a
preventative check that d->rename_status wasn't already set and output a
BUG message if it was. The problem isn't that there are multiple rename
targets to a single path as the error implies, the problem is that 's'
is not freed/cleared between the two run_status() calls.
Ever since commit dc6b1d92ca9c ("wt-status: use settings from
git_diff_ui_config", 2018-05-04), which stopped hardcoding
DIFF_DETECT_RENAME and allowed users to ask for copy detection, this bug
has also been triggerable with a copy instead of a rename.
Fix the bug by clearing s->change. A better change might be to clean up
all of s between the two run_status() calls. A good first step towards
such a goal might be writing a function to free the necessary fields in
the wt_status * struct; a cursory glance at the code suggests all of its
allocated data is probably leaked. However, doing all that cleanup is a
bigger task for someone else interested to tackle; just fix the bug for
now.
Reported-by: Andrea Stacchiotti <andreastacchiotti@gmail.com>
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-09-27 19:36:57 +02:00
|
|
|
test_expect_success 'setup empty commit with unstaged rename and copy' '
|
|
|
|
test_create_repo unstaged_rename_and_copy &&
|
|
|
|
(
|
|
|
|
cd unstaged_rename_and_copy &&
|
|
|
|
|
|
|
|
echo content >orig &&
|
|
|
|
git add orig &&
|
|
|
|
test_commit orig &&
|
|
|
|
|
|
|
|
cp orig new_copy &&
|
|
|
|
mv orig new_rename &&
|
|
|
|
git add -N new_copy new_rename
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'check commit with unstaged rename and copy' '
|
|
|
|
(
|
|
|
|
cd unstaged_rename_and_copy &&
|
|
|
|
|
|
|
|
test_must_fail git -c diff.renames=copy commit
|
|
|
|
)
|
|
|
|
'
|
|
|
|
|
2019-12-17 10:17:22 +01:00
|
|
|
test_expect_success 'commit without staging files fails and displays hints' '
|
|
|
|
echo "initial" >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m initial &&
|
|
|
|
echo "changes" >>file &&
|
|
|
|
test_must_fail git commit -m update >actual &&
|
|
|
|
test_i18ngrep "no changes added to commit (use \"git add\" and/or \"git commit -a\")" actual
|
|
|
|
'
|
|
|
|
|
2007-07-23 06:17:42 +02:00
|
|
|
test_done
|