| 1707 | } |
| 1708 | |
| 1709 | static void wt_status_get_detached_from(struct repository *r, |
| 1710 | struct wt_status_state *state) |
| 1711 | { |
| 1712 | struct grab_1st_switch_cbdata cb; |
| 1713 | struct commit *commit; |
| 1714 | struct object_id oid; |
| 1715 | char *ref = NULL; |
| 1716 | |
| 1717 | strbuf_init(&cb.buf, 0); |
| 1718 | if (refs_for_each_reflog_ent_reverse(get_main_ref_store(r), "HEAD", grab_1st_switch, &cb) <= 0) { |
| 1719 | strbuf_release(&cb.buf); |
| 1720 | return; |
| 1721 | } |
| 1722 | |
| 1723 | if (repo_dwim_ref(r, cb.buf.buf, cb.buf.len, &oid, &ref, |
| 1724 | 1) == 1 && |
| 1725 | /* oid is a commit? match without further lookup */ |
| 1726 | (oideq(&cb.noid, &oid) || |
| 1727 | /* perhaps oid is a tag, try to dereference to a commit */ |
| 1728 | ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL && |
| 1729 | oideq(&cb.noid, &commit->object.oid)))) { |
| 1730 | const char *from = ref; |
| 1731 | if (!skip_prefix(from, "refs/tags/", &from)) |
| 1732 | skip_prefix(from, "refs/remotes/", &from); |
| 1733 | state->detached_from = xstrdup(from); |
| 1734 | } else |
| 1735 | state->detached_from = |
| 1736 | xstrdup(repo_find_unique_abbrev(r, &cb.noid, DEFAULT_ABBREV)); |
| 1737 | oidcpy(&state->detached_oid, &cb.noid); |
| 1738 | state->detached_at = !repo_get_oid(r, "HEAD", &oid) && |
| 1739 | oideq(&oid, &state->detached_oid); |
| 1740 | |
| 1741 | free(ref); |
| 1742 | strbuf_release(&cb.buf); |
| 1743 | } |
| 1744 | |
| 1745 | int wt_status_check_rebase(const struct worktree *wt, |
| 1746 | struct wt_status_state *state) |
no test coverage detected