On Thu, Sep 10, 2009 at 10:16:18AM -0400, Jeff King wrote:
And we may want to add a test for HEAD, as well.
Also, I seem to be able to stimulate a segfault on a detached HEAD, but
I haven't investigated it yet.
Found it. We should probably squash this in:
diff --git a/sha1_name.c b/sha1_name.c
index a886846..ef4ec11 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -276,7 +276,7 @@ static char *substitute_branch_name(const char **string, int *len)
struct branch *tracking = branch_get(*ref ? ref : NULL);
free(ref);
- if (tracking->merge && tracking->merge[0]->dst) {
+ if (tracking && tracking->merge && tracking->merge[0]->dst) {
*string = xstrdup(tracking->merge[0]->dst);
*len = strlen(*string);
return (char *)*string;diff --git a/t/t1506-rev-parse-tracked.sh b/t/t1506-rev-parse-tracked.sh
index 89193e1..2be5b75 100755
--- a/t/t1506-rev-parse-tracked.sh
+++ b/t/t1506-rev-parse-tracked.sh
@@ -61,4 +61,15 @@ test_expect_success '<branch>@{t}@{1} resolves correctly' '
test 5 = $(commit_subject my-side@{t}@{1})
'
+test_expect_success 'HEAD@{t} dereferences HEAD' '
+ (cd clone && git checkout master) &&
+ test refs/remotes/origin/master = "$(full_name HEAD@{t})"
+'
+
+test_expect_success 'HEAD@{t} and @{t} on detached HEAD fail' '
+ (cd clone && git checkout master^0) &&
+ test_must_fail full_name @{t} &&
+ test_must_fail full_name HEAD@{t}
+'
+
test_done