add detached HEAD to --all listing
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?
Signature · 1 line
Max
Quoted 1 line · Max Kirillov
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)
masterIf 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
Quoted 5 lines · Jeff King
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.
Signature · 1 line
Max
PATCH 1/1 rev-parse: include HEAD in --all output
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.
--- 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
builtin/rev-parse.c +1 -0
@@ -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 ; }
t/t1514-rev-parse-detached.sh new file +21 -0
@@ -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
t/t6018-rev-list-glob.sh +2 -2
@@ -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/*' '
Signature · 1 line
2.0.1.1697.g73c6810
Re: [PATCH] rev-parse: include HEAD in --all output
Quoted 7 lines · 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.shwhich 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
Re: [PATCH] rev-parse: include HEAD in --all output
Quoted 11 lines · Jeff King
Quoted 8 lines · 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.shwhich relied on exact list of returned hashes.
Quoted 8 lines
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.cparser 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?
Signature · 1 line
Max
Re: [PATCH] rev-parse: include HEAD in --all output
Quoted 2 lines · Max Kirillov
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.
Re: [PATCH] rev-parse: include HEAD in --all output
Quoted 3 lines · Junio C Hamano
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.
Signature · 1 line
Max