0

For this project I use libgit2. I can create successful clones of Repositories. I can see changes with "git status" from the command line, but when I try to fetch changes from the Remote Repository, my program doesn't emit any errors, but doesn't work.

bool Repository::fetchRemoteRepository(QString repos)
{
    git_repository *repo = nullptr;

    int error = git_repository_open(&repo, repos.toStdString().c_str());
    if (error < 0)
    {
        const git_error *err = giterr_last();
        mError = QString(err->message);
        git_repository_free(repo);
        return false;
    }

    git_remote *remote;

    error = git_remote_lookup(&remote, repo, "origin");
    if (error < 0)
    {
        const git_error *err = giterr_last();
        mError = QString(err->message);
        git_remote_free(remote);
        git_repository_free(repo);
        return false;
    }

    error = git_remote_fetch(remote, NULL, NULL, NULL);
    if (error < 0)
    {
        const git_error *err = giterr_last();
        mError = QString(err->message);
        git_remote_free(remote);
        git_repository_free(repo);
        return false;
    }

    git_remote_free(remote);
    git_repository_free(repo);
    return true;
}

I use libgit2 0.26.0

user4581301
  • 33,082
  • 7
  • 33
  • 54
Fuel
  • 21
  • 1
  • Are you sure that `git fetch` _should_ pull data from the remote? You mention `git status` showing changes, but I'm not sure what that has to do with the state of the remote, could you explain what you mean there? – Edward Thomson Feb 27 '18 at 09:25
  • if i type "git status" then git itself says me that there are changes on the remote repository and i need to do "git pull". but i dont want to use git commandline in my program. thats why i use libgit2. i can succesfull clone a Repository with libgit2, but at the moment i cant fetch/pull Data from the Remote Repository with libgit2. – Fuel Feb 27 '18 at 11:19
  • I'm not encouraging you to run `git fetch` in your program, I'm encouraging you to use it for troubleshooting. I don't think it will fetch anything from the remote, either. That's because `git status` doesn't talk to the remote, so it doesn't know if there are changes on the remote or not. (Only `git fetch` talks to the remote.) `git status` looks at your remote tracking branch, once `git fetch` has downloaded changes, and tells you that your local branch is not up to date with your remote tracking branch. – Edward Thomson Feb 27 '18 at 11:28
  • If you want those changes, you need to merge your remote tracking branch into your local branch. https://git-scm.com/book/id/v2/Git-Branching-Remote-Branches and https://stackoverflow.com/questions/292357/what-is-the-difference-between-git-pull-and-git-fetch should elucidate. – Edward Thomson Feb 27 '18 at 11:29

0 Answers0