From c351389de5a82cbe76064bbb21abc3239e016baf Mon Sep 17 00:00:00 2001 From: woblight Date: Sun, 11 Aug 2019 11:57:07 +0200 Subject: [PATCH] If a detached head is originated from a branch, it will now detect the remote branch to check for updates --- addon.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/addon.cpp b/addon.cpp index 65d1b34..e856963 100644 --- a/addon.cpp +++ b/addon.cpp @@ -119,6 +119,32 @@ void Addon::scanBranches() git_reference_free(ref); } git_branch_iterator_free(iter); + if (data.cb.isEmpty()) { + git_reflog *reflog; + if (!git_reflog_read(&reflog, m_repo.get(), "HEAD")) { + for (size_t i = 0; i < git_reflog_entrycount(reflog); i++) { + auto entry = git_reflog_entry_byindex(reflog, i); + QRegExp rex("checkout: moving from \\S+ to (.*)"); + if (rex.indexIn(git_reflog_entry_message(entry)) != -1) { + auto f = &git_branch_upstream_remote; + git_branch_lookup(&ref, m_repo.get(), rex.cap(1).toLocal8Bit(), GIT_BRANCH_LOCAL); + if (!ref) { + f = &git_branch_remote_name; + git_branch_lookup(&ref, m_repo.get(), rex.cap(1).toLocal8Bit(), GIT_BRANCH_REMOTE); + } + if (!ref) break; + git_buf buf = GIT_BUF_INIT_CONST(0, nullptr); + if (!f(&buf, m_repo.get(), git_reference_name(ref))) { + data.cr = buf.ptr; + data.cb = rex.cap(1); + } + git_buf_dispose(&buf); + git_reference_free(ref); + break; + } + } + } + } return data; },[this](auto data){ setRemote(data.cr);