Skip to content

feat: add add subcommand #16

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 10 commits into from
Jul 17, 2025
Merged

feat: add add subcommand #16

merged 10 commits into from
Jul 17, 2025

Conversation

SandrineP
Copy link
Collaborator

@SandrineP SandrineP commented Jul 15, 2025

Add the git add sub-command, with the --all flag.

@SandrineP SandrineP marked this pull request as ready for review July 16, 2025 13:28

void index_wrapper::add_impl(std::vector<std::string> patterns)
{
git_strarray array{new char*[patterns.size()], patterns.size()};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This leaks. I think it would be worth having a wrapper of git_strarray, that correctly manages the memory and use it here. It will be useful for other commands anyway.

@SandrineP SandrineP changed the title feat: add 'add' subcommand feat: add add subcommand Jul 16, 2025

void index_wrapper::add_impl(std::vector<std::string> patterns)
{
git_strarray_wrapper array=git_strarray_wrapper(patterns);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
git_strarray_wrapper array=git_strarray_wrapper(patterns);
git_strarray_wrapper array{patterns};

@@ -2,7 +2,7 @@

#define GIT2CPP_VERSION_MAJOR 0
#define GIT2CPP_VERSION_MINOR 0
#define GIT2CPP_VERSION_PATCH 1
#define GIT2CPP_VERSION_PATCH 2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why updating the version?

Copy link
Collaborator Author

@SandrineP SandrineP Jul 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The 0.0.2 has been released but we forgot to change it there, so it's to catch up.


private:
bool all_flag = false;
std::vector<std::string> add_files;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convention: data member names should start with m_ (or p_) so it is easy to distinguish them from local variables.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_ stands for "member" and p_ stands for what ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pointer

test/test_add.py Outdated
def test_add(git2cpp_path, all_flag):
with open("./test/mook_file.txt", "x") as f:
pass
f.close()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line isn't needed as the f will be automatically closed when the with ... block is exited. The same applies to 4 lines below.


os.remove("./test/mook_file.txt")
os.remove("./test/mook_file_2.txt")
subprocess.run(cmd_add, capture_output=True, text=True)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line just to undo the add, to leave the test directory at the end the same as it was at the start? If so can you add a comment saying this, otherwise it will look suspicious in future to have this line without any following assert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the reason why ! I'll write a comment.

Copy link
Member

@ianthomas23 ianthomas23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @SandrineP!

@ianthomas23 ianthomas23 merged commit 78f7356 into QuantStack:main Jul 17, 2025
1 check passed
@SandrineP SandrineP deleted the add_sc branch July 17, 2025 13:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants