Skip to content

Add basic git init functionality #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 29, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Use correct run-time path to git2cpp binary
  • Loading branch information
ianthomas23 committed May 29, 2025
commit f0ea04f26a9be4c162ca1ff6efedc2aaaa258879
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'
8 changes: 4 additions & 4 deletions test/test_git.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@


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


def test_error_on_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 p.stdout == b''
Expand Down
27 changes: 8 additions & 19 deletions test/test_init.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
import os
from pathlib import Path
import pytest
import subprocess


# 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)


def test_init_in_directory(tmp_path):
def test_init_in_directory(git2cpp_path, tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []

cmd = ['/Users/iant/github/git2cpp/build/git2cpp', 'init', '--bare', str(tmp_path)]
cmd = [git2cpp_path, 'init', '--bare', str(tmp_path)]
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 0
assert p.stdout == b''
Expand All @@ -30,12 +19,12 @@ def test_init_in_directory(tmp_path):
# TODO: check this is a valid git repo


def test_init_in_cwd(tmp_path, run_in_tmp_path):
def test_init_in_cwd(git2cpp_path, tmp_path, run_in_tmp_path):
# tmp_path exists and is empty.
assert list(tmp_path.iterdir()) == []
assert Path.cwd() == tmp_path

cmd = ['/Users/iant/github/git2cpp/build/git2cpp', 'init', '--bare']
cmd = [git2cpp_path, 'init', '--bare']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 0
assert p.stdout == b''
Expand All @@ -51,16 +40,16 @@ def test_init_in_cwd(tmp_path, run_in_tmp_path):
# TODO: Test without bare flag.


def test_error_on_unknown_option():
cmd = ['build/git2cpp', 'init', '--unknown']
def test_error_on_unknown_option(git2cpp_path):
cmd = [git2cpp_path, 'init', '--unknown']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 1
assert p.stdout == b''
assert p.stderr.startswith(b"The following argument was not expected: --unknown")


def test_error_on_repeated_directory():
cmd = ['build/git2cpp', 'init', 'abc', 'def']
def test_error_on_repeated_directory(git2cpp_path):
cmd = [git2cpp_path, 'init', 'abc', 'def']
p = subprocess.run(cmd, capture_output=True)
assert p.returncode == 1
assert p.stdout == b''
Expand Down