Skip to content

Commit cd44cf1

Browse files
authored
Minor improvements for branch subcommand (#24)
1 parent 0c96016 commit cd44cf1

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

src/subcommand/branch_subcommand.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,7 @@ void branch_subcommand::run()
2525

2626
if (m_list_flag || m_branch_name.empty())
2727
{
28-
auto head_name = repo.head().short_name();
29-
std::cout << "* " << head_name << std::endl;
30-
git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL);
31-
auto iter = repo.iterate_branches(type);
32-
auto br = iter.next();
33-
while (br)
34-
{
35-
if (br->name() != head_name)
36-
{
37-
std::cout << " " << br->name() << std::endl;
38-
}
39-
br = iter.next();
40-
}
28+
run_list(repo);
4129
}
4230
else if (m_deletion_flag)
4331
{
@@ -49,6 +37,26 @@ void branch_subcommand::run()
4937
}
5038
}
5139

40+
void branch_subcommand::run_list(const repository_wrapper& repo)
41+
{
42+
auto head_name = repo.head().short_name();
43+
git_branch_t type = m_all_flag ? GIT_BRANCH_ALL : (m_remote_flag ? GIT_BRANCH_REMOTE : GIT_BRANCH_LOCAL);
44+
auto iter = repo.iterate_branches(type);
45+
auto br = iter.next();
46+
while (br)
47+
{
48+
if (br->name() != head_name)
49+
{
50+
std::cout << " " << br->name() << std::endl;
51+
}
52+
else
53+
{
54+
std::cout << "* " << br->name() << std::endl;
55+
}
56+
br = iter.next();
57+
}
58+
}
59+
5260
void branch_subcommand::run_deletion(repository_wrapper& repo)
5361
{
5462
auto branch = repo.find_branch(m_branch_name);

src/subcommand/branch_subcommand.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class branch_subcommand
1616

1717
private:
1818

19+
void run_list(const repository_wrapper& repo);
1920
void run_deletion(repository_wrapper& repo);
2021
void run_creation(repository_wrapper& repo);
2122

test/test_branch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_branch_create_delete(rename_git, git2cpp_path):
1313
subprocess.run(create_cmd, capture_output=True, cwd="test/data/status_data", text=True)
1414
list_cmd = [git2cpp_path, 'branch']
1515
p = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True)
16-
assert(p.stdout == '* main\n foregone\n')
16+
assert(p.stdout == ' foregone\n* main\n')
1717
del_cmd = [git2cpp_path, 'branch', '-d', 'foregone']
1818
subprocess.run(del_cmd, capture_output=True, cwd="test/data/status_data", text=True)
1919
p2 = subprocess.run(list_cmd, capture_output=True, cwd="test/data/status_data", text=True)

0 commit comments

Comments
 (0)