2007-07-31 23:37:30 +04:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Kristian Høgsberg <krh@redhat.com>
|
|
|
|
#
|
|
|
|
|
|
|
|
# FIXME: Test the various index usages, -i and -o, test reflog,
|
2007-12-08 15:29:47 +03:00
|
|
|
# signoff
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2008-09-03 12:59:33 +04:00
|
|
|
test_description='git commit'
|
2007-07-31 23:37:30 +04:00
|
|
|
. ./test-lib.sh
|
2011-12-07 18:50:23 +04:00
|
|
|
. "$TEST_DIRECTORY/diff-lib.sh"
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
author='The Real Author <someguy@his.email.org>'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_tick
|
2011-02-23 02:42:17 +03:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'initial status' '
|
|
|
|
echo bongo bongo >file &&
|
|
|
|
git add file &&
|
2011-04-14 03:17:29 +04:00
|
|
|
git status >actual &&
|
2017-06-21 21:16:14 +03:00
|
|
|
test_i18ngrep "No commits yet" actual
|
2011-04-14 03:17:29 +04:00
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'fail initial amend' '
|
|
|
|
test_must_fail git commit --amend
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'setup: initial commit' '
|
|
|
|
git commit -m initial
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success '-m and -F do not mix' '
|
2012-03-30 22:04:08 +04:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 18:50:23 +04:00
|
|
|
test_must_fail git commit -m foo -m bar -F file
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success '-m and -C do not mix' '
|
2012-03-30 22:04:08 +04:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 18:50:23 +04:00
|
|
|
test_must_fail git commit -C HEAD -m illegal
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04: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 18:15:39 +03:00
|
|
|
|
2011-05-07 10:00:00 +04:00
|
|
|
test_expect_success PERL 'can use paths with --interactive' '
|
2011-05-10 03:53:00 +04:00
|
|
|
echo bong-o-bong >file &&
|
|
|
|
# 2: update, 1:st path, that is all, 7: quit
|
|
|
|
( echo 2; echo 1; echo; echo 7 ) |
|
2011-05-07 10:00:00 +04:00
|
|
|
git commit -m foo --interactive file &&
|
|
|
|
git reset --hard HEAD^
|
2011-05-10 03:53:00 +04:00
|
|
|
'
|
2007-11-12 18:15:39 +03:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'using invalid commit with -C' '
|
2013-08-24 08:01:44 +04:00
|
|
|
test_must_fail git commit --allow-empty -C bogus
|
2011-12-07 18:50:23 +04:00
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04: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 23:54:57 +04:00
|
|
|
git reset --hard &&
|
2011-12-07 18:50:23 +04:00
|
|
|
test_must_fail git commit -m initial
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2014-02-21 23:16:54 +04: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
|
|
|
|
'
|
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'setup: non-initial commit' '
|
|
|
|
echo bongo bongo bongo >file &&
|
|
|
|
git commit -m next -a
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2014-02-21 23:16:54 +04:00
|
|
|
test_expect_success '--dry-run with stuff to commit returns ok' '
|
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --dry-run
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_failure '--short with stuff to commit returns ok' '
|
|
|
|
echo bongo bongo bongo >>file &&
|
|
|
|
git commit -m next -a --short
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_failure '--porcelain with stuff to commit returns ok' '
|
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2011-12-07 18:50:23 +04: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 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04: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 23:37:30 +04:00
|
|
|
|
2012-03-30 22:30:59 +04: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 23:14:33 +04: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 &&
|
|
|
|
test_i18ngrep "did not edit" err
|
|
|
|
'
|
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'setup: commit message from file' '
|
2012-03-30 22:30:59 +04:00
|
|
|
git checkout HEAD file && echo >>file && git add file &&
|
2011-12-07 18:50:23 +04:00
|
|
|
echo this is the commit message, coming from a file >msg &&
|
|
|
|
git commit -F msg -a
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'amend commit' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
sed -e "s/a file/an amend commit/g" < "$1" > "$1-"
|
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor &&
|
|
|
|
EDITOR=./editor git commit --amend
|
|
|
|
'
|
2007-07-31 23:37:30 +04: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-11 00:40:29 +04: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-03 01:15:13 +03: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-11 00:40:29 +04:00
|
|
|
git diff --exit-code
|
|
|
|
'
|
|
|
|
|
2011-12-07 18:54:14 +04: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 22:53:26 +04: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 22:56:26 +03:00
|
|
|
test_expect_success '--amend to set message to empty' '
|
|
|
|
echo bata >file &&
|
2016-04-06 20:15:03 +03: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 22:56:26 +03:00
|
|
|
test_expect_success '--amend to set empty message needs --allow-empty-message' '
|
2016-04-06 20:15:03 +03: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 18:54:14 +04: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 18:50:23 +04: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 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'editing message from other commit' '
|
|
|
|
cat >editor <<-\EOF &&
|
|
|
|
#!/bin/sh
|
|
|
|
sed -e "s/amend/older/g" < "$1" > "$1-"
|
|
|
|
mv "$1-" "$1"
|
|
|
|
EOF
|
|
|
|
chmod 755 editor &&
|
|
|
|
echo hula hula >file &&
|
|
|
|
EDITOR=./editor git commit -c HEAD^ -a
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success 'message from stdin' '
|
|
|
|
echo silly new contents >file &&
|
|
|
|
echo commit message from stdin |
|
|
|
|
git commit -F - -a
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04: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 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
test_expect_success PERL 'interactive add' '
|
|
|
|
echo 7 |
|
|
|
|
git commit --interactive |
|
|
|
|
grep "What now"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
|
|
|
|
echo zoo >file &&
|
2011-05-10 23:12:31 +04:00
|
|
|
test_must_fail git diff --exit-code >diff1 &&
|
2011-12-07 18:50:23 +04:00
|
|
|
(echo u ; echo "*" ; echo q) |
|
|
|
|
(
|
|
|
|
EDITOR=: &&
|
|
|
|
export EDITOR &&
|
|
|
|
test_must_fail git commit --interactive
|
|
|
|
) &&
|
2011-05-10 23:12:31 +04:00
|
|
|
git diff >diff2 &&
|
2011-12-07 18:50:23 +04:00
|
|
|
compare_diff_patch diff1 diff2
|
|
|
|
'
|
2007-07-31 23:37:30 +04:00
|
|
|
|
2011-12-07 18:50:23 +04: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 23:37:30 +04:00
|
|
|
|
2007-09-15 03:53:58 +04:00
|
|
|
test_expect_success 'partial commit that involves removal (1)' '
|
2007-09-13 03:04:22 +04: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 21:32:44 +04:00
|
|
|
test_cmp expected current
|
2007-09-13 03:04:22 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-09-15 03:53:58 +04:00
|
|
|
test_expect_success 'partial commit that involves removal (2)' '
|
2007-09-13 03:04:22 +04:00
|
|
|
|
|
|
|
git commit -m "Partial: remove file" file &&
|
|
|
|
git diff-tree --name-status HEAD^ HEAD >current &&
|
|
|
|
echo "D file" >expected &&
|
2008-09-10 21:32:44 +04:00
|
|
|
test_cmp expected current
|
2007-09-13 03:04:22 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-09-15 03:53:58 +04: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 21:32:44 +04:00
|
|
|
test_cmp expected current
|
2007-09-15 03:53:58 +04:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-10 12:49:34 +03:00
|
|
|
test_expect_success 'amend commit to fix author' '
|
|
|
|
|
|
|
|
oldtick=$GIT_AUTHOR_DATE &&
|
|
|
|
test_tick &&
|
|
|
|
git reset --hard &&
|
|
|
|
git cat-file -p HEAD |
|
|
|
|
sed -e "s/author.*/author $author $oldtick/" \
|
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
|
|
|
|
expected &&
|
|
|
|
git commit --amend --author="$author" &&
|
|
|
|
git cat-file -p HEAD > current &&
|
2008-09-10 21:32:44 +04:00
|
|
|
test_cmp expected current
|
2007-11-10 12:49:34 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-12-03 01:16:18 +03:00
|
|
|
test_expect_success 'amend commit to fix date' '
|
|
|
|
|
|
|
|
test_tick &&
|
|
|
|
newtick=$GIT_AUTHOR_DATE &&
|
|
|
|
git reset --hard &&
|
|
|
|
git cat-file -p HEAD |
|
|
|
|
sed -e "s/author.*/author $author $newtick/" \
|
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
|
|
|
|
expected &&
|
|
|
|
git commit --amend --date="$newtick" &&
|
|
|
|
git cat-file -p HEAD > current &&
|
|
|
|
test_cmp expected current
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2014-05-02 05:10:01 +04: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 05:12:42 +04: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 20:02:25 +03:00
|
|
|
'
|
|
|
|
|
2007-11-10 12:49:34 +03:00
|
|
|
test_expect_success 'sign off (1)' '
|
|
|
|
|
|
|
|
echo 1 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
git commit -s -m "thank you" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
|
|
|
|
(
|
|
|
|
echo thank you
|
|
|
|
echo
|
|
|
|
git var GIT_COMMITTER_IDENT |
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
|
|
|
|
) >expected &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2007-11-10 12:49:34 +03: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" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
|
|
|
|
(
|
|
|
|
echo thank you
|
|
|
|
echo
|
|
|
|
echo $existing
|
|
|
|
git var GIT_COMMITTER_IDENT |
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
|
|
|
|
) >expected &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2007-11-10 12:49:34 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2009-10-28 20:13:44 +03:00
|
|
|
test_expect_success 'signoff gap' '
|
|
|
|
|
|
|
|
echo 3 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
alt="Alt-RFC-822-Header: Value" &&
|
|
|
|
git commit -s -m "welcome
|
|
|
|
|
|
|
|
$alt" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
|
|
|
|
(
|
|
|
|
echo welcome
|
|
|
|
echo
|
|
|
|
echo $alt
|
|
|
|
git var GIT_COMMITTER_IDENT |
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
|
|
|
|
) >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" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
|
|
|
|
(
|
|
|
|
echo welcome
|
|
|
|
echo
|
|
|
|
echo We have now
|
|
|
|
echo $alt
|
|
|
|
echo
|
|
|
|
git var GIT_COMMITTER_IDENT |
|
|
|
|
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /"
|
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2016-11-02 20:29:20 +03:00
|
|
|
test_expect_success 'signoff respects trailer config' '
|
|
|
|
|
|
|
|
echo 5 >positive &&
|
|
|
|
git add positive &&
|
|
|
|
git commit -s -m "subject
|
|
|
|
|
|
|
|
non-trailer line
|
|
|
|
Myfooter: x" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
|
|
|
|
(
|
|
|
|
echo subject
|
|
|
|
echo
|
|
|
|
echo non-trailer line
|
|
|
|
echo Myfooter: x
|
|
|
|
echo
|
|
|
|
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" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual &&
|
|
|
|
(
|
|
|
|
echo subject
|
|
|
|
echo
|
|
|
|
echo non-trailer line
|
|
|
|
echo Myfooter: x
|
|
|
|
echo "Signed-off-by: $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL>"
|
|
|
|
) >expected &&
|
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2007-11-10 12:49:34 +03:00
|
|
|
test_expect_success 'multiple -m' '
|
|
|
|
|
|
|
|
>negative &&
|
|
|
|
git add negative &&
|
|
|
|
git commit -m "one" -m "two" -m "three" &&
|
|
|
|
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual &&
|
|
|
|
(
|
|
|
|
echo one
|
|
|
|
echo
|
|
|
|
echo two
|
|
|
|
echo
|
|
|
|
echo three
|
|
|
|
) >expected &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2007-11-10 12:49:34 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-11-02 18:33:06 +03:00
|
|
|
test_expect_success 'amend commit to fix author' '
|
|
|
|
|
|
|
|
oldtick=$GIT_AUTHOR_DATE &&
|
|
|
|
test_tick &&
|
|
|
|
git reset --hard &&
|
|
|
|
git cat-file -p HEAD |
|
|
|
|
sed -e "s/author.*/author $author $oldtick/" \
|
|
|
|
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \
|
|
|
|
expected &&
|
|
|
|
git commit --amend --author="$author" &&
|
|
|
|
git cat-file -p HEAD > current &&
|
2008-09-10 21:32:44 +04:00
|
|
|
test_cmp expected current
|
2007-11-02 18:33:06 +03:00
|
|
|
|
|
|
|
'
|
2007-11-15 17:49:58 +03:00
|
|
|
|
|
|
|
test_expect_success 'git commit <file> with dirty index' '
|
|
|
|
echo tacocat > elif &&
|
|
|
|
echo tehlulz > chz &&
|
|
|
|
git add chz &&
|
|
|
|
git commit elif -m "tacocat is a palindrome" &&
|
|
|
|
git show --stat | grep elif &&
|
|
|
|
git diff --cached | grep chz
|
|
|
|
'
|
|
|
|
|
2007-12-03 10:24:50 +03:00
|
|
|
test_expect_success 'same tree (single parent)' '
|
|
|
|
|
2011-12-07 18:50:23 +04:00
|
|
|
git reset --hard &&
|
|
|
|
test_must_fail git commit -m empty
|
2007-12-03 10:24:50 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-03 11:03:10 +03:00
|
|
|
test_expect_success 'same tree (single parent) --allow-empty' '
|
|
|
|
|
|
|
|
git commit --allow-empty -m "forced empty" &&
|
|
|
|
git cat-file commit HEAD | grep forced
|
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-03 10:24:50 +03: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" &&
|
|
|
|
git checkout master &&
|
|
|
|
|
|
|
|
git merge -s ours side -m "empty ok" &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
: >expected &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected actual &&
|
2007-12-03 10:24:50 +03:00
|
|
|
|
|
|
|
git commit --amend -m "empty really ok" &&
|
|
|
|
git diff HEAD^ HEAD >actual &&
|
|
|
|
: >expected &&
|
2008-03-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2007-12-03 10:24:50 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2007-12-14 22:57:22 +03: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-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2007-12-14 22:57:22 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2008-02-03 11:00:09 +03: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-13 00:36:36 +03:00
|
|
|
test_cmp expected actual
|
2008-02-03 11:00:09 +03:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2010-03-12 20:04:34 +03: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 07:14:47 +04:00
|
|
|
test_expect_success 'commit a file whose name is a dash' '
|
|
|
|
git reset --hard &&
|
|
|
|
for i in 1 2 3 4 5
|
|
|
|
do
|
|
|
|
echo $i
|
|
|
|
done >./- &&
|
|
|
|
git add ./- &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m "add dash" >output </dev/null &&
|
|
|
|
test_i18ngrep " changed, 5 insertions" output
|
|
|
|
'
|
|
|
|
|
2013-06-01 15:02:00 +04: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 05:38:25 +03: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 &&
|
|
|
|
! $(git merge --no-commit commit-1) &&
|
|
|
|
echo "commit-2-state" >test-file &&
|
|
|
|
git add test-file &&
|
|
|
|
git commit --dry-run &&
|
|
|
|
git commit -m "conflicts fixed from merge."
|
|
|
|
'
|
|
|
|
|
2007-07-31 23:37:30 +04:00
|
|
|
test_done
|