cppgit2 icon indicating copy to clipboard operation
cppgit2 copied to clipboard

How to stage all files by mask?

Open MasterGroosha opened this issue 5 years ago • 0 comments
trafficstars

Hello, I'm having issues staging all files in repo (similar to git add .)

What I see in stdout:

terminate called after throwing an instance of 'std::logic_error'
  what():  basic_string::_M_construct null not valid

My code: mod_git.h

#include <cppgit2/repository.hpp>

class GitWorker {
public:
    GitWorker(const std::string &path);
    void StageAll();
    
private:
    cppgit2::repository m_Repo;
};

mod_git.cpp

#include "mod_git.h"
#include <string>
#include <vector>
#include <iostream>

using namespace std;

GitWorker::GitWorker(const string &path)
    : m_Repo(cppgit2::repository::open(path)) 
    {
    }

void GitWorker::StageAll() {
    auto index = m_Repo.index();
    const vector<string> test = {"*"};
    index.add_entries_that_match(test, cppgit2::index::add_option::force, NULL);
}

main.cpp

int main(int argc, char* argv[]) {
    GitWorker git = GitWorker(".");
    update_text(); // writes something to file
    git.StageAll();
    return 0;
}

MasterGroosha avatar Jun 11 '20 11:06 MasterGroosha