[PATCH 07/23] Introduce --detached

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

 



detached
---
 Documentation/git-test.txt |    2 ++
 git-conditions-lib.sh      |   11 +++++++++++
 t/t1520-test.sh            |   30 +++++++++++++++++++++---------
 3 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/Documentation/git-test.txt b/Documentation/git-test.txt
index e872608..501725c 100644
--- a/Documentation/git-test.txt
+++ b/Documentation/git-test.txt
@@ -74,6 +74,8 @@ CONDITIONS
 	Tests if there are (not) any merge conflicts in the index.
 '--rebasing'|'--not-rebasing'::
         Tests if a rebase is (not) in progress.
+'--detached'|'--not-detached'::
+	Tests if the head is (not) detached.
 
 EXTENDING THE CONDITION LIBRARY
 -------------------------------
diff --git a/git-conditions-lib.sh b/git-conditions-lib.sh
index 0d6e0a1..34de896 100644
--- a/git-conditions-lib.sh
+++ b/git-conditions-lib.sh
@@ -64,5 +64,16 @@ check_rebasing_0()
 	fi
 }
 
+check_detached_0()
+{
+	if ! git symbolic-ref -q HEAD >/dev/null
+	then
+		echo "HEAD is detached."
+	else
+		echo "HEAD is not detached."
+		false
+	fi
+}
+
 
 fi
diff --git a/t/t1520-test.sh b/t/t1520-test.sh
index ebff63c..bb39050 100755
--- a/t/t1520-test.sh
+++ b/t/t1520-test.sh
@@ -274,16 +274,28 @@ test_expect_success 'git test --not-untracked # when there are untracked files -
 	test_must_fail git test --not-untracked
 '
 
+test_expect_success 'git test --not-detached' \
 '
-    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 
+	git test --not-detached
+'
+
+test_expect_success 'git test --detached # should fail' \
+'
+	test_must_fail git test --detached
+'
+
+test_expect_success 'git test --not-detached # when detached, should fail' \
+'
+	test_when_finished "git checkout -f master" && 
+	git checkout HEAD^0 &&
+	test_must_fail git test --not-detached
+'
+
+test_expect_success 'git test --detached # when detached' \
+'
+	test_when_finished "git checkout -f master" && 
+	git checkout HEAD^0 &&
+	git test --detached
 '
 
 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]