git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC] add detached HEAD to --all listing
@ 2014-08-27 14:18 Max Kirillov
  2014-08-27 14:22 ` Jeff King
  0 siblings, 1 reply; 8+ messages in thread
From: Max Kirillov @ 2014-08-27 14:18 UTC (permalink / raw)
  To: Git Mailing List

Hello.

Could HEAD be added to list of heads while using --all switch?
Detached heads are not something very unusual and incorrect, in
submodules for example, or for some scripts. Having to specify it
additionally when I meet such checkout feels like some flaw.

What are opinions on that, could it be changed?

-- 
Max

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] add detached HEAD to --all listing
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff King @ 2014-08-27 14:22 UTC (permalink / raw)
  To: Max Kirillov; +Cc: Git Mailing List

On Wed, Aug 27, 2014 at 05:18:21PM +0300, Max Kirillov wrote:

> Could HEAD be added to list of heads while using --all switch?

To which command?

If you mean "git branch", I think the detached HEAD is already
mentioned:

  $ git branch
  * (detached from 1290ebd)
    master

If you mean "git log", I think it is included there, too:

  $ git log --decorate --oneline --all
  685450f (HEAD) more
  1290ebd (master) foo

Is there some other command you have in mind? git-push, maybe?

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFC] add detached HEAD to --all listing
  2014-08-27 14:22 ` Jeff King
@ 2014-08-27 14:33   ` Max Kirillov
  2014-08-30 22:24     ` [PATCH] rev-parse: include HEAD in --all output Max Kirillov
  0 siblings, 1 reply; 8+ messages in thread
From: Max Kirillov @ 2014-08-27 14:33 UTC (permalink / raw)
  To: Jeff King, Paul Mackerras; +Cc: Git Mailing List

On Wed, Aug 27, 2014 at 5:22 PM, Jeff King <peff@peff.net> wrote:
> If you mean "git log", I think it is included there, too:
>
>   $ git log --decorate --oneline --all
>   685450f (HEAD) more
>   1290ebd (master) foo

I meant "git log", did not know it's there. Where I actually would
like to see it in gitk --all, apparently it performs its own
filtering.

Thanks.

-- 
Max

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] rev-parse: include HEAD in --all output
  2014-08-27 14:33   ` Max Kirillov
@ 2014-08-30 22:24     ` Max Kirillov
  2014-08-31 15:30       ` Jeff King
  0 siblings, 1 reply; 8+ messages in thread
From: Max Kirillov @ 2014-08-30 22:24 UTC (permalink / raw)
  To: Junio C Hamano, Jeff King; +Cc: Paul Mackerras, git, Max Kirillov

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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] rev-parse: include HEAD in --all output
  2014-08-30 22:24     ` [PATCH] rev-parse: include HEAD in --all output Max Kirillov
@ 2014-08-31 15:30       ` Jeff King
  2014-08-31 21:36         ` Max Kirillov
  0 siblings, 1 reply; 8+ messages in thread
From: Jeff King @ 2014-08-31 15:30 UTC (permalink / raw)
  To: Max Kirillov; +Cc: Junio C Hamano, Paul Mackerras, git

On Sun, Aug 31, 2014 at 01:24:48AM +0300, Max Kirillov wrote:

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

I think the missing bit of the justification here is that "--all" _does_
include HEAD in other contexts (like in git-log), and rev-parse should
probably match it.

This is probably the right thing to do. It's possible that some caller
of rev-parse really depends on "--all" meaning "just the refs", but I
kind of doubt it. Being in sync with the revision.c parser seems saner.

-Peff

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rev-parse: include HEAD in --all output
  2014-08-31 15:30       ` Jeff King
@ 2014-08-31 21:36         ` Max Kirillov
  2014-09-02 16:59           ` Junio C Hamano
  0 siblings, 1 reply; 8+ messages in thread
From: Max Kirillov @ 2014-08-31 21:36 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, Paul Mackerras, git

On Sun, Aug 31, 2014 at 11:30:54AM -0400, Jeff King wrote:
> On Sun, Aug 31, 2014 at 01:24:48AM +0300, Max Kirillov wrote:
> 
>> 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.
> 
> I think the missing bit of the justification here is that
> "--all" _does_ include HEAD in other contexts (like in
> git-log), and rev-parse should probably match it.
> 
> This is probably the right thing to do. It's possible that
> some caller of rev-parse really depends on "--all" meaning
> "just the refs", but I kind of doubt it. Being in sync
> with the revision.c parser seems saner.

Actually, yes, this is a bit incompatible change, and while
I'm pretty sure that rev-parse returning hashes should
include detached HEAD, returning HEAD when it's called with
something like "--symbolic" might be questioned. It could
depend on the output mode (add HEAD only if printing hashes)
but this kind of logic does not look good. So maybe some
more opinions should be asked for.

btw, manpage for git-rev-parse says "Show all refs found in
refs/.", should it also be changed?

-- 
Max

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rev-parse: include HEAD in --all output
  2014-08-31 21:36         ` Max Kirillov
@ 2014-09-02 16:59           ` Junio C Hamano
  2014-09-03 16:18             ` Max Kirillov
  0 siblings, 1 reply; 8+ messages in thread
From: Junio C Hamano @ 2014-09-02 16:59 UTC (permalink / raw)
  To: Max Kirillov; +Cc: Jeff King, Paul Mackerras, git

Max Kirillov <max@max630.net> writes:

> btw, manpage for git-rev-parse says "Show all refs found in
> refs/.", should it also be changed?

I would rather see "rev-parse --all" not to include HEAD, especially
if it has been documented that way.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] rev-parse: include HEAD in --all output
  2014-09-02 16:59           ` Junio C Hamano
@ 2014-09-03 16:18             ` Max Kirillov
  0 siblings, 0 replies; 8+ messages in thread
From: Max Kirillov @ 2014-09-03 16:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Jeff King, Paul Mackerras, git

On Tue, Sep 02, 2014 at 09:59:17AM -0700, Junio C Hamano wrote:
> 
> I would rather see "rev-parse --all" not to include HEAD,
> especially if it has been documented that way.

Ok, then probably I'll want to change it in gitk.

But, with the "multiple working trees" feature, I would also
want to get other HEADs in view, even if they are detached.
I could add it to --all when it returns detached HEAD (like
in git-rev-list), but if it does not, probably some
new dedicated option should be for that purpose. Something
like "git rev-parse --heads", for example.

-- 
Max

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-09-03 16:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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     ` [PATCH] rev-parse: include HEAD in --all output Max Kirillov
2014-08-31 15:30       ` Jeff King
2014-08-31 21:36         ` Max Kirillov
2014-09-02 16:59           ` Junio C Hamano
2014-09-03 16:18             ` Max Kirillov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).