Skip to content

Commit 2a9533c

Browse files
committed
Fixed most of commands creating a git repo instead of throwing an error
1 parent f928517 commit 2a9533c

14 files changed

+33
-10
lines changed

src/subcommand/add_subcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app)
2323
void add_subcommand::run()
2424
{
2525
auto directory = get_current_git_path();
26-
auto bare = false;
27-
auto repo = repository_wrapper::init(directory, bare);
26+
auto repo = repository_wrapper::open(directory);
2827

2928
index_wrapper index = repo.make_index();
3029

src/subcommand/commit_subcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ commit_subcommand::commit_subcommand(const libgit2_object&, CLI::App& app)
1919
void commit_subcommand::run()
2020
{
2121
auto directory = get_current_git_path();
22-
auto bare = false;
23-
auto repo = repository_wrapper::init(directory, bare);
22+
auto repo = repository_wrapper::open(directory);
2423
auto author_committer_signatures = signature_wrapper::get_default_signature_from_env(repo);
2524

2625
if (m_commit_message.empty())

src/subcommand/log_subcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ void print_commit(const commit_wrapper& commit, std::string m_format_flag)
8080
void log_subcommand::run()
8181
{
8282
auto directory = get_current_git_path();
83-
auto bare = false;
84-
auto repo = repository_wrapper::init(directory, bare);
83+
auto repo = repository_wrapper::open(directory);
8584
// auto branch_name = repo.head().short_name();
8685

8786
git_revwalk* walker;

src/subcommand/reset_subcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ reset_subcommand::reset_subcommand(const libgit2_object&, CLI::App& app)
2727
void reset_subcommand::run()
2828
{
2929
auto directory = get_current_git_path();
30-
auto bare = false;
31-
auto repo = repository_wrapper::init(directory, bare);
30+
auto repo = repository_wrapper::open(directory);
3231

3332
auto target = repo.revparse_single(m_commit);
3433
if (!target)

src/subcommand/status_subcommand.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ void print_not_tracked(const std::vector<print_entry>& entries_to_print, const s
183183
void status_subcommand::run()
184184
{
185185
auto directory = get_current_git_path();
186-
auto bare = false;
187-
auto repo = repository_wrapper::init(directory, bare);
186+
auto repo = repository_wrapper::open(directory);
188187
auto sl = status_list_wrapper::status_list(repo);
189188
auto branch_name = repo.head().short_name();
190189

173 Bytes
Binary file not shown.
172 Bytes
Binary file not shown.
151 Bytes
Binary file not shown.
15 Bytes
Binary file not shown.

test/test_add.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ def test_add(xtl_clone, git2cpp_path, tmp_path, all_flag):
3232
assert "Untracked files" not in p_status.stdout
3333
else:
3434
assert "Untracked files" in p_status.stdout
35+
36+
def test_add_nogit(git2cpp_path, tmp_path):
37+
p = tmp_path / "mook_file.txt"
38+
p.write_text('')
39+
40+
cmd_add = [git2cpp_path, 'add', 'mook_file.txt']
41+
p_add = subprocess.run(cmd_add, cwd=tmp_path, text=True)
42+
assert p_add.returncode != 0

0 commit comments

Comments
 (0)