gitremote.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "gitremote.h"
  2. #include <gitauthenticator.h>
  3. #include <git2/remote.h>
  4. GitRemote::GitRemote(git_remote* raw, GitRepository* parent) : GitBase(raw, parent)
  5. {
  6. }
  7. GitRemote* GitRemote::fromName(const QString& remoteName, GitRepository* parent)
  8. {
  9. git_remote* remote = nullptr;
  10. git_remote_lookup(&remote, parent->raw(), remoteName.toUtf8().data());
  11. return new GitRemote(remote, parent);
  12. }
  13. QString GitRemote::name() const
  14. {
  15. return QString(git_remote_name(raw()));
  16. }
  17. void GitRemote::fetch()
  18. {
  19. QString reflogRecord = QString("Fetch from remote: " + name());
  20. git_fetch_options opts = GIT_FETCH_OPTIONS_INIT;
  21. opts.callbacks.update_tips = [](const char *refname, const git_oid *a, const git_oid *b, void *data) -> int { return 0; };
  22. opts.callbacks.sideband_progress = [](const char *str, int len, void *payload) -> int { return 0; };
  23. opts.callbacks.transfer_progress = [](const git_transfer_progress *stats, void *payload) -> int {
  24. qDebug() << "transferProgress: " << stats->total_objects << "/" << stats->received_objects;
  25. return 0;
  26. };
  27. opts.callbacks.credentials = [](git_cred **cred, const char *url, const char *username_from_url, unsigned int allowed_types, void *payload) -> int {
  28. qDebug() << "Url: " << url;
  29. qDebug() << "Username: " << username_from_url;
  30. qDebug() << "Allowed types: " << allowed_types;
  31. return GitAuthenticator::instance()->authenticate(reinterpret_cast<GitRemote*>(payload), cred, username_from_url, allowed_types);
  32. };
  33. opts.callbacks.payload = this;
  34. git_remote_fetch(m_raw, nullptr, &opts, reflogRecord.toLatin1().data());
  35. }