This shows that with the "--keep" option, changes that are both in
the work tree and the index are kept in the work tree after the
reset (but discarded in the index).
In the case of unmerged entries, we can see that "git reset --keep"
works only when the target state is the same as HEAD. And then the
work tree is not reset.
Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Christian Couder15 years agocommitted byJunio C Hamano
test_description='Tests for "git reset" with "--merge" and "--keep" options'
. ./test-lib.sh
@ -43,6 +43,30 @@ test_expect_success 'reset --merge is ok when switching back' '
@@ -43,6 +43,30 @@ test_expect_success 'reset --merge is ok when switching back' '
test_expect_success 'reset --keep is ok with changes in file it does not touch' '
git reset --hard second &&
cat file1 >file2 &&
git reset --keep HEAD^ &&
! grep 4 file1 &&
grep 4 file2 &&
test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
test -z "$(git diff --cached)"
'
test_expect_success 'reset --keep is ok when switching back' '
git reset --keep second &&
grep 4 file1 &&
grep 4 file2 &&
test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
test -z "$(git diff --cached)"
'
# The next test will test the following:
#
# working index HEAD target working index HEAD
@ -74,6 +98,18 @@ test_expect_success 'reset --merge is ok again when switching back (1)' '
@@ -74,6 +98,18 @@ test_expect_success 'reset --merge is ok again when switching back (1)' '
test_expect_success 'reset --keep fails with changes in index in files it touches' '
git reset --hard second &&
echo "line 5" >> file1 &&
git add file1 &&
test_must_fail git reset --keep HEAD^
'
# The next test will test the following:
#
# working index HEAD target working index HEAD
@ -100,6 +136,30 @@ test_expect_success 'reset --merge is ok again when switching back (2)' '
@@ -100,6 +136,30 @@ test_expect_success 'reset --merge is ok again when switching back (2)' '
test_expect_success 'reset --keep keeps changes it does not touch' '
git reset --hard second &&
echo "line 4" >> file2 &&
git add file2 &&
git reset --keep HEAD^ &&
grep 4 file2 &&
test "$(git rev-parse HEAD)" = "$(git rev-parse initial)" &&
test -z "$(git diff --cached)"
'
test_expect_success 'reset --keep keeps changes when switching back' '
git reset --keep second &&
grep 4 file2 &&
grep 4 file1 &&
test "$(git rev-parse HEAD)" = "$(git rev-parse second)" &&
test -z "$(git diff --cached)"
'
# The next test will test the following:
#
# working index HEAD target working index HEAD
@ -116,6 +176,22 @@ test_expect_success 'reset --merge fails with changes in file it touches' '
@@ -116,6 +176,22 @@ test_expect_success 'reset --merge fails with changes in file it touches' '
test_expect_success 'setup 3 different branches' '
git reset --hard second &&
git branch branch1 &&
@ -152,6 +228,18 @@ test_expect_success '"reset --merge HEAD^" is ok with pending merge' '
@@ -152,6 +228,18 @@ test_expect_success '"reset --merge HEAD^" is ok with pending merge' '
@ -166,6 +254,21 @@ test_expect_success '"reset --merge HEAD" is ok with pending merge' '
@@ -166,6 +254,21 @@ test_expect_success '"reset --merge HEAD" is ok with pending merge' '