git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christian Couder <chriscool@tuxfamily.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Stephan Beyer <s-beyer@gmx.net>,
	Daniel Barkalow <barkalow@iabervon.org>,
	Jakub Narebski <jnareb@gmail.com>,
	Paolo Bonzini <bonzini@gnu.org>,
	Johannes Sixt <j.sixt@viscovery.net>,
	Stephen Boyd <bebarino@gmail.com>
Subject: [PATCH] t7111: check that reset options work as described in the tables
Date: Fri, 08 Jan 2010 05:45:10 +0100	[thread overview]
Message-ID: <20100108044511.3530.90952.chriscool@tuxfamily.org> (raw)

Some previous patches added some tables to the "git reset"
documentation. These tables describe the behavior of "git reset"
depending on the option it is passed and the state of the files
in the working tree, the index, HEAD and the target commit.

This patch adds some tests to make sure that the tables describe
the behavior of "git reset".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 t/t7111-reset-table.sh |  121 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 121 insertions(+), 0 deletions(-)
 create mode 100755 t/t7111-reset-table.sh

diff --git a/t/t7111-reset-table.sh b/t/t7111-reset-table.sh
new file mode 100755
index 0000000..16b33a5
--- /dev/null
+++ b/t/t7111-reset-table.sh
@@ -0,0 +1,121 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Christian Couder
+#
+
+test_description='Tests to check that "reset" options follow a known table'
+
+. ./test-lib.sh
+
+
+test_expect_success 'creating initial commits' '
+    test_commit E file1 &&
+    test_commit D file1 &&
+    test_commit C file1
+'
+
+test_expect_success 'creating table file 1' '
+    cat <<EOF >table1
+A B C D soft   A B D
+A B C D mixed  A D D
+A B C D hard   D D D
+A B C D merge  XXXXX
+A B C C soft   A B C
+A B C C mixed  A C C
+A B C C hard   C C C
+A B C C merge  XXXXX
+B B C D soft   B B D
+B B C D mixed  B D D
+B B C D hard   D D D
+B B C D merge  D D D
+B B C C soft   B B C
+B B C C mixed  B C C
+B B C C hard   C C C
+B B C C merge  C C C
+B C C D soft   B C D
+B C C D mixed  B D D
+B C C D hard   D D D
+B C C D merge  XXXXX
+B C C C soft   B C C
+B C C C mixed  B C C
+B C C C hard   C C C
+B C C C merge  B C C
+EOF
+'
+
+while read W1 I1 H1 T opt W2 I2 H2
+do
+    test_expect_success "check: $W1 $I1 $H1 $T --$opt $W2 $I2 $H2" '
+        git reset --hard C &&
+        if [ "$I1" != "$H1" ]
+        then
+            echo "$I1" > file1 &&
+            git add file1
+        fi &&
+        if [ "$W1" != "$I1" ]
+        then
+            echo "$W1" > file1
+        fi &&
+        if [ "$W2" != "XXXXX" ]
+        then
+            git reset --$opt $T &&
+            test "$(cat file1)" = "$W2" &&
+            git checkout-index -f -- file1 &&
+            test "$(cat file1)" = "$I2" &&
+            git checkout -f HEAD -- file1 &&
+            test "$(cat file1)" = "$H2"
+        else
+            test_must_fail git reset --$opt $T
+        fi
+    '
+done < table1
+
+test_expect_success 'setting up branches to test with unmerged entries' '
+    git reset --hard C &&
+    git branch branch1 &&
+    git branch branch2 &&
+    git checkout branch1 &&
+    test_commit B1 file1 &&
+    git checkout branch2 &&
+    test_commit B2 file1
+'
+
+test_expect_success 'creating table file 2' '
+    cat <<EOF >table2
+X U C D soft   XXXXX
+X U C D mixed  X D D
+X U C D hard   D D D
+X U C D merge  D D D
+X U C C soft   XXXXX
+X U C C mixed  X C C
+X U C C hard   C C C
+X U C C merge  C C C
+EOF
+'
+
+while read W1 I1 H1 T opt W2 I2 H2
+do
+    test_expect_success "check: $W1 $I1 $H1 $T --$opt $W2 $I2 $H2" '
+        git reset --hard B2 &&
+        test_must_fail git merge branch1 &&
+        cat file1 >X_file1 &&
+        if [ "$W2" != "XXXXX" ]
+        then
+            git reset --$opt $T &&
+            if [ "$W2" = "X" ]
+            then
+                test_cmp file1 X_file1
+            else
+                test "$(cat file1)" = "$W2"
+            fi &&
+            git checkout-index -f -- file1 &&
+            test "$(cat file1)" = "$I2" &&
+            git checkout -f HEAD -- file1 &&
+            test "$(cat file1)" = "$H2"
+        else
+            test_must_fail git reset --$opt $T
+        fi
+    '
+done < table2
+
+test_done
-- 
1.6.6.rc2.5.g49666

                 reply	other threads:[~2010-01-08  4:45 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100108044511.3530.90952.chriscool@tuxfamily.org \
    --to=chriscool@tuxfamily.org \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=bebarino@gmail.com \
    --cc=bonzini@gnu.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=jnareb@gmail.com \
    --cc=s-beyer@gmx.net \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).