Skip to content

Commit

Permalink
Add missing branch coverage in def add
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelLipski committed Dec 8, 2023
1 parent 3b5dff3 commit 1e8c5f2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/man/git-machete.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "GIT-MACHETE" "1" "Dec 07, 2023" "" "git-machete"
.TH "GIT-MACHETE" "1" "Dec 08, 2023" "" "git-machete"
.SH NAME
git-machete \- git-machete 3.22.0
.sp
Expand Down
3 changes: 2 additions & 1 deletion git_machete/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def add(self,
# Let's skip interactive questions so as not to confuse new users.
self.__roots = [current_branch]
self.__managed_branches = [current_branch]
if verbose:
# This section of code is only ever executed in verbose mode, but let's leave the `if` for consistency
if verbose: # pragma: no branch
print(fmt(f"Added branch {bold(current_branch)} as a new root"))
opt_onto = current_branch
self.__git.create_branch(branch, out_of, switch_head=switch_head_if_new_branch)
Expand Down
32 changes: 32 additions & 0 deletions tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,38 @@ def test_add_new_branch_onto_master_for_fresh_start_with_yes(self) -> None:
""")
assert read_branch_layout_file() == "master\n foo\n"

def test_add_new_branch_with_onto(self) -> None:
self.repo_sandbox\
.new_branch("master").commit()\
.new_branch("develop").commit()

body: str = \
"""
master
develop
"""
rewrite_branch_layout_file(body)

assert_success(
['add', '--onto=master', '--yes', 'foo'],
"""
A local branch foo does not exist. Creating out of master
Added branch foo onto master
""")
assert read_branch_layout_file() == "master\n develop\n foo\n"
assert self.repo_sandbox.get_commit_hash("master") == self.repo_sandbox.get_commit_hash("foo")

def test_add_new_branch_when_detached_head_for_fresh_start(self) -> None:
self.repo_sandbox.new_branch("master").commit("master commit.")\
.check_out(self.repo_sandbox.get_current_commit_hash())
assert_success(
['add', '--yes', 'foo'],
"""
A local branch foo does not exist. Creating out of the current HEAD
Added branch foo as a new root
""")
assert read_branch_layout_file() == "foo\n"

def test_add_new_branch_onto_master_for_fresh_start_without_yes(self, mocker: MockerFixture) -> None:
self.repo_sandbox.new_branch("master").commit("master commit.")

Expand Down

0 comments on commit 1e8c5f2

Please sign in to comment.