* Extract branch information from rebase/bisect */
| 1643 | * Extract branch information from rebase/bisect |
| 1644 | */ |
| 1645 | static char *get_branch(const struct worktree *wt, const char *path) |
| 1646 | { |
| 1647 | struct strbuf sb = STRBUF_INIT; |
| 1648 | struct object_id oid; |
| 1649 | const char *branch_name; |
| 1650 | |
| 1651 | if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0) |
| 1652 | goto got_nothing; |
| 1653 | |
| 1654 | while (sb.len && sb.buf[sb.len - 1] == '\n') |
| 1655 | strbuf_setlen(&sb, sb.len - 1); |
| 1656 | if (!sb.len) |
| 1657 | goto got_nothing; |
| 1658 | if (skip_prefix(sb.buf, "refs/heads/", &branch_name)) |
| 1659 | strbuf_remove(&sb, 0, branch_name - sb.buf); |
| 1660 | else if (starts_with(sb.buf, "refs/")) |
| 1661 | ; |
| 1662 | else if (!get_oid_hex(sb.buf, &oid)) { |
| 1663 | strbuf_reset(&sb); |
| 1664 | strbuf_add_unique_abbrev(&sb, &oid, DEFAULT_ABBREV); |
| 1665 | } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */ |
| 1666 | goto got_nothing; |
| 1667 | else /* bisect */ |
| 1668 | ; |
| 1669 | return strbuf_detach(&sb, NULL); |
| 1670 | |
| 1671 | got_nothing: |
| 1672 | strbuf_release(&sb); |
| 1673 | return NULL; |
| 1674 | } |
| 1675 | |
| 1676 | struct grab_1st_switch_cbdata { |
| 1677 | struct strbuf buf; |
no test coverage detected