git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 02/23] Introduce --unstaged.

From
Jon Seymour <jon.seymour@gmail.com>
Date
Apr 23, 2011, 07:22 UTC
Message-ID
<1303543372-77843-3-git-send-email-jon.seymour@gmail.com>
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
Previous: Drew NorthupNext: Jon Seymour
Message 4 of 29 in “RFC: Introducing git-test, git-atomic, git-base and git-work”
  1. 00/23 RFC: Introducing git-test, git-atomic, git-base and git-workJon Seymour, Apr 23, 2011
  2. 01/23 Introduce git-test.sh and git-test-lib.shJon Seymour, Apr 23, 2011
  3. Drew NorthupApr 27, 2011
  4. 02/23 Introduce --unstaged.Jon Seymour, Apr 23, 2011
  5. 03/23 Introduce --stagedJon Seymour, Apr 23, 2011
  6. 04/23 Introduce --untracked.Jon Seymour, Apr 23, 2011
  7. 05/23 Introduce --conflictedJon Seymour, Apr 23, 2011
  8. 06/23 Introduce --rebasingJon Seymour, Apr 23, 2011
  9. 07/23 Introduce --detachedJon Seymour, Apr 23, 2011
  10. 08/23 Introduce --branch-existsJon Seymour, Apr 23, 2011
  11. 09/23 Introduce --tag-existsJon Seymour, Apr 23, 2011
  12. 10/23 Introduce --ref-existsJon Seymour, Apr 23, 2011
  13. 11/23 Introduce --commit-exists.Jon Seymour, Apr 23, 2011
  14. 12/23 Introduce --checked-outJon Seymour, Apr 23, 2011
  15. 13/23 Introduce --reachableJon Seymour, Apr 23, 2011
  16. 14/23 Introduce --tree-same.Jon Seymour, Apr 23, 2011
  17. 15/23 Introduce --sameJon Seymour, Apr 23, 2011
  18. 16/23 miscJon Seymour, Apr 23, 2011
  19. 17/23 whitespace fix.Jon Seymour, Apr 23, 2011
  20. 18/23 tests --conflicted.Jon Seymour, Apr 23, 2011
  21. 19/23 rebasing: add testsJon Seymour, Apr 23, 2011
  22. 20/23 test: git test cleanups.Jon Seymour, Apr 23, 2011
  23. 21/23 Introduce git-atomic.Jon Seymour, Apr 23, 2011
  24. 22/23 Introduce git base.Jon Seymour, Apr 23, 2011
  25. 23/23 Introduce support for the git-work command.Jon Seymour, Apr 23, 2011
  26. Peter BaumannApr 23, 2011
  27. Jon SeymourApr 23, 2011
  28. Jon SeymourApr 23, 2011
  29. Jon SeymourApr 24, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.