[PATCH] rev-parse: include HEAD in --all output

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

 



for_each_ref() does not include it itself, and without the hash
the detached HEAD may be missed by some frontends (like gitk).

Add test which verifies the head is returned

Update test t6018-rev-list-glob.sh which relied on exact list of
returned hashes.

Signed-off-by: Max Kirillov <max@xxxxxxxxxx>
---
 builtin/rev-parse.c           |  1 +
 t/t1514-rev-parse-detached.sh | 21 +++++++++++++++++++++
 t/t6018-rev-list-glob.sh      |  4 ++--
 3 files changed, 24 insertions(+), 2 deletions(-)
 create mode 100755 t/t1514-rev-parse-detached.sh

diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
index d85e08c..42f468c 100644
--- a/builtin/rev-parse.c
+++ b/builtin/rev-parse.c
@@ -642,6 +642,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
 				continue;
 			}
 			if (!strcmp(arg, "--all")) {
+				head_ref(show_reference, NULL);
 				for_each_ref(show_reference, NULL);
 				continue;
 			}
diff --git a/t/t1514-rev-parse-detached.sh b/t/t1514-rev-parse-detached.sh
new file mode 100755
index 0000000..eeb2318
--- /dev/null
+++ b/t/t1514-rev-parse-detached.sh
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+test_description='test git rev-parse references'
+
+. ./test-lib.sh
+
+test_expect_success 'make repo' '
+	git commit --allow-empty -m commit1 &&
+	git commit --allow-empty -m commit2 &&
+	git checkout  --detach master &&
+	git commit --allow-empty -m commit3
+'
+
+head_sha1=`git rev-parse HEAD`
+
+test_expect_success 'HEAD should be listed in rev-parse --all' '
+	git rev-parse --all >all_refs &&
+	grep -q "$head_sha1" all_refs
+'
+
+test_done
diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh
index d00f7db..ba0b89c 100755
--- a/t/t6018-rev-list-glob.sh
+++ b/t/t6018-rev-list-glob.sh
@@ -134,11 +134,11 @@ test_expect_success 'rev-parse --exclude with --branches' '
 '
 
 test_expect_success 'rev-parse --exclude with --all' '
-	compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags"
+	compare rev-parse "--exclude=refs/remotes/* --all" "HEAD --branches --tags"
 '
 
 test_expect_success 'rev-parse accumulates multiple --exclude' '
-	compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches
+	compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" "HEAD --branches"
 '
 
 test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
-- 
2.0.1.1697.g73c6810

--
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]