Add basic `git init` functionality by ianthomas23 · Pull Request #7 · QuantStack/git2cpp · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/subcommand/init_subcommand.cpp
2 changes: 2 additions & 0 deletions src/subcommand/init_subcommand.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <string>
#include "base_subcommand.hpp"

class InitSubcommand : public BaseSubcommand
Expand All @@ -10,4 +11,5 @@ class InitSubcommand : public BaseSubcommand

private:
bool bare;
std::string directory;
};
13 changes: 3 additions & 10 deletions src/wrapper/repository_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@ RepositoryWrapper::~RepositoryWrapper()
}
}

void RepositoryWrapper::init(bool bare)
void RepositoryWrapper::init(const std::string& directory, bool bare)
{
std::cout << "repo init - start" << std::endl;

// what if it is already initialised???

// convert error code to exception
std::string path = "repo";
throwIfError(git_repository_init(&_repo, path.c_str(), bare));

std::cout << "repo init - end " << std::endl;
// what if it is already initialised? Throw exception or delete and recreate?
throwIfError(git_repository_init(&_repo, directory.c_str(), bare));
}
2 changes: 1 addition & 1 deletion src/wrapper/repository_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class RepositoryWrapper : public BaseWrapper

virtual ~RepositoryWrapper();

void init(bool bare);
void init(const std::string& directory, bool bare);

private:
git_repository *_repo;
Expand Down
17 changes: 17 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from pathlib import Path
import pytest


# Fixture to run test in current tmp_path
@pytest.fixture
def run_in_tmp_path(tmp_path):
original_cwd = os.getcwd()
os.chdir(tmp_path)
yield
os.chdir(original_cwd)


@pytest.fixture(scope='session')
def git2cpp_path():
return Path(__file__).parent.parent / 'build' / 'git2cpp'
18 changes: 11 additions & 7 deletions test/test_git.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import pytest
import subprocess

def test_version():
cmd = ['build/git2cpp', '-v']

@pytest.mark.parametrize("arg", ['-v', '--version'])
def test_version(git2cpp_path, arg):
cmd = [git2cpp_path, arg]
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 0
assert len(p.stderr) == 0
assert p.stderr == b''
assert p.stdout.startswith(b'git2cpp ')

def test_unknown_option():
cmd = ['build/git2cpp', '--unknown']

def test_error_on_unknown_option(git2cpp_path):
cmd = [git2cpp_path, '--unknown']
p = subprocess.run(cmd, capture_output=True)
#assert p.returncode == 1
assert len(p.stdout) == 0
assert p.returncode == 1
assert p.stdout == b''
assert p.stderr.startswith(b"The following argument was not expected: --unknown")
56 changes: 56 additions & 0 deletions test/test_init.py