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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions src/subcommand/branch_subcommand.cpp
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
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
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