Skip to content

Commit 5cfa05e

Browse files
committed
fix 'add --all'
1 parent ef291ed commit 5cfa05e

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

src/utils/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class wrapper_base
3333
wrapper_base& operator=(wrapper_base&& rhs)
3434
{
3535
std::swap(p_resource, rhs.p_resource);
36-
return this;
36+
return *this;
3737
}
3838

3939
operator resource_type*() const noexcept

src/wrapper/index_wrapper.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#include "../utils/git_exception.hpp"
33
#include "../wrapper/repository_wrapper.hpp"
44

5+
#include <iostream>
6+
57
index_wrapper::~index_wrapper()
68
{
79
git_index_free(p_resource);
@@ -22,6 +24,8 @@ void index_wrapper::add_entry(const git_index_entry* entry)
2224

2325
void index_wrapper::add_all()
2426
{
25-
git_strarray array = {0}; // array of strings, array of path patterns
27+
const char* patterns[] = {"."};
28+
git_strarray array{(char**)patterns, 1};
2629
throwIfError(git_index_add_all(*this, &array, 0, NULL, NULL));
30+
throwIfError(git_index_write(*this));
2731
}

test/data/status_data/embeded_git/config

100644100755
File mode changed.

test/test_add.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os
2+
import subprocess
3+
4+
import pytest
5+
6+
7+
@pytest.mark.parametrize("all_flag", ["-A", "--all", "--no-ignore-removal"])
8+
def test_add(git2cpp_path, all_flag):
9+
with open("./test/mook_file.txt", "x") as f:
10+
pass
11+
f.close()
12+
13+
cmd_add = [git2cpp_path, 'add']
14+
if all_flag != "":
15+
cmd_add.append(all_flag)
16+
subprocess.run(cmd_add, capture_output=True, text=True)
17+
18+
cmd_status = [git2cpp_path, 'status', "--long"]
19+
p_status = subprocess.run(cmd_status, capture_output=True, text=True)
20+
21+
print(p_status.stdout)
22+
# assert "Changes to be committed" in p.stdout
23+
# assert "Changes not staged for commit" in p.stdout
24+
# assert "Untracked files" in p.stdout
25+
# assert "new file" in p.stdout
26+
# assert "deleted" in p.stdout
27+
# assert "modified" in p.stdout
28+
#
29+
os.remove("./test/mook_file.txt")

0 commit comments

Comments
 (0)