| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| build/ | ||
| __pycache__/ | ||
| .cache/ | ||
| compile_commands.json |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -4,7 +4,7 @@ channels: | |
| dependencies: | ||
| - cli11 | ||
| - libgit2 | ||
| - meson | ||
| - cmake | ||
| - pkg-config | ||
| - python | ||
| - pytest | ||
| Expand Down | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| #include <git2.h> | ||
|
|
||
| #include "add_subcommand.hpp" | ||
| #include "../wrapper/index_wrapper.hpp" | ||
| #include "../wrapper/repository_wrapper.hpp" | ||
|
|
||
|
|
||
| add_subcommand::add_subcommand(const libgit2_object&, CLI::App& app) | ||
| { | ||
| auto *sub = app.add_subcommand("add", "Add file contents to the index"); | ||
|
|
||
| sub->add_option("files", m_add_files, "Files to add"); | ||
|
|
||
| sub->add_flag("-A,--all,--no-ignore-removal", m_all_flag, ""); | ||
| // sub->add_flag("-n,--dryrun", dryrun_flag, ""); | ||
| // sub->add_flag("-u,--update", update_flag, ""); | ||
| // sub->add_flag("-v,--verbose", verbose_flag, ""); | ||
|
|
||
| sub->callback([this]() { this->run(); }); | ||
| }; | ||
|
|
||
|
|
||
| void add_subcommand::run() | ||
| { | ||
| auto directory = get_current_git_path(); | ||
| auto bare = false; | ||
| auto repo = repository_wrapper::init(directory, bare); | ||
|
|
||
| index_wrapper index = repo.make_index(); | ||
|
|
||
| if (m_all_flag) | ||
| { | ||
| index.add_all(); | ||
| } | ||
| else | ||
| { | ||
| index.add_entries(m_add_files); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #pragma once | ||
|
|
||
| #include <CLI/CLI.hpp> | ||
|
|
||
| #include "../utils/common.hpp" | ||
|
|
||
| class add_subcommand | ||
| { | ||
| public: | ||
|
|
||
| explicit add_subcommand(const libgit2_object&, CLI::App& app); | ||
| void run(); | ||
|
|
||
| private: | ||
| bool m_all_flag = false; | ||
| std::vector<std::string> m_add_files; | ||
| }; |
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #include "index_wrapper.hpp" | ||
| #include "../utils/git_exception.hpp" | ||
| #include "../wrapper/repository_wrapper.hpp" | ||
|
|
||
| #include <vector> | ||
|
|
||
| index_wrapper::~index_wrapper() | ||
| { | ||
| git_index_free(p_resource); | ||
| p_resource=nullptr; | ||
| } | ||
|
|
||
| index_wrapper index_wrapper::init(repository_wrapper& rw) | ||
| { | ||
| index_wrapper index; | ||
| throwIfError(git_repository_index(&(index.p_resource), rw)); | ||
| return index; | ||
| } | ||
|
|
||
| void index_wrapper::add_entries(std::vector<std::string> patterns) | ||
| { | ||
| add_impl(std::move(patterns)); | ||
| } | ||
|
|
||
| void index_wrapper::add_all() | ||
| { | ||
| add_impl({{"."}}); | ||
| } | ||
|
|
||
| void index_wrapper::add_impl(std::vector<std::string> patterns) | ||
| { | ||
| git_strarray_wrapper array{patterns}; | ||
| throwIfError(git_index_add_all(*this, array, 0, NULL, NULL)); | ||
| throwIfError(git_index_write(*this)); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include <git2.h> | ||
|
|
||
| #include "../utils/common.hpp" | ||
|
|
||
| class repository_wrapper; | ||
|
|
||
| class index_wrapper : public wrapper_base<git_index> | ||
| { | ||
| public: | ||
|
|
||
| ~index_wrapper(); | ||
|
|
||
| index_wrapper(index_wrapper&&) = default; | ||
| index_wrapper& operator=(index_wrapper&&) = default; | ||
|
|
||
| static index_wrapper init(repository_wrapper& rw); | ||
|
|
||
| void add_entries(std::vector<std::string> patterns); | ||
| void add_all(); | ||
|
|
||
|
|
||
| private: | ||
|
|
||
| index_wrapper() = default; | ||
| void add_impl(std::vector<std::string> patterns); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import os | ||
| import subprocess | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("all_flag", ["", "-A", "--all", "--no-ignore-removal"]) | ||
| def test_add(git2cpp_path, all_flag): | ||
| with open("./test/mook_file.txt", "x") as f: | ||
| pass | ||
|
|
||
| with open("./test/mook_file_2.txt", "x") as f: | ||
| pass | ||
|
|
||
| cmd_add = [git2cpp_path, 'add'] | ||
| if all_flag != "": | ||
| cmd_add.append(all_flag) | ||
| else: | ||
| cmd_add.append("test/mook_file.txt") | ||
| subprocess.run(cmd_add, capture_output=True, text=True) | ||
|
|
||
| cmd_status = [git2cpp_path, 'status', "--long"] | ||
| p_status = subprocess.run(cmd_status, capture_output=True, text=True) | ||
|
|
||
| assert "Changes to be committed" in p_status.stdout | ||
| assert "new file" in p_status.stdout | ||
| if all_flag != "": | ||
| assert "Untracked files" not in p_status.stdout | ||
| else: | ||
| assert "Untracked files" in p_status.stdout | ||
|
|
||
| os.remove("./test/mook_file.txt") | ||
| os.remove("./test/mook_file_2.txt") | ||
|
|
||
| # undo the add, to leave the test directory at the end the same as it was at the start | ||
| subprocess.run(cmd_add, capture_output=True, text=True) | ||
|
Comment thread
Copy link
Copy Markdown
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityIs 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.
Sorry, something went wrong.
All reactions
Copy link
Copy Markdown
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityYes, that's the reason why ! I'll write a comment.
Sorry, something went wrong.
All reactions
|
||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityWhy updating the version?
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThe 0.0.2 has been released but we forgot to change it there, so it's to catch up.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.