2007-07-31 19:37:30 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
|
|
|
|
#
|
|
|
|
|
2024-01-17 16:13:55 +00:00
|
|
|
# FIXME: Test the various index usages, test reflog
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2008-09-03 08:59:33 +00:00
|
|
|
test_description='git commit'
|
2020-11-18 23:44:40 +00:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-18 23:44:19 +00:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2007-07-31 19:37:30 +00:00
|
|
|
. ./test-lib.sh
|
2021-02-12 13:29:40 +00:00
|
|
|
. "$TEST_DIRECTORY/lib-diff.sh"
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
author='The Real Author <someguy@his.email.org>'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_tick
|
2011-02-22 23:42:17 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'initial status' '
|
|
|
|
echo bongo bongo >file &&
|
|
|
|
git add file &&
|
2011-04-13 23:17:29 +00:00
|
|
|
git status >actual &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep "No commits yet" actual
|
2011-04-13 23:17:29 +00:00
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'fail initial amend' '
|
|
|
|
test_must_fail git commit --amend
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'setup: initial commit' '
|
|
|
|
git commit -m initial
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success '-m and -F do not mix' '
|
2012-03-30 18:04:08 +00:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 14:50:23 +00:00
|
|
|
test_must_fail git commit -m foo -m bar -F file
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success '-m and -C do not mix' '
|
2012-03-30 18:04:08 +00:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 14:50:23 +00:00
|
|
|
test_must_fail git commit -C HEAD -m illegal
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'paths and -a do not mix' '
|
|
|
|
echo King of the bongo >file &&
|
|
|
|
test_must_fail git commit -m foo -a file
|
|
|
|
'
|
2007-11-12 15:15:39 +00:00
|
|
|
|
2011-05-07 06:00:00 +00:00
|
|
|
test_expect_success PERL 'can use paths with --interactive' '
|
2011-05-09 23:53:00 +00:00
|
|
|
echo bong-o-bong >file &&
|
|
|
|
# 2: update, 1:st path, that is all, 7: quit
|
2018-07-02 00:23:42 +00:00
|
|
|
test_write_lines 2 1 "" 7 |
|
2011-05-07 06:00:00 +00:00
|
|
|
git commit -m foo --interactive file &&
|
|
|
|
git reset --hard HEAD^
|
2011-05-09 23:53:00 +00:00
|
|
|
'
|
2007-11-12 15:15:39 +00:00
|
|
|
|
2018-04-03 17:57:45 +00:00
|
|
|
test_expect_success 'removed files and relative paths' '
|
|
|
|
test_when_finished "rm -rf foo" &&
|
|
|
|
git init foo &&
|
|
|
|
>foo/foo.txt &&
|
|
|
|
git -C foo add foo.txt &&
|
|
|
|
git -C foo commit -m first &&
|
|
|
|
git -C foo rm foo.txt &&
|
|
|
|
|
|
|
|
mkdir -p foo/bar &&
|
|
|
|
git -C foo/bar commit -m second ../foo.txt
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'using invalid commit with -C' '
|
2013-08-24 04:01:44 +00:00
|
|
|
test_must_fail git commit --allow-empty -C bogus
|
2011-12-07 14:50:23 +00:00
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'nothing to commit' '
|
t7501: fix "empty commit" test with NO_PERL
t7501.9 tries to check that "git commit" will fail when the
index is unchanged. It relies on previous tests not to have
modified the index. When it was originally written, this was
always the case. However, commit c65dc35 (t7501: test the
right kind of breakage, 2012-03-30) changed earlier tests (4
and 5) to leave a modification in the index.
We never noticed, however, because t7501.7, between the two,
clears the index state as a side effect. However, that test
depends on the PERL prerequisite, and so it does not always
run. Therefore if NO_PERL is set, we do not run the
intervening test, the index is left unclean, and t7501.9
fails.
We could fix this by moving t7501.9 up in the script.
However, this patch instead leaves it in place and adds a
"git reset" before the commit. This makes the test more
explicit about its preconditions, and will future-proof it
against any other changes in the test state.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-01-23 19:54:57 +00:00
|
|
|
git reset --hard &&
|
2011-12-07 14:50:23 +00:00
|
|
|
test_must_fail git commit -m initial
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2014-02-21 19:16:54 +00:00
|
|
|
test_expect_success '--dry-run fails with nothing to commit' '
|
|
|
|
test_must_fail git commit -m initial --dry-run
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--short fails with nothing to commit' '
|
|
|
|
test_must_fail git commit -m initial --short
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--porcelain fails with nothing to commit' '
|
|
|
|
test_must_fail git commit -m initial --porcelain
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--long fails with nothing to commit' '
|
|
|
|
test_must_fail git commit -m initial --long
|
|
|
|
'
|
|
|
|
|
t7501: add tests for --include and --only
Add tests for --only (-o) and --include (-i). This include testing
with or without staged changes for both -i and -o. Also to test
for committing untracked files with -i, -o and without -i/-o.
Some tests already exist in t7501 for testing --only, however,
it is only tested in combination with --amend and --allow-empty
and on to-be-born branch. The addition of these tests check, when
the pathspec is provided without using -only, that only the files
matching the pathspec get committed. This behavior is same when
we provide --only and it is checked by the tests.
(as --only is the default mode of operation when pathspec is
provided.)
As for --include, there is no prior test for checking if --include
also commits staged changes, thus add test for that. Along with
the tests also document a potential bug, in which, when provided
with -i and a pathspec that does not match any tracked path,
commit does not fail if there are staged changes. And when there
are no staged changes commit fails. However, no error is returned
to stderr in either of the cases. This is described in the TODO
comment before the relevent testcase.
And also add a test for checking incompatibilty when using -o and
-i together.
Thus, these tests belong in t7501 with other similar existing tests,
as described in the case of --only.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-01-17 16:13:54 +00:00
|
|
|
test_expect_success 'fail to commit untracked file (even with --include/--only)' '
|
|
|
|
echo content >baz &&
|
|
|
|
error="error: pathspec .baz. did not match any file(s) known to git" &&
|
|
|
|
|
|
|
|
test_must_fail git commit -m "baz" baz 2>err &&
|
|
|
|
test_grep -e "$error" err &&
|
|
|
|
|
|
|
|
test_must_fail git commit --only -m "baz" baz 2>err &&
|
|
|
|
test_grep -e "$error" err &&
|
|
|
|
|
|
|
|
# TODO: as for --include, the below command will fail because
|
|
|
|
# nothing is staged. If something was staged, it would not fail
|
|
|
|
# even though the provided pathspec does not match any tracked
|
|
|
|
# path. (However, the untracked paths that match the pathspec are
|
|
|
|
# not committed and only the staged changes get committed.)
|
|
|
|
# In either cases, no error is returned to stderr like in (--only
|
|
|
|
# and without --only/--include) cases. In a similar manner,
|
|
|
|
# "git add -u baz" also does not error out.
|
|
|
|
#
|
|
|
|
# Therefore, the below test is just to document the current behavior
|
|
|
|
# and is not an endorsement to the current behavior, and we may
|
|
|
|
# want to fix this. And when that happens, this test should be
|
|
|
|
# updated accordingly.
|
|
|
|
|
|
|
|
test_must_fail git commit --include -m "baz" baz 2>err &&
|
|
|
|
test_must_be_empty err
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'setup: non-initial commit' '
|
|
|
|
echo bongo bongo bongo >file &&
|
|
|
|
git commit -m next -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2014-02-21 19:16:54 +00:00
|
|
|
test_expect_success '--dry-run with stuff to commit returns ok' '
|
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --dry-run
|
|
|
|
'
|
|
|
|
|
2018-09-06 00:53:29 +00:00
|
|
|
test_expect_success '--short with stuff to commit returns ok' '
|
2014-02-21 19:16:54 +00:00
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --short
|
|
|
|
'
|
|
|
|
|
2018-09-06 00:53:29 +00:00
|
|
|
test_expect_success '--porcelain with stuff to commit returns ok' '
|
2014-02-21 19:16:54 +00:00
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --porcelain
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--long with stuff to commit returns ok' '
|
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --long
|
|
|
|
'
|
|
|
|
|
t7501: add tests for --include and --only
Add tests for --only (-o) and --include (-i). This include testing
with or without staged changes for both -i and -o. Also to test
for committing untracked files with -i, -o and without -i/-o.
Some tests already exist in t7501 for testing --only, however,
it is only tested in combination with --amend and --allow-empty
and on to-be-born branch. The addition of these tests check, when
the pathspec is provided without using -only, that only the files
matching the pathspec get committed. This behavior is same when
we provide --only and it is checked by the tests.
(as --only is the default mode of operation when pathspec is
provided.)
As for --include, there is no prior test for checking if --include
also commits staged changes, thus add test for that. Along with
the tests also document a potential bug, in which, when provided
with -i and a pathspec that does not match any tracked path,
commit does not fail if there are staged changes. And when there
are no staged changes commit fails. However, no error is returned
to stderr in either of the cases. This is described in the TODO
comment before the relevent testcase.
And also add a test for checking incompatibilty when using -o and
-i together.
Thus, these tests belong in t7501 with other similar existing tests,
as described in the case of --only.
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Christian Couder <christian.couder@gmail.com>
Signed-off-by: Ghanshyam Thakkar <shyamthakkar001@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2024-01-17 16:13:54 +00:00
|
|
|
for opt in "" "-o" "--only"
|
|
|
|
do
|
|
|
|
test_expect_success 'exclude additional staged changes when given pathspec' '
|
|
|
|
echo content >>file &&
|
|
|
|
echo content >>baz &&
|
|
|
|
git add baz &&
|
|
|
|
git commit $opt -m "file" file &&
|
|
|
|
|
|
|
|
git diff --name-only >actual &&
|
|
|
|
test_must_be_empty actual &&
|
|
|
|
|
|
|
|
test_write_lines baz >expect &&
|
|
|
|
git diff --name-only --cached >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
test_write_lines file >expect &&
|
|
|
|
git diff --name-only HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
|
|
|
test_expect_success '-i/--include includes staged changes' '
|
|
|
|
echo content >>file &&
|
|
|
|
echo content >>baz &&
|
|
|
|
git add file &&
|
|
|
|
|
|
|
|
# baz is in the index, therefore, it will be committed
|
|
|
|
git commit --include -m "file and baz" baz &&
|
|
|
|
|
|
|
|
git diff --name-only HEAD >remaining &&
|
|
|
|
test_must_be_empty remaining &&
|
|
|
|
|
|
|
|
test_write_lines baz file >expect &&
|
|
|
|
git diff --name-only HEAD^ HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--include and --only do not mix' '
|
|
|
|
test_when_finished "git reset --hard" &&
|
|
|
|
echo content >>file &&
|
|
|
|
echo content >>baz &&
|
|
|
|
test_must_fail git commit --include --only -m "file baz" file baz 2>actual &&
|
|
|
|
test_grep -e "fatal: options .-i/--include. and .-o/--only. cannot be used together" actual
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'commit message from non-existing file' '
|
|
|
|
echo more bongo: bongo bongo bongo bongo >file &&
|
|
|
|
test_must_fail git commit -F gah -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'empty commit message' '
|
|
|
|
# Empty except stray tabs and spaces on a few lines.
|
|
|
|
sed -e "s/@//g" >msg <<-\EOF &&
|
|
|
|
@ @
|
|
|
|
@@
|
|
|
|
@ @
|
|
|
|
@Signed-off-by: hula@
|
|
|
|
EOF
|
|
|
|
test_must_fail git commit -F msg -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2012-03-30 18:30:59 +00:00
|
|
|
test_expect_success 'template "emptyness" check does not kick in with -F' '
|
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
|
|
|
git commit -t file -F file
|
|
|
|
'
|
|
|
|
|
2012-03-30 19:14:33 +00:00
|
|
|
test_expect_success 'template "emptyness" check' '
|
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
|
|
|
test_must_fail git commit -t file 2>err &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep "did not edit" err
|
2012-03-30 19:14:33 +00:00
|
|
|
'
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'setup: commit message from file' '
|
2012-03-30 18:30:59 +00:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 14:50:23 +00:00
|
|
|
echo this is the commit message, coming from a file >msg &&
|
|
|
|
git commit -F msg -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'amend commit' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
2019-11-27 19:53:40 +00:00
|
|
|
sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
|
2011-12-07 14:50:23 +00:00
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor &&
|
|
|
|
EDITOR=./editor git commit --amend
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
commit: fix "--amend --only" with no pathspec
When we do not have any pathspec, we typically disallow an
explicit "--only", because it makes no sense (your commit
would, by definition, be empty). But since 6a74642
(git-commit --amend: two fixes., 2006-04-20), we have
allowed "--amend --only" with the intent that it would amend
the commit, ignoring any contents staged in the index.
However, while that commit allowed the combination, we never
actually implemented the logic to make it work. The current
code notices that we have no pathspec and assumes we want to
do an as-is commit (i.e., the "--only" is ignored).
Instead, we must make sure to follow the partial-commit
code-path. We also need to tweak the list_paths function to
handle a NULL pathspec.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-10 20:40:29 +00:00
|
|
|
test_expect_success 'amend --only ignores staged contents' '
|
|
|
|
cp file file.expect &&
|
|
|
|
echo changed >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit --no-edit --amend --only &&
|
|
|
|
git cat-file blob HEAD:file >file.actual &&
|
|
|
|
test_cmp file.expect file.actual &&
|
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
2016-12-02 22:15:13 +00:00
|
|
|
test_expect_success 'allow-empty --only ignores staged contents' '
|
|
|
|
echo changed-again >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit --allow-empty --only -m "empty" &&
|
|
|
|
git cat-file blob HEAD:file >file.actual &&
|
|
|
|
test_cmp file.expect file.actual &&
|
commit: fix "--amend --only" with no pathspec
When we do not have any pathspec, we typically disallow an
explicit "--only", because it makes no sense (your commit
would, by definition, be empty). But since 6a74642
(git-commit --amend: two fixes., 2006-04-20), we have
allowed "--amend --only" with the intent that it would amend
the commit, ignoring any contents staged in the index.
However, while that commit allowed the combination, we never
actually implemented the logic to make it work. The current
code notices that we have no pathspec and assumes we want to
do an as-is commit (i.e., the "--only" is ignored).
Instead, we must make sure to follow the partial-commit
code-path. We also need to tweak the list_paths function to
handle a NULL pathspec.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-07-10 20:40:29 +00:00
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:54:14 +00:00
|
|
|
test_expect_success 'set up editor' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
sed -e "s/unamended/amended/g" <"$1" >"$1-"
|
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'amend without launching editor' '
|
|
|
|
echo unamended >expect &&
|
|
|
|
git commit --allow-empty -m "unamended" &&
|
|
|
|
echo needs more bongo >file &&
|
|
|
|
git add file &&
|
|
|
|
EDITOR=./editor git commit --no-edit --amend &&
|
|
|
|
git diff --exit-code HEAD -- file &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--amend --edit' '
|
|
|
|
echo amended >expect &&
|
|
|
|
git commit --allow-empty -m "unamended" &&
|
|
|
|
echo bongo again >file &&
|
|
|
|
git add file &&
|
|
|
|
EDITOR=./editor git commit --edit --amend &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
2012-07-09 18:53:26 +00:00
|
|
|
test_expect_success '--amend --edit of empty message' '
|
|
|
|
cat >replace <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
echo "amended" >"$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 replace &&
|
|
|
|
git commit --allow-empty --allow-empty-message -m "" &&
|
|
|
|
echo more bongo >file &&
|
|
|
|
git add file &&
|
|
|
|
EDITOR=./replace git commit --edit --amend &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
./replace expect &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
commit: do not ignore an empty message given by -m ''
When f9568530 (builtin-commit: resurrect behavior for multiple -m
options, 2007-11-11) converted a "char *message" to "struct strbuf
message" to hold the messages given with the "-m" option, it
incorrectly changed the checks "did we get a message with the -m
option?" to "is message.len 0?". Later, we noticed one breakage
from this change and corrected it with 25206778 (commit: don't start
editor if empty message is given with -m, 2013-05-25).
However, "we got a message with -m, even though an empty one, so we
shouldn't be launching an editor" was not the only breakage.
* "git commit --amend -m '' --allow-empty", even though it looks
strange, is a valid request to amend the commit to have no
message at all. Due to the misdetection of the presence of -m on
the command line, we ended up keeping the log messsage from the
original commit.
* "git commit -m "$msg" -F file" should be rejected whether $msg is
an empty string or not, but due to the same bug, was not rejected
when $msg is empty.
* "git -c template=file -m "$msg"" should ignore the template even
when $msg is empty, but it didn't and instead used the contents
from the template file.
Correct these by checking have_option_m, which the earlier 25206778
introduced to fix the same bug.
Reported-by: Adam Dinwoodie <adam@dinwoodie.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-07 19:56:26 +00:00
|
|
|
test_expect_success '--amend to set message to empty' '
|
|
|
|
echo bata >file &&
|
2016-04-06 17:15:03 +00:00
|
|
|
git add file &&
|
|
|
|
git commit -m "unamended" &&
|
|
|
|
git commit --amend --allow-empty-message -m "" &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
echo "" >expect &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
commit: do not ignore an empty message given by -m ''
When f9568530 (builtin-commit: resurrect behavior for multiple -m
options, 2007-11-11) converted a "char *message" to "struct strbuf
message" to hold the messages given with the "-m" option, it
incorrectly changed the checks "did we get a message with the -m
option?" to "is message.len 0?". Later, we noticed one breakage
from this change and corrected it with 25206778 (commit: don't start
editor if empty message is given with -m, 2013-05-25).
However, "we got a message with -m, even though an empty one, so we
shouldn't be launching an editor" was not the only breakage.
* "git commit --amend -m '' --allow-empty", even though it looks
strange, is a valid request to amend the commit to have no
message at all. Due to the misdetection of the presence of -m on
the command line, we ended up keeping the log messsage from the
original commit.
* "git commit -m "$msg" -F file" should be rejected whether $msg is
an empty string or not, but due to the same bug, was not rejected
when $msg is empty.
* "git -c template=file -m "$msg"" should ignore the template even
when $msg is empty, but it didn't and instead used the contents
from the template file.
Correct these by checking have_option_m, which the earlier 25206778
introduced to fix the same bug.
Reported-by: Adam Dinwoodie <adam@dinwoodie.org>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-07 19:56:26 +00:00
|
|
|
test_expect_success '--amend to set empty message needs --allow-empty-message' '
|
2016-04-06 17:15:03 +00:00
|
|
|
echo conga >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m "unamended" &&
|
|
|
|
test_must_fail git commit --amend -m "" &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
echo "unamended" >expect &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:54:14 +00:00
|
|
|
test_expect_success '-m --edit' '
|
|
|
|
echo amended >expect &&
|
|
|
|
git commit --allow-empty -m buffer &&
|
|
|
|
echo bongo bongo >file &&
|
|
|
|
git add file &&
|
|
|
|
EDITOR=./editor git commit -m unamended --edit &&
|
|
|
|
git diff-tree -s --format=%s HEAD >msg &&
|
|
|
|
test_cmp expect msg
|
|
|
|
'
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success '-m and -F do not mix' '
|
|
|
|
echo enough with the bongos >file &&
|
|
|
|
test_must_fail git commit -F msg -m amending .
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'using message from other commit' '
|
|
|
|
git commit -C HEAD^ .
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'editing message from other commit' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
2019-11-27 19:53:40 +00:00
|
|
|
sed -e "s/amend/older/g" <"$1" >"$1-"
|
2011-12-07 14:50:23 +00:00
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor &&
|
|
|
|
echo hula hula >file &&
|
|
|
|
EDITOR=./editor git commit -c HEAD^ -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'message from stdin' '
|
|
|
|
echo silly new contents >file &&
|
|
|
|
echo commit message from stdin |
|
|
|
|
git commit -F - -a
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'overriding author from command line' '
|
|
|
|
echo gak >file &&
|
|
|
|
git commit -m author \
|
|
|
|
--author "Rubber Duck <rduck@convoy.org>" -a >output 2>&1 &&
|
|
|
|
grep Rubber.Duck output
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success PERL 'interactive add' '
|
2019-11-27 19:53:43 +00:00
|
|
|
echo 7 | test_must_fail git commit --interactive >out &&
|
|
|
|
grep "What now" out
|
2011-12-07 14:50:23 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
|
|
|
|
echo zoo >file &&
|
2011-05-10 19:12:31 +00:00
|
|
|
test_must_fail git diff --exit-code >diff1 &&
|
2018-07-02 00:23:42 +00:00
|
|
|
test_write_lines u "*" q |
|
2011-12-07 14:50:23 +00:00
|
|
|
(
|
|
|
|
EDITOR=: &&
|
|
|
|
export EDITOR &&
|
|
|
|
test_must_fail git commit --interactive
|
|
|
|
) &&
|
2011-05-10 19:12:31 +00:00
|
|
|
git diff >diff2 &&
|
2011-12-07 14:50:23 +00:00
|
|
|
compare_diff_patch diff1 diff2
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
test_expect_success 'editor not invoked if -F is given' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
sed -e s/good/bad/g <"$1" >"$1-"
|
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor &&
|
|
|
|
|
|
|
|
echo A good commit message. >msg &&
|
|
|
|
echo moo >file &&
|
|
|
|
|
|
|
|
EDITOR=./editor git commit -a -F msg &&
|
|
|
|
git show -s --pretty=format:%s >subject &&
|
|
|
|
grep -q good subject &&
|
|
|
|
|
|
|
|
echo quack >file &&
|
|
|
|
echo Another good message. |
|
|
|
|
EDITOR=./editor git commit -a -F - &&
|
|
|
|
git show -s --pretty=format:%s >subject &&
|
|
|
|
grep -q good subject
|
|
|
|
'
|
2007-07-31 19:37:30 +00:00
|
|
|
|
2007-09-14 23:53:58 +00:00
|
|
|
test_expect_success 'partial commit that involves removal (1)' '
|
2007-09-12 23:04:22 +00:00
|
|
|
|
|
|
|
git rm --cached file &&
|
|
|
|
mv file elif &&
|
|
|
|
git add elif &&
|
|
|
|
git commit -m "Partial: add elif" elif &&
|
|
|
|
git diff-tree --name-status HEAD^ HEAD >current &&
|
|
|
|
echo "A elif" >expected &&
|
2008-09-10 17:32:44 +00:00
|
|
|
test_cmp expected current
|
2007-09-12 23:04:22 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-09-14 23:53:58 +00:00
|
|
|
test_expect_success 'partial commit that involves removal (2)' '
|
2007-09-12 23:04:22 +00:00
|
|
|
|
|
|
|
git commit -m "Partial: remove file" file &&
|
|
|
|
git diff-tree --name-status HEAD^ HEAD >current &&
|
|
|
|
echo "D file" >expected &&
|
2008-09-10 17:32:44 +00:00
|
|
|
test_cmp expected current
|
2007-09-12 23:04:22 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-09-14 23:53:58 +00:00
|
|
|
test_expect_success 'partial commit that involves removal (3)' '
|
|
|
|
|
|
|
|
git rm --cached elif &&
|
|
|
|
echo elif >elif &&
|
|
|
|
git commit -m "Partial: modify elif" elif &&
|
|
|
|
git diff-tree --name-status HEAD^ HEAD >current &&
|
|
|
|
echo "M elif" >expected &&
|
2008-09-10 17:32:44 +00:00
|
|
|
test_cmp expected current
|
2007-09-14 23:53:58 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-10 09:49:34 +00:00
|
|
|
test_expect_success 'amend commit to fix author' '
|
|
|
|
|
|
|
|
oldtick=$GIT_AUTHOR_DATE &&
|
|
|
|
test_tick &&
|
|
|
|
git reset --hard &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file -p HEAD >commit &&
|
2007-11-10 09:49:34 +00:00
|
|
|
sed -e "s/author.*/author $author $oldtick/" \
|
2019-11-27 19:53:43 +00:00
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
|
|
|
|
commit >expected &&
|
2007-11-10 09:49:34 +00:00
|
|
|
git commit --amend --author="$author" &&
|
2019-11-27 19:53:40 +00:00
|
|
|
git cat-file -p HEAD >current &&
|
2008-09-10 17:32:44 +00:00
|
|
|
test_cmp expected current
|
2007-11-10 09:49:34 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-12-02 22:16:18 +00:00
|
|
|
test_expect_success 'amend commit to fix date' '
|
|
|
|
|
|
|
|
test_tick &&
|
|
|
|
newtick=$GIT_AUTHOR_DATE &&
|
|
|
|
git reset --hard &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file -p HEAD >commit &&
|
2009-12-02 22:16:18 +00:00
|
|
|
sed -e "s/author.*/author $author $newtick/" \
|
2019-11-27 19:53:43 +00:00
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
|
|
|
|
commit >expected &&
|
2009-12-02 22:16:18 +00:00
|
|
|
git commit --amend --date="$newtick" &&
|
2019-11-27 19:53:40 +00:00
|
|
|
git cat-file -p HEAD >current &&
|
2009-12-02 22:16:18 +00:00
|
|
|
test_cmp expected current
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2024-01-17 16:13:55 +00:00
|
|
|
test_expect_success 'amend commit to add signoff' '
|
|
|
|
|
|
|
|
test_commit "msg" file content &&
|
|
|
|
git commit --amend --signoff &&
|
|
|
|
test_commit_message HEAD <<-EOF
|
|
|
|
msg
|
|
|
|
|
|
|
|
Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'amend does not add signoff if it already exists' '
|
|
|
|
|
|
|
|
test_commit --signoff "tenor" file newcontent &&
|
|
|
|
git commit --amend --signoff &&
|
|
|
|
test_commit_message HEAD <<-EOF
|
|
|
|
tenor
|
|
|
|
|
|
|
|
Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
|
|
|
|
EOF
|
|
|
|
'
|
|
|
|
|
2014-05-02 01:10:01 +00:00
|
|
|
test_expect_success 'commit mentions forced date in output' '
|
|
|
|
git commit --amend --date=2010-01-02T03:04:05 >output &&
|
|
|
|
grep "Date: *Sat Jan 2 03:04:05 2010" output
|
|
|
|
'
|
|
|
|
|
2014-05-02 01:12:42 +00:00
|
|
|
test_expect_success 'commit complains about completely bogus dates' '
|
|
|
|
test_must_fail git commit --amend --date=seventeen
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'commit --date allows approxidate' '
|
|
|
|
git commit --amend \
|
|
|
|
--date="midnight the 12th of october, anno domini 1979" &&
|
|
|
|
echo "Fri Oct 12 00:00:00 1979 +0000" >expect &&
|
|
|
|
git log -1 --format=%ad >actual &&
|
|
|
|
test_cmp expect actual
|
2010-12-13 17:02:25 +00:00
|
|
|
'
|
|
|
|
|
2007-11-10 09:49:34 +00:00
|
|
|
test_expect_success 'sign off (1)' '
|
|
|
|
|
|
|
|
echo 1 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
git commit -s -m "thank you" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2007-11-10 09:49:34 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo thank you &&
|
|
|
|
echo &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >ident &&
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
|
2007-11-10 09:49:34 +00:00
|
|
|
) >expected &&
|
2008-03-12 21:36:36 +00:00
|
|
|
test_cmp expected actual
|
2007-11-10 09:49:34 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'sign off (2)' '
|
|
|
|
|
|
|
|
echo 2 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
existing="Signed-off-by: Watch This <watchthis@example.com>" &&
|
|
|
|
git commit -s -m "thank you
|
|
|
|
|
|
|
|
$existing" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2007-11-10 09:49:34 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo thank you &&
|
|
|
|
echo &&
|
|
|
|
echo $existing &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >ident &&
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
|
2007-11-10 09:49:34 +00:00
|
|
|
) >expected &&
|
2008-03-12 21:36:36 +00:00
|
|
|
test_cmp expected actual
|
2007-11-10 09:49:34 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-10-28 17:13:44 +00:00
|
|
|
test_expect_success 'signoff gap' '
|
|
|
|
|
|
|
|
echo 3 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
alt="Alt-RFC-822-Header: Value" &&
|
|
|
|
git commit -s -m "welcome
|
|
|
|
|
|
|
|
$alt" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2009-10-28 17:13:44 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo welcome &&
|
|
|
|
echo &&
|
|
|
|
echo $alt &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >ident &&
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
|
2009-10-28 17:13:44 +00:00
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'signoff gap 2' '
|
|
|
|
|
|
|
|
echo 4 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
alt="fixed: 34" &&
|
|
|
|
git commit -s -m "welcome
|
|
|
|
|
|
|
|
We have now
|
|
|
|
$alt" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2009-10-28 17:13:44 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo welcome &&
|
|
|
|
echo &&
|
|
|
|
echo We have now &&
|
|
|
|
echo $alt &&
|
|
|
|
echo &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git var GIT_COMMITTER_IDENT >ident &&
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
|
2009-10-28 17:13:44 +00:00
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-11-02 17:29:20 +00:00
|
|
|
test_expect_success 'signoff respects trailer config' '
|
|
|
|
|
|
|
|
echo 5 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
git commit -s -m "subject
|
|
|
|
|
|
|
|
non-trailer line
|
|
|
|
Myfooter: x" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2016-11-02 17:29:20 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo subject &&
|
|
|
|
echo &&
|
|
|
|
echo non-trailer line &&
|
|
|
|
echo Myfooter: x &&
|
|
|
|
echo &&
|
2016-11-02 17:29:20 +00:00
|
|
|
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
|
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual &&
|
|
|
|
|
|
|
|
echo 6 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
git -c "trailer.Myfooter.ifexists=add" commit -s -m "subject
|
|
|
|
|
|
|
|
non-trailer line
|
|
|
|
Myfooter: x" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2016-11-02 17:29:20 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo subject &&
|
|
|
|
echo &&
|
|
|
|
echo non-trailer line &&
|
|
|
|
echo Myfooter: x &&
|
2016-11-02 17:29:20 +00:00
|
|
|
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
|
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2018-08-23 00:50:37 +00:00
|
|
|
test_expect_success 'signoff not confused by ---' '
|
|
|
|
cat >expected <<-EOF &&
|
|
|
|
subject
|
|
|
|
|
|
|
|
body
|
|
|
|
---
|
|
|
|
these dashes confuse the parser!
|
|
|
|
|
|
|
|
Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>
|
|
|
|
EOF
|
|
|
|
# should be a noop, since we already signed
|
|
|
|
git commit --allow-empty --signoff -F expected &&
|
|
|
|
git log -1 --pretty=format:%B >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2007-11-10 09:49:34 +00:00
|
|
|
test_expect_success 'multiple -m' '
|
|
|
|
|
|
|
|
>negative &&
|
|
|
|
git add negative &&
|
|
|
|
git commit -m "one" -m "two" -m "three" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
sed -e "1,/^\$/d" commit >actual &&
|
2007-11-10 09:49:34 +00:00
|
|
|
(
|
2018-07-02 00:24:03 +00:00
|
|
|
echo one &&
|
|
|
|
echo &&
|
|
|
|
echo two &&
|
|
|
|
echo &&
|
2007-11-10 09:49:34 +00:00
|
|
|
echo three
|
|
|
|
) >expected &&
|
2008-03-12 21:36:36 +00:00
|
|
|
test_cmp expected actual
|
2007-11-10 09:49:34 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-02 15:33:06 +00:00
|
|
|
test_expect_success 'amend commit to fix author' '
|
|
|
|
|
|
|
|
oldtick=$GIT_AUTHOR_DATE &&
|
|
|
|
test_tick &&
|
|
|
|
git reset --hard &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file -p HEAD >commit &&
|
2007-11-02 15:33:06 +00:00
|
|
|
sed -e "s/author.*/author $author $oldtick/" \
|
2019-11-27 19:53:43 +00:00
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
|
|
|
|
commit >expected &&
|
2007-11-02 15:33:06 +00:00
|
|
|
git commit --amend --author="$author" &&
|
2019-11-27 19:53:40 +00:00
|
|
|
git cat-file -p HEAD >current &&
|
2008-09-10 17:32:44 +00:00
|
|
|
test_cmp expected current
|
2007-11-02 15:33:06 +00:00
|
|
|
|
|
|
|
'
|
2007-11-15 14:49:58 +00:00
|
|
|
|
|
|
|
test_expect_success 'git commit <file> with dirty index' '
|
2019-11-27 19:53:40 +00:00
|
|
|
echo tacocat >elif &&
|
|
|
|
echo tehlulz >chz &&
|
2007-11-15 14:49:58 +00:00
|
|
|
git add chz &&
|
|
|
|
git commit elif -m "tacocat is a palindrome" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git show --stat >stat &&
|
|
|
|
grep elif stat &&
|
|
|
|
git diff --cached >diff &&
|
|
|
|
grep chz diff
|
2007-11-15 14:49:58 +00:00
|
|
|
'
|
|
|
|
|
2007-12-03 07:24:50 +00:00
|
|
|
test_expect_success 'same tree (single parent)' '
|
|
|
|
|
2011-12-07 14:50:23 +00:00
|
|
|
git reset --hard &&
|
|
|
|
test_must_fail git commit -m empty
|
2007-12-03 07:24:50 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-03 08:03:10 +00:00
|
|
|
test_expect_success 'same tree (single parent) --allow-empty' '
|
|
|
|
|
|
|
|
git commit --allow-empty -m "forced empty" &&
|
2019-11-27 19:53:43 +00:00
|
|
|
git cat-file commit HEAD >commit &&
|
|
|
|
grep forced commit
|
2007-12-03 08:03:10 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-03 07:24:50 +00:00
|
|
|
test_expect_success 'same tree (merge and amend merge)' '
|
|
|
|
|
|
|
|
git checkout -b side HEAD^ &&
|
|
|
|
echo zero >zero &&
|
|
|
|
git add zero &&
|
|
|
|
git commit -m "add zero" &&
|
2020-11-18 23:44:40 +00:00
|
|
|
git checkout main &&
|
2007-12-03 07:24:50 +00:00
|
|
|
|
|
|
|
git merge -s ours side -m "empty ok" &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 21:57:25 +00:00
|
|
|
test_must_be_empty actual &&
|
2007-12-03 07:24:50 +00:00
|
|
|
|
|
|
|
git commit --amend -m "empty really ok" &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 21:57:25 +00:00
|
|
|
test_must_be_empty actual
|
2007-12-03 07:24:50 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-14 19:57:22 +00:00
|
|
|
test_expect_success 'amend using the message from another commit' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "old commit" &&
|
|
|
|
old=$(git rev-parse --verify HEAD) &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "new commit" &&
|
|
|
|
new=$(git rev-parse --verify HEAD) &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty --amend -C "$old" &&
|
|
|
|
git show --pretty="format:%ad %s" "$old" >expected &&
|
|
|
|
git show --pretty="format:%ad %s" HEAD >actual &&
|
2008-03-12 21:36:36 +00:00
|
|
|
test_cmp expected actual
|
2007-12-14 19:57:22 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-02-03 08:00:09 +00:00
|
|
|
test_expect_success 'amend using the message from a commit named with tag' '
|
|
|
|
|
|
|
|
git reset --hard &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "old commit" &&
|
|
|
|
old=$(git rev-parse --verify HEAD) &&
|
|
|
|
git tag -a -m "tag on old" tagged-old HEAD &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty -m "new commit" &&
|
|
|
|
new=$(git rev-parse --verify HEAD) &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --allow-empty --amend -C tagged-old &&
|
|
|
|
git show --pretty="format:%ad %s" "$old" >expected &&
|
|
|
|
git show --pretty="format:%ad %s" HEAD >actual &&
|
2008-03-12 21:36:36 +00:00
|
|
|
test_cmp expected actual
|
2008-02-03 08:00:09 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2010-03-12 17:04:34 +00:00
|
|
|
test_expect_success 'amend can copy notes' '
|
|
|
|
|
|
|
|
git config notes.rewrite.amend true &&
|
|
|
|
git config notes.rewriteRef "refs/notes/*" &&
|
|
|
|
test_commit foo &&
|
|
|
|
git notes add -m"a note" &&
|
|
|
|
test_tick &&
|
|
|
|
git commit --amend -m"new foo" &&
|
|
|
|
test "$(git notes show)" = "a note"
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2012-06-28 03:14:47 +00:00
|
|
|
test_expect_success 'commit a file whose name is a dash' '
|
|
|
|
git reset --hard &&
|
2021-12-09 05:11:05 +00:00
|
|
|
test_write_lines 1 2 3 4 5 >./- &&
|
2012-06-28 03:14:47 +00:00
|
|
|
git add ./- &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "add dash" >output </dev/null &&
|
2023-10-31 05:23:30 +00:00
|
|
|
test_grep " changed, 5 insertions" output
|
2012-06-28 03:14:47 +00:00
|
|
|
'
|
|
|
|
|
2013-06-01 11:02:00 +00:00
|
|
|
test_expect_success '--only works on to-be-born branch' '
|
|
|
|
# This test relies on having something in the index, as it
|
|
|
|
# would not otherwise actually prove much. So check this.
|
|
|
|
test -n "$(git ls-files)" &&
|
|
|
|
git checkout --orphan orphan &&
|
|
|
|
echo foo >newfile &&
|
|
|
|
git add newfile &&
|
|
|
|
git commit --only newfile -m"--only on unborn branch" &&
|
|
|
|
echo newfile >expected &&
|
|
|
|
git ls-tree -r --name-only HEAD >actual &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-02-16 02:38:25 +00:00
|
|
|
test_expect_success '--dry-run with conflicts fixed from a merge' '
|
|
|
|
# setup two branches with conflicting information
|
|
|
|
# in the same file, resolve the conflict,
|
|
|
|
# call commit with --dry-run
|
|
|
|
echo "Initial contents, unimportant" >test-file &&
|
|
|
|
git add test-file &&
|
|
|
|
git commit -m "Initial commit" &&
|
|
|
|
echo "commit-1-state" >test-file &&
|
|
|
|
git commit -m "commit 1" -i test-file &&
|
|
|
|
git tag commit-1 &&
|
|
|
|
git checkout -b branch-2 HEAD^1 &&
|
|
|
|
echo "commit-2-state" >test-file &&
|
|
|
|
git commit -m "commit 2" -i test-file &&
|
2018-08-21 23:28:11 +00:00
|
|
|
test_must_fail git merge --no-commit commit-1 &&
|
2016-02-16 02:38:25 +00:00
|
|
|
echo "commit-2-state" >test-file &&
|
|
|
|
git add test-file &&
|
|
|
|
git commit --dry-run &&
|
|
|
|
git commit -m "conflicts fixed from merge."
|
|
|
|
'
|
|
|
|
|
2018-09-06 00:53:29 +00:00
|
|
|
test_expect_success '--dry-run --short' '
|
2018-09-06 00:53:28 +00:00
|
|
|
>test-file &&
|
|
|
|
git add test-file &&
|
|
|
|
git commit --dry-run --short
|
|
|
|
'
|
|
|
|
|
2007-07-31 19:37:30 +00:00
|
|
|
test_done
|