Skip to content

Commit

Permalink
#5662: Add check whether the current branch is up to date with the tr…
Browse files Browse the repository at this point in the history
…acked remote branch
  • Loading branch information
codereader committed Jul 5, 2021
1 parent ef045b7 commit d28f089
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
6 changes: 0 additions & 6 deletions include/iuimanager.h

This file was deleted.

29 changes: 29 additions & 0 deletions plugins/vcs/Repository.cpp
Expand Up @@ -105,6 +105,35 @@ void Repository::fetchFromTrackedRemote()
remote->fetch();
}

bool Repository::isUpToDateWithRemote()
{
auto head = getHead();

if (!head)
{
rWarning() << "Could not retrieve HEAD reference from repository" << std::endl;
return false;
}

auto trackedBranch = head->getUpstream();

git_revwalk* walker;
git_revwalk_new(&walker, _repository);
git_revwalk_push_ref(walker, trackedBranch->getName().c_str());
git_revwalk_hide_head(walker);

git_oid id;
std::size_t count = 0;
while (!git_revwalk_next(&id, walker))
{
++count;
}

git_revwalk_free(walker);

return count == 0;
}

git_repository* Repository::_get()
{
return _repository;
Expand Down
2 changes: 2 additions & 0 deletions plugins/vcs/Repository.h
Expand Up @@ -45,6 +45,8 @@ class Repository final
// Performs a fetch from the remote the current branch is tracking
void fetchFromTrackedRemote();

bool isUpToDateWithRemote();

// Creates a new instance of this repository, not sharing any libgit2 handles with the original
std::shared_ptr<Repository> clone();

Expand Down
8 changes: 5 additions & 3 deletions plugins/vcs/ui/VcsStatus.h
@@ -1,5 +1,6 @@
#pragma once

#include "i18n.h"
#include "iuserinterface.h"
#include <wx/panel.h>
#include <wx/stattext.h>
Expand Down Expand Up @@ -62,7 +63,7 @@ class VcsStatus final :
return;
}

_timer.Start(1000 * 30); // 5 mins
_timer.Start(1000 * 5 * 60); // 5 mins
}

private:
Expand All @@ -85,14 +86,15 @@ class VcsStatus final :

void performFetch(std::shared_ptr<git::Repository> repository)
{
GlobalUserInterface().dispatch([this]() { _text->SetLabel("Fetching..."); });
GlobalUserInterface().dispatch([this]() { _text->SetLabel(_("Fetching...")); });

repository->fetchFromTrackedRemote();

std::lock_guard<std::mutex> guard(_fetchLock);
_fetchInProgress = false;

GlobalUserInterface().dispatch([this]() { _text->SetLabel("Up to date"); });
auto status = repository->isUpToDateWithRemote() ? _("Up to date") : _("Updates available");
GlobalUserInterface().dispatch([&]() { _text->SetLabel(status); });
}
};

Expand Down

0 comments on commit d28f089

Please sign in to comment.