test_must_fail: --not-staged --- Documentation/git-test.txt | 3 ++ git-conditions-lib.sh | 11 ++++++++++ t/t1520-test.sh | 45 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 0 deletions(-) diff --git a/Documentation/git-test.txt b/Documentation/git-test.txt index 4b2c129..9264c90 100644 --- a/Documentation/git-test.txt +++ b/Documentation/git-test.txt @@ -66,6 +66,9 @@ CONDITIONS ---------- '--unstaged'|'--not-unstaged':: Tests if there are (not) any unstaged changes in the working tree. +'--staged'|'--not-staged':: + Tests if there are (not) any staged changes in the index. + EXTENDING THE CONDITION LIBRARY ------------------------------- diff --git a/git-conditions-lib.sh b/git-conditions-lib.sh index f9ff0b9..55b4131 100644 --- a/git-conditions-lib.sh +++ b/git-conditions-lib.sh @@ -19,5 +19,16 @@ check_unstaged_0() fi } +check_staged_0() +{ + if test $(git diff-index --cached --name-only HEAD | wc -l) -ne 0 + then + echo "There are staged files." + else + echo "There are no staged files." + false + fi +} + fi diff --git a/t/t1520-test.sh b/t/t1520-test.sh index 8543943..7438f93 100755 --- a/t/t1520-test.sh +++ b/t/t1520-test.sh @@ -216,5 +216,50 @@ test_expect_success 'git test --unstaged # when there are only staged files' \ git test --not-unstaged ' +test_expect_success 'git test --staged # should fail' \ ' + test_must_fail git test --staged +' + +test_expect_success 'git test --not-staged' \ +' + git test --not-staged +' + +test_expect_success 'git test --staged # when there are 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 --staged +' + +test_expect_success 'git test --not-staged # when there are staged files - should fail' \ +' + test_when_finished "git reset --hard HEAD && git checkout master" && + git checkout -f M^0 && + git stash apply --index STASH_STAGED && + test_must_fail git test --not-staged +' + +test_expect_success 'git test --staged # when there are only 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 --not-staged +' + +' + test_when_finished "git reset --hard HEAD && git checkout master" && + git test --not-staged --not-unstaged && + ! git test --staged && + ! git test --unstaged && + git checkout M^0 && + git stash apply --index STASH_STAGED && + git test --not-unstaged --staged && + ! git test --unstaged && + ! git test --not-staged +' + 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