diff --git a/docs/man/git-machete.1 b/docs/man/git-machete.1 index acffe48a8..0f262f5fc 100644 --- a/docs/man/git-machete.1 +++ b/docs/man/git-machete.1 @@ -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 diff --git a/git_machete/client.py b/git_machete/client.py index 76a6871b8..7b19bcaf3 100644 --- a/git_machete/client.py +++ b/git_machete/client.py @@ -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) diff --git a/tests/test_add.py b/tests/test_add.py index b97b98fe9..8eb5e4e5e 100644 --- a/tests/test_add.py +++ b/tests/test_add.py @@ -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.")