git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Kirillov <max@max630.net>
To: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Cc: Paul Mackerras <paulus@samba.org>,
	git@vger.kernel.org, Max Kirillov <max@max630.net>
Subject: [PATCH] rev-parse: include HEAD in --all output
Date: Sun, 31 Aug 2014 01:24:48 +0300	[thread overview]
Message-ID: <1409437488-25233-1-git-send-email-max@max630.net> (raw)
In-Reply-To: <CAF7_NFRz6Zc-wTDSFdkW4N2wRATZ8-g05j6sFu1t7DB0X72dkg@mail.gmail.com>

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@max630.net>
---
 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

  reply	other threads:[~2014-08-30 22:34 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-27 14:18 [RFC] add detached HEAD to --all listing Max Kirillov
2014-08-27 14:22 ` Jeff King
2014-08-27 14:33   ` Max Kirillov
2014-08-30 22:24     ` Max Kirillov [this message]
2014-08-31 15:30       ` [PATCH] rev-parse: include HEAD in --all output Jeff King
2014-08-31 21:36         ` Max Kirillov
2014-09-02 16:59           ` Junio C Hamano
2014-09-03 16:18             ` Max Kirillov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409437488-25233-1-git-send-email-max@max630.net \
    --to=max@max630.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=paulus@samba.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).