reachable --- Documentation/git-test.txt | 2 + git-conditions-lib.sh | 14 ++++++ t/t1520-test.sh | 101 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 117 insertions(+), 0 deletions(-) diff --git a/Documentation/git-test.txt b/Documentation/git-test.txt index f76aa38..e28ed88 100644 --- a/Documentation/git-test.txt +++ b/Documentation/git-test.txt @@ -86,6 +86,8 @@ CONDITIONS Tests if the specified commit does (not) exist. '--checked-out'|'--not-checked-out branch':: Tests if the specified branch is (not) checked out. +'--reachable'|'--not-reachable' first second:: + Tests if the first commit is (not) reachable from the second. EXTENDING THE CONDITION LIBRARY ------------------------------- diff --git a/git-conditions-lib.sh b/git-conditions-lib.sh index 3eccc19..0223fcd 100644 --- a/git-conditions-lib.sh +++ b/git-conditions-lib.sh @@ -136,5 +136,19 @@ check_checked_out_1() } +check_reachable_2() +{ + first=$(git rev-parse --quiet --verify "$1" 2>/dev/null) || die "'$1' is not a commit" + second=$(git rev-parse --quiet --verify "$2" 2>/dev/null) || die "'$2' is not a commit" + if test "$first" = "$second" \ + -o -z "$(git rev-list -n1 "$first" ^"$second")" + then + echo "'$1' is reachable from '$2'." + else + echo "'$1' is not reachable from '$2'." + false + fi +} + fi diff --git a/t/t1520-test.sh b/t/t1520-test.sh index bb39050..3e33f8a 100755 --- a/t/t1520-test.sh +++ b/t/t1520-test.sh @@ -298,4 +298,105 @@ test_expect_success 'git test --detached # when detached' \ git test --detached ' + +test_expect_success 'git test --reachable #should fail' \ +' + test_must_fail git test --reachable +' + +test_expect_success 'git test --not-reachable #should fail' \ +' + test_must_fail git test --reachable +' + +test_expect_success 'git test --reachable A #should fail' \ +' + test_must_fail git test --reachable A +' + +test_expect_success 'git test --not-reachable A #should fail' \ +' + test_must_fail git test --not-reachable A +' + +test_expect_success 'git test --reachable does-not-exist-1 does-not-exist-2 #should fail' \ +' + test_must_fail git test --reachable does-not-exist-1 does-not-exist-2 +' + +test_expect_success 'git test --not-reachable does-not-exist-1 does-not-exist-2 #should fail' \ +' + test_must_fail git test --not-reachable does-not-exist-1 does-not-exist-2 +' + +test_expect_success 'git test --reachable does-not-exist-1 A #should fail' \ +' + test_must_fail git test --reachable does-not-exist-1 A +' + +test_expect_success 'git test --not-reachable does-not-exist-1 A #should fail' \ +' + test_must_fail git test --not-reachable does-not-exist-1 A +' + +test_expect_success 'git test --reachable A does-not-exist-2 #should fail' \ +' + test_must_fail git test --reachable A does-not-exist-2 +' + +test_expect_success 'git test --not-reachable A does-not-exist-2 #should fail' \ +' + test_must_fail git test --not-reachable A does-not-exist-2 +' + +test_expect_success 'git test --reachable A C' \ +' + git test --reachable A C +' + +test_expect_success 'git test --not-reachable A C # should fail' \ +' + test_must_fail git test --not-reachable A C +' + +test_expect_success 'git test --reachable C A # should fail' \ +' + test_must_fail git test --reachable C A +' + +test_expect_success 'git test --not-reachable C A # should fail' \ +' + git test --not-reachable C A +' + +test_expect_success 'git test --reachable C C' \ +' + git test --reachable C C +' + +test_expect_success 'git test --not-reachable C C' \ +' + test_must_fail git test --not-reachable C C +' + +test_expect_success 'git test --reachable C F' \ +' + test_must_fail git test --reachable C F +' + +test_expect_success 'git test --not-reachable C F' \ +' + git test --not-reachable C F +' + +test_expect_success 'git test --reachable F C' \ +' + test_must_fail git test --reachable F C +' + +test_expect_success 'git test --not-reachable F C' \ +' + git test --not-reachable F C +' + 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