FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Minor improvements for branch subcommand by JohanMabille · Pull Request #24 · QuantStack/git2cpp · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .cpp  (1) .hpp  (1) .py  (1) All 3 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
34 changes: 21 additions & 13 deletions src/subcommand/branch_subcommand.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,7 @@ void branch_subcommand::run()

if (m_list_flag || m_branch_name.empty())
{
auto head_name = repo.head().short_name();
std::cout << "* " << head_name << std::endl;
git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL);
auto iter = repo.iterate_branches(type);
auto br = iter.next();
while (br)
{
if (br->name() != head_name)
{
std::cout << " " << br->name() << std::endl;
}
br = iter.next();
}
run_list(repo);
}
else if (m_deletion_flag)
{
Expand All @@ -49,6 +37,26 @@ void branch_subcommand::run()
}
}

void branch_subcommand::run_list(const repository_wrapper& repo)
{
auto head_name = repo.head().short_name();
git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL);
auto iter = repo.iterate_branches(type);
auto br = iter.next();
while (br)
{
if (br->name() != head_name)
{
std::cout << " " << br->name() << std::endl;
}
else
{
std::cout << "* " << br->name() << std::endl;
}
br = iter.next();
}
}

void branch_subcommand::run_deletion(repository_wrapper& repo)
{
auto branch = repo.find_branch(m_branch_name);
Expand Down
1 change: 1 addition & 0 deletions src/subcommand/branch_subcommand.hpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class branch_subcommand

private:

void run_list(const repository_wrapper& repo);
void run_deletion(repository_wrapper& repo);
void run_creation(repository_wrapper& repo);

Expand Down
2 changes: 1 addition & 1 deletion test/test_branch.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_branch_create_delete(rename_git, git2cpp_path):
subprocess.run(create_cmd, capture_output=True, cwd="test/data/status_data", text=True)
list_cmd = [git2cpp_path, 'branch']
p = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True)
assert(p.stdout == '* main\n foregone\n')
assert(p.stdout == ' foregone\n* main\n')
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
subprocess.run(del_cmd, capture_output=True, cwd="test/data/status_data", text=True)
p2 = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True)
Expand Down

Back | FazBrowse Home | New Git URL