[PATCH 02/23] Introduce --unstaged.

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

 



test_must_fail: unstaged
---
 Documentation/git-test.txt |    2 ++
 git-conditions-lib.sh      |   11 +++++++++++
 t/t1520-test.sh            |   35 +++++++++++++++++++++++++++++++++++
 3 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/Documentation/git-test.txt b/Documentation/git-test.txt
index 1792c4e..4b2c129 100644
--- a/Documentation/git-test.txt
+++ b/Documentation/git-test.txt
@@ -64,6 +64,8 @@ OPTIONS
 
 CONDITIONS
 ----------
+'--unstaged'|'--not-unstaged'::
+	Tests if there are (not) any unstaged changes in the working tree.
 
 EXTENDING THE CONDITION LIBRARY
 -------------------------------
diff --git a/git-conditions-lib.sh b/git-conditions-lib.sh
index f462e22..f9ff0b9 100644
--- a/git-conditions-lib.sh
+++ b/git-conditions-lib.sh
@@ -8,5 +8,16 @@ __GIT_CONDITIONS_LIB_INCLUDED=t
 #
 # Provides a function that enables the evaluation of assertions.
 #
+check_unstaged_0()
+{
+	if test $(git diff-files --name-only | wc -l) -ne 0
+	then
+		echo "There are unstaged files."
+	else
+		echo "There are no unstaged files."
+		false
+	fi
+}
+
 
 fi
diff --git a/t/t1520-test.sh b/t/t1520-test.sh
index 9e3abe6..8543943 100755
--- a/t/t1520-test.sh
+++ b/t/t1520-test.sh
@@ -181,5 +181,40 @@ test_expect_success 'git test --not-always-fails-0' \
 '
 	git test --not-always-fails-0
 '
+
+test_expect_success 'git test --unstaged # should fail' \
+'
+	test_must_fail git test --unstaged
+'
+
+test_expect_success 'git test --not-unstaged' \
+'
+	git test --not-unstaged
+'
+
+test_expect_success 'git test --unstaged # when there are unstaged files' \
+'
+	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	git checkout -f M^0 &&
+	git stash apply --index STASH_UNSTAGED &&
+	git test --unstaged
+'
+
+test_expect_success 'git test --not-unstaged # when there are unstaged files - should fail' \
+'
+	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	git checkout -f M^0 &&
+	git stash apply --index STASH_UNSTAGED &&
+	test_must_fail git test --not-unstaged
+'
+
+test_expect_success 'git test --unstaged # when there are only staged files' \
+'
+	test_when_finished "git reset --hard HEAD && git checkout master" && 
+	git checkout -f M^0 &&
+	git stash apply --index STASH_STAGED &&
+	git test --not-unstaged
+'
+
 '
 test_done
-- 
1.7.5.rc1.23.g7f622

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[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]