| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -230,7 +230,9 @@ void log_subcommand::print_commit(repository_wrapper& repo, const commit_wrapper | |||
| 230 | 230 | ||
| 231 | 231 | std::string message = commit.message(); | |
| 232 | 232 | while (!message.empty() && message.back() == '\n') | |
| 233 | + { | ||
| 233 | 234 | message.pop_back(); | |
| 235 | + } | ||
| 234 | 236 | ||
| 235 | 237 | if (oneline) | |
| 236 | 238 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,10 +8,9 @@ revparse_subcommand::revparse_subcommand(const libgit2_object&, CLI::App& app) | |||
| 8 | 8 | ||
| 9 | 9 | auto* bare_opt = sub->add_flag("--is-bare-repository", m_is_bare_repository_flag, "When the repository is bare print \"true\", otherwise \"false\"."); | |
| 10 | 10 | auto* shallow_opt = sub->add_flag("--is-shallow-repository", m_is_shallow_repository_flag, "When the repository is shallow print \"true\", otherwise \"false\"."); | |
| 11 | + auto* rev_opt = sub->add_option("<rev>", m_revisions, "Revision(s) to parse (e.g. HEAD, main, HEAD~1, dae86e, ...)"); | ||
| 11 | 12 | ||
| 12 | - sub->add_option("<rev>", m_revisions, "Revision(s) to parse (e.g. HEAD, main, HEAD~1, dae86e, ...)"); | ||
| 13 | - | ||
| 14 | - sub->parse_complete_callback([this, sub, bare_opt, shallow_opt]() { | ||
| 13 | + sub->parse_complete_callback([this, sub, bare_opt, shallow_opt, rev_opt]() { | ||
| 15 | 14 | for (CLI::Option* opt : sub->parse_order()) | |
| 16 | 15 | { | |
| 17 | 16 | if (opt == bare_opt) | |
@@ -22,6 +21,10 @@ revparse_subcommand::revparse_subcommand(const libgit2_object&, CLI::App& app) | |||
| 22 | 21 | { | |
| 23 | 22 | m_queries_in_order.push_back("is_shallow"); | |
| 24 | 23 | } | |
| 24 | + else if (opt == rev_opt) | ||
| 25 | + { | ||
| 26 | + m_queries_in_order.push_back("is_rev"); | ||
| 27 | + } | ||
| 25 | 28 | } | |
| 26 | 29 | }); | |
| 27 | 30 | ||
@@ -33,6 +36,7 @@ void revparse_subcommand::run() | |||
| 33 | 36 | auto directory = get_current_git_path(); | |
| 34 | 37 | auto repo = repository_wrapper::open(directory); | |
| 35 | 38 | ||
| 39 | + size_t i = 0; | ||
| 36 | 40 | if (!m_queries_in_order.empty()) | |
| 37 | 41 | { | |
| 38 | 42 | for (const auto& q : m_queries_in_order) | |
@@ -45,27 +49,25 @@ void revparse_subcommand::run() | |||
| 45 | 49 | { | |
| 46 | 50 | std::cout << std::boolalpha << repo.is_shallow() << std::endl; | |
| 47 | 51 | } | |
| 48 | - } | ||
| 49 | - return; | ||
| 50 | - } | ||
| 52 | + if (q == "is_rev") | ||
| 53 | + { | ||
| 54 | + const auto& rev = m_revisions[i]; | ||
| 55 | + auto obj = repo.revparse_single(rev.c_str()); | ||
| 51 | 56 | ||
| 52 | - if (!m_revisions.empty()) | ||
| 53 | - { | ||
| 54 | - for (const auto& rev : m_revisions) | ||
| 55 | - { | ||
| 56 | - auto obj = repo.revparse_single(rev.c_str()); | ||
| 57 | + if (!obj.has_value()) | ||
| 58 | + { | ||
| 59 | + throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT); | ||
| 60 | + } | ||
| 57 | 61 | ||
| 58 | - if (!obj.has_value()) | ||
| 59 | - { | ||
| 60 | - throw git_exception("bad revision '" + rev + "'", git2cpp_error_code::BAD_ARGUMENT); | ||
| 61 | - return; | ||
| 62 | + auto oid = obj.value().oid(); | ||
| 63 | + std::cout << git_oid_tostr_s(&oid) << std::endl; | ||
| 64 | + i += 1; | ||
| 62 | 65 | } | |
| 63 | - | ||
| 64 | - auto oid = obj.value().oid(); | ||
| 65 | - std::cout << git_oid_tostr_s(&oid) << std::endl; | ||
| 66 | 66 | } | |
| 67 | - return; | ||
| 68 | 67 | } | |
| 69 | - | ||
| 70 | - std::cout << "revparse only supports --is-bare-repository, --is-shallow-repository and parsing revisions for now" << std::endl; | ||
| 68 | + else | ||
| 69 | + { | ||
| 70 | + std::cout << "revparse only supports --is-bare-repository, --is-shallow-repository and parsing revisions for now" << std::endl; | ||
| 71 | + } | ||
| 72 | + return; | ||
| 71 | 73 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,6 +70,41 @@ def test_revparse_multiple_revs(repo_init_with_commit, git2cpp_path, tmp_path): | |||
| 70 | 70 | assert p.returncode == 0 | |
| 71 | 71 | ||
| 72 | 72 | lines = p.stdout.splitlines() | |
| 73 | + print() | ||
| 73 | 74 | assert len(lines) == 2 | |
| 74 | 75 | assert all(len(x) == 40 for x in lines) | |
| 75 | 76 | assert lines[0] != lines[1] | |
| 77 | + | ||
| 78 | + | ||
| 79 | + def test_revparse_multiple_opts(git2cpp_path, tmp_path, run_in_tmp_path): | ||
| 80 | + """Test the options are printed in order""" | ||
| 81 | + url = "https://github.com/xtensor-stack/xtl.git" | ||
| 82 | + cmd = [git2cpp_path, "clone", "--depth", "2", url] | ||
| 83 | + p = subprocess.run(cmd, capture_output=True, text=True, cwd=tmp_path) | ||
| 84 | + assert p.returncode == 0 | ||
| 85 | + assert (tmp_path / "xtl").exists() | ||
| 86 | + | ||
| 87 | + xtl_path = tmp_path / "xtl" | ||
| 88 | + | ||
| 89 | + p = subprocess.run( | ||
| 90 | + [ | ||
| 91 | + git2cpp_path, | ||
| 92 | + "rev-parse", | ||
| 93 | + "HEAD", | ||
| 94 | + "--is-shallow-repository", | ||
| 95 | + "--is-bare-repository", | ||
| 96 | + "HEAD~1", | ||
| 97 | + ], | ||
| 98 | + capture_output=True, | ||
| 99 | + text=True, | ||
| 100 | + cwd=xtl_path, | ||
| 101 | + ) | ||
| 102 | + assert p.returncode == 0 | ||
| 103 | + | ||
| 104 | + lines = p.stdout.splitlines() | ||
| 105 | + assert len(lines) == 4 | ||
| 106 | + assert len(lines[0]) == 40 | ||
| 107 | + assert len(lines[3]) == 40 | ||
| 108 | + assert lines[0] != lines[1] | ||
| 109 | + assert "true" in lines[1] | ||
| 110 | + assert "false" in lines[2] | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments