git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jon Seymour <jon.seymour@gmail.com>
To: git@vger.kernel.org
Cc: Jon Seymour <jon.seymour@gmail.com>
Subject: [PATCH 02/23] Introduce --unstaged.
Date: Sat, 23 Apr 2011 17:22:31 +1000	[thread overview]
Message-ID: <1303543372-77843-3-git-send-email-jon.seymour@gmail.com> (raw)
In-Reply-To: <1303543372-77843-1-git-send-email-jon.seymour@gmail.com>

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

  parent reply	other threads:[~2011-04-23  7:24 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-23  7:22 [PATCH 00/23] RFC: Introducing git-test, git-atomic, git-base and git-work Jon Seymour
2011-04-23  7:22 ` [PATCH 01/23] Introduce git-test.sh and git-test-lib.sh Jon Seymour
2011-04-27 19:11   ` Drew Northup
2011-04-23  7:22 ` Jon Seymour [this message]
2011-04-23  7:22 ` [PATCH 03/23] Introduce --staged Jon Seymour
2011-04-23  7:22 ` [PATCH 04/23] Introduce --untracked Jon Seymour
2011-04-23  7:22 ` [PATCH 05/23] Introduce --conflicted Jon Seymour
2011-04-23  7:22 ` [PATCH 06/23] Introduce --rebasing Jon Seymour
2011-04-23  7:22 ` [PATCH 07/23] Introduce --detached Jon Seymour
2011-04-23  7:22 ` [PATCH 08/23] Introduce --branch-exists Jon Seymour
2011-04-23  7:22 ` [PATCH 09/23] Introduce --tag-exists Jon Seymour
2011-04-23  7:22 ` [PATCH 10/23] Introduce --ref-exists Jon Seymour
2011-04-23  7:22 ` [PATCH 11/23] Introduce --commit-exists Jon Seymour
2011-04-23  7:22 ` [PATCH 12/23] Introduce --checked-out Jon Seymour
2011-04-23  7:22 ` [PATCH 13/23] Introduce --reachable Jon Seymour
2011-04-23  7:22 ` [PATCH 14/23] Introduce --tree-same Jon Seymour
2011-04-23  7:22 ` [PATCH 15/23] Introduce --same Jon Seymour
2011-04-23  7:22 ` [PATCH 16/23] misc Jon Seymour
2011-04-23  7:22 ` [PATCH 17/23] whitespace fix Jon Seymour
2011-04-23  7:22 ` [PATCH 18/23] tests --conflicted Jon Seymour
2011-04-23  7:22 ` [PATCH 19/23] rebasing: add tests Jon Seymour
2011-04-23  7:22 ` [PATCH 20/23] test: git test cleanups Jon Seymour
2011-04-23  7:22 ` [PATCH 21/23] Introduce git-atomic Jon Seymour
2011-04-23  7:22 ` [PATCH 22/23] Introduce git base Jon Seymour
2011-04-23  7:22 ` [PATCH 23/23] Introduce support for the git-work command Jon Seymour
2011-04-23  9:13 ` [PATCH 00/23] RFC: Introducing git-test, git-atomic, git-base and git-work Peter Baumann
2011-04-23 17:16   ` Jon Seymour
2011-04-23 18:37     ` Jon Seymour
2011-04-24 15:47       ` Jon Seymour

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=1303543372-77843-3-git-send-email-jon.seymour@gmail.com \
    --to=jon.seymour@gmail.com \
    --cc=git@vger.kernel.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).