Re: [PATCH] Add tests for documented features of "git reset".

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2007/9/11, Junio C Hamano <gitster@xxxxxxxxx>:
> I also suspect this would not pass on CRLF boxes.

I finally removed the hardcoded object IDs (patch attached,
to be applied on top of the previous patch).

But I don't know what to fix for making the test to pass
in CRLF boxes. Could it due to the comparison of
expected diffs with files created using <<EOF?
From b4c696b3e5b79d02c228bbc79d0d0e8f6a144453 Mon Sep 17 00:00:00 2001
From: Carlos Rica <jasampler@xxxxxxxxx>
Date: Thu, 13 Sep 2007 12:37:45 +0200
Subject: [PATCH] t7102-reset: Use tags to avoid hardcoded revision IDs.

Signed-off-by: Carlos Rica <jasampler@xxxxxxxxx>
---
 t/t7102-reset.sh |   83 ++++++++++++++++++++++++++---------------------------
 1 files changed, 41 insertions(+), 42 deletions(-)

diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh
index 2cad4db..7e3da71 100755
--- a/t/t7102-reset.sh
+++ b/t/t7102-reset.sh
@@ -21,19 +21,28 @@ test_expect_success 'creating initial files and commits' '
 
 	echo "2nd line 1st file" >>first &&
 	git commit -a -m "modify 1st file" &&
+	git tag modify1 &&
 
 	git rm first &&
 	git mv second secondfile &&
 	git commit -a -m "remove 1st and rename 2nd" &&
+	git tag moves &&
 
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
-	git commit -a -m "modify 2nd file"
+	git commit -a -m "modify 2nd file" &&
+	git tag modify2
 '
 # git log --pretty=oneline # to see those SHA1 involved
 
+refs_are_equal() {
+	r1=$(git rev-parse $1) &&
+	r2=$(git rev-parse $2) &&
+	test $r1 = $r2
+}
+
 check_changes () {
-	test "$(git rev-parse HEAD)" = "$1" &&
+	refs_are_equal HEAD $1 &&
 	git diff | git diff .diff_expect - &&
 	git diff --cached | git diff .cached_expect - &&
 	for FILE in *
@@ -56,7 +65,7 @@ test_expect_success 'giving a non existing revision should fail' '
 	! git reset --mixed aaaaaa &&
 	! git reset --soft aaaaaa &&
 	! git reset --hard aaaaaa &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 test_expect_success \
@@ -65,7 +74,7 @@ test_expect_success \
 	! git reset --hard -- first &&
 	! git reset --soft HEAD^ -- first &&
 	! git reset --hard HEAD^ -- first &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 test_expect_success 'giving unrecognized options should fail' '
@@ -77,7 +86,7 @@ test_expect_success 'giving unrecognized options should fail' '
 	! git reset --soft -o &&
 	! git reset --hard --other &&
 	! git reset --hard -o &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 test_expect_success \
@@ -101,7 +110,7 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 test_expect_success \
@@ -124,27 +133,19 @@ test_expect_success \
 
 	git checkout master &&
 	git branch -D branch3 branch4 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 test_expect_success \
 	'resetting to HEAD with no changes should succeed and do nothing' '
-	git reset --hard &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset --hard HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset --soft &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset --soft HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset --mixed &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset --mixed HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
-	git reset HEAD &&
-		check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	git reset --hard && check_changes modify2
+	git reset --hard HEAD && check_changes modify2
+	git reset --soft && check_changes modify2
+	git reset --soft HEAD && check_changes modify2
+	git reset --mixed && check_changes modify2
+	git reset --mixed HEAD && check_changes modify2
+	git reset && check_changes modify2
+	git reset HEAD && check_changes modify2
 '
 
 >.diff_expect
@@ -165,9 +166,8 @@ secondfile:
 EOF
 test_expect_success '--soft reset only should show changes in diff --cached' '
 	git reset --soft HEAD^ &&
-	check_changes d1a4bc3abce4829628ae2dcb0d60ef3d1a78b1c4 &&
-	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes moves &&
+	refs_are_equal ORIG_HEAD modify2
 '
 
 >.diff_expect
@@ -182,9 +182,9 @@ test_expect_success \
 	'changing files and redo the last commit should succeed' '
 	echo "3rd line 2nd file" >>secondfile &&
 	git commit -a -C ORIG_HEAD &&
-	check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d &&
-	test "$(git rev-parse ORIG_HEAD)" = \
-			3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	git tag addline1
+	check_changes addline1 &&
+	refs_are_equal ORIG_HEAD modify2
 '
 
 >.diff_expect
@@ -199,9 +199,8 @@ EOF
 test_expect_success \
 	'--hard reset should change the files and undo commits permanently' '
 	git reset --hard HEAD~2 &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
-	test "$(git rev-parse ORIG_HEAD)" = \
-			3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d
+	check_changes modify1 &&
+	refs_are_equal ORIG_HEAD addline1
 '
 
 >.diff_expect
@@ -243,7 +242,7 @@ test_expect_success \
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	git add secondfile &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e
+	check_changes modify1
 '
 
 cat >.diff_expect <<EOF
@@ -271,9 +270,8 @@ secondfile:
 EOF
 test_expect_success '--mixed reset to HEAD should unadd the files' '
 	git reset &&
-	check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
-	test "$(git rev-parse ORIG_HEAD)" = \
-			ddaefe00f1da16864591c61fdc7adb5d7cd6b74e
+	check_changes modify1 &&
+	refs_are_equal ORIG_HEAD modify1
 '
 
 >.diff_expect
@@ -285,7 +283,7 @@ secondfile:
 EOF
 test_expect_success 'redoing the last two commits should succeed' '
 	git add secondfile &&
-	git reset --hard ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
+	git reset --hard modify1 &&
 
 	git rm first &&
 	git mv second secondfile &&
@@ -294,7 +292,7 @@ test_expect_success 'redoing the last two commits should succeed' '
 	echo "1st line 2nd file" >secondfile &&
 	echo "2nd line 2nd file" >>secondfile &&
 	git commit -a -m "modify 2nd file" &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 >.diff_expect
@@ -316,10 +314,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
 	git checkout branch2 &&
 	echo "3rd line in branch2" >>secondfile &&
 	git commit -a -m "change in branch2" &&
+	git tag addline2 &&
 
 	! git pull . branch1 &&
 	git reset --hard &&
-	check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb
+	check_changes addline2
 '
 
 >.diff_expect
@@ -332,15 +331,15 @@ EOF
 test_expect_success \
 	'--hard reset to ORIG_HEAD should clear a fast-forward merge' '
 	git reset --hard HEAD^ &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes modify2 &&
 
 	git pull . branch1 &&
 	git reset --hard ORIG_HEAD &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc &&
+	check_changes modify2 &&
 
 	git checkout master &&
 	git branch -D branch1 branch2 &&
-	check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc
+	check_changes modify2
 '
 
 cat > expect << EOF
-- 
1.5.3.1


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux