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
3 changes: 1 addition & 2 deletions src/subcommand/add_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app)
void add_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto repo = repository_wrapper::open(directory);

index_wrapper index = repo.make_index();

Expand Down
3 changes: 1 addition & 2 deletions src/subcommand/commit_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
void commit_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto repo = repository_wrapper::open(directory);
auto author_committer_signatures = signature_wrapper::get_default_signature_from_env(repo);

if (m_commit_message.empty())
Expand Down
3 changes: 1 addition & 2 deletions src/subcommand/log_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ void print_commit(const commit_wrapper& commit, std::string m_format_flag)
void log_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto repo = repository_wrapper::open(directory);
// auto branch_name = repo.head().short_name();

git_revwalk* walker;
Expand Down
3 changes: 1 addition & 2 deletions src/subcommand/reset_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ reset_subcommand::reset_subcommand(const libgit2_object&, CLI::App& app)
void reset_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto repo = repository_wrapper::open(directory);

auto target = repo.revparse_single(m_commit);
if (!target)
Expand Down
3 changes: 1 addition & 2 deletions src/subcommand/status_subcommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s
void status_subcommand::run()
{
auto directory = get_current_git_path();
auto bare = false;
auto repo = repository_wrapper::init(directory, bare);
auto repo = repository_wrapper::open(directory);
auto sl = status_list_wrapper::status_list(repo);
auto branch_name = repo.head().short_name();

Expand Down
8 changes: 8 additions & 0 deletions test/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,11 @@ def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
assert "Untracked files" not in p_status.stdout
else:
assert "Untracked files" in p_status.stdout

def test_add_nogit(git2cpp_path, tmp_path):
p = tmp_path / "mook_file.txt"
p.write_text('')

cmd_add = [git2cpp_path, 'add', 'mook_file.txt']
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True)
assert p_add.returncode != 0
5 changes: 5 additions & 0 deletions test/test_branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ def test_branch_create_delete(xtl_clone, git2cpp_path, tmp_path):
p_list2 = subprocess.run(list_cmd, capture_output=True, cwd=xtl_path, text=True)
assert p_list2.returncode == 0
assert(p_list2.stdout == '* master\n')

def test_branch_nogit(git2cpp_path, tmp_path):
cmd = [git2cpp_path, 'branch']
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode != 0
5 changes: 5 additions & 0 deletions test/test_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ def test_log(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, format_
else:
assert "CommitDate" in p_log.stdout

def test_log_nogit(git_config, git2cpp_path, tmp_path):
cmd_log = [git2cpp_path, 'log']
p_log = subprocess.run(cmd_log, capture_output=True, cwd=tmp_path, text=True)
assert p_log.returncode != 0


@pytest.mark.parametrize("max_count_flag", ["", "-n", "--max-count"])
def test_max_count(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch, max_count_flag):
Expand Down
6 changes: 6 additions & 0 deletions test/test_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,9 @@ def test_reset(xtl_clone, git_config, git2cpp_path, tmp_path, monkeypatch):
p_log = subprocess.run(cmd_log_2, capture_output=True, cwd=xtl_path, text=True)
assert p_log.returncode == 0
assert "Jane Doe" not in p_log.stdout

def test_reset_nogit(git2cpp_path, tmp_path):
cmd_reset = [git2cpp_path, "reset", "--hard", "HEAD~1"]
p_reset = subprocess.run(cmd_reset, capture_output=True, cwd=tmp_path, text=True)
assert p_reset.returncode != 0

4 changes: 4 additions & 0 deletions test/test_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def test_status_new_file(xtl_clone, git2cpp_path, tmp_path, short_flag, long_fla
assert " D " in p.stdout
assert "?? " in p.stdout

def test_status_nogit(git2cpp_path, tmp_path):
cmd = [git2cpp_path, 'status']
p = subprocess.run(cmd, capture_output=True, cwd=tmp_path, text=True)
assert p.returncode != 0

@pytest.mark.parametrize("short_flag", ["", "-s", "--short"])
@pytest.mark.parametrize("long_flag", ["", "--long"])
Expand Down