123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- #include "gitrepository.h"
- #include <QDebug>
- #include <QFileInfo>
- #include <QDir>
- #include <gitbranch.h>
- #include <gitcommit.h>
- #include <git2.h>
- GitRepository::GitRepository(const QString& root) : QObject(nullptr)
- {
- if(git_repository_open(&m_raw, root.toUtf8().data()) != 0) {
- qDebug() << "Cannot open repository";
- close();
- return;
- }
- m_root = root;
- m_path = git_repository_workdir(m_raw);
- m_name = m_path;//TODO: replace with Human readable name
- qDebug() << "New repo:" << m_name << m_root << m_path;
- readBranches();
- }
- GitRepository::~GitRepository()
- {
- close();
- }
- void GitRepository::close()
- {
- if(m_raw) {
- git_repository_free(m_raw);
- }
- m_raw = nullptr;
- }
- void GitRepository::readBranches()
- {
- git_reference *branchRef;
- git_branch_t branchType;
- git_branch_iterator* iter;
- git_branch_iterator_new(&iter, m_raw, GIT_BRANCH_ALL);
- while(git_branch_next(&branchRef, &branchType, iter) == 0)
- {
- GitBranch* branch = new GitBranch(branchRef, branchType, this);
- m_branches.insert(branch->name(), QPointer<GitBranch>(branch));
- qDebug() << branch->name();
- qDebug() << branch->type();
- }
- }
|