Commits

Greg Ward committed 5c1398e

git: fix %r implementation to work if not at a branch head.
(If .git/HEAD does not look like a branch name, assume it is a commit ID.)

Comments (0)

Files changed (2)

                 found_branch = 1;
             }
             else {
+                /* if it's not a branch name, assume it is a commit ID */
                 debug(".git/HEAD doesn't look like a head ref: unknown branch");
                 result->branch = "(unknown)";
+                result->revision = strndup(buf, 12); /* XXX mem leak! */
             }
             if (context->options->show_revision && found_branch) {
                 char buf[1024];

tests/test-simple

 
     echo 3f786850e387550fdab836ed7e6dc881de23001b > .git/HEAD
     assert_vcprompt "git nobranch" "(unknown)"
-
-    # XXX this case not handled yet
-    #assert_vcprompt "git nobranch (show rev)" "(unknown):3f786850e385" "%b:%r"
+    assert_vcprompt "git nobranch (show rev)" "(unknown):3f786850e387" "%b:%r"
 
     echo "ref: refs/heads/foo" > .git/HEAD
     assert_vcprompt "git branch" "git:foo" "%n:%b"