Skip to content

Commit e94e3c1

Browse files
committed
Fix crashes on @ sign in branch names
1 parent 8939647 commit e94e3c1

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## New in git-machete 3.36.4
44

5+
- fixed: git-machete no longer crashing when branch name contains a `@` (reported by @brandtdaniels)
56
- improved: more GitHub PR description template files are recognized (like `.github/PULL_REQUEST_TEMPLATE.md` or `docs/pull_request_template.md`)
67

78
## New in git-machete 3.36.3

git_machete/git_operations.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,10 +684,11 @@ def get_counterpart_branches() -> Iterator[str]:
684684
raise UnexpectedMacheteException(
685685
f"`git reflog` did not return exactly 3 values: `{values}` ({hex_repr(entry)})")
686686
selector, hash, subject = values
687-
branch_and_index = selector.split("@")
687+
# Let's split just on the rightmost `@` in case the branch name contains a `@`
688+
branch_and_index = selector.rsplit("@", 1)
688689
if len(branch_and_index) != 2:
689690
raise UnexpectedMacheteException(
690-
f"`git reflog` did not return exactly 2 values: `{values}` ({hex_repr(entry)})")
691+
f"`branch@index` from `git reflog` did not rsplit into exactly 2 values: `{branch_and_index}` ({hex_repr(entry)})")
691692
branch, _ = branch_and_index
692693
any_branch_name = AnyBranchName.of(branch)
693694
if any_branch_name not in self.__reflogs_cached:

tests/test_git_operations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,13 @@ def test_get_reflog_when_log_showsignature_is_true(self) -> None:
187187
# If the bug reported in GitHub issue #1286 is not fixed, this method call
188188
# should raise an UnexpectedMacheteException.
189189
git.get_reflog(AnyBranchName.of("feature"))
190+
191+
def test_get_reflog_for_branch_with_at_sign(self) -> None:
192+
create_repo()
193+
new_branch("feature@foo")
194+
commit("feature commit")
195+
196+
git = GitContext()
197+
# If the bug reported in GitHub issue #1481 is not fixed, this method call
198+
# should raise an UnexpectedMacheteException.
199+
git.get_reflog(AnyBranchName.of("feature@foo"))

tests/test_status.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -735,17 +735,18 @@ def test_status_during_side_effecting_operations(self) -> None:
735735
create_repo()
736736
new_branch("master")
737737
commit()
738-
new_branch("develop")
738+
# Let's also see how a branch with `@` in its name is handled in various context (issue #1481).
739+
new_branch("develop@foo")
739740
add_file_and_commit("1.txt", "some-content")
740741
check_out("master")
741742
new_branch("feature")
742743
add_file_and_commit("1.txt", "some-other-content")
743-
check_out("develop")
744+
check_out("develop@foo")
744745

745746
body: str = \
746747
"""
747748
master
748-
develop
749+
develop@foo
749750
"""
750751
rewrite_branch_layout_file(body)
751752

@@ -759,7 +760,7 @@ def test_status_during_side_effecting_operations(self) -> None:
759760
master
760761
|
761762
| Some commit message.
762-
o-GIT AM IN PROGRESS develop *
763+
o-GIT AM IN PROGRESS develop@foo *
763764
"""
764765
)
765766
assert_success(['status', '-l'], expected_status_output)
@@ -775,7 +776,7 @@ def test_status_during_side_effecting_operations(self) -> None:
775776
master
776777
|
777778
| Some commit message.
778-
o-CHERRY-PICKING develop *
779+
o-CHERRY-PICKING develop@foo *
779780
"""
780781
)
781782
assert_success(['status', '-l'], expected_status_output)
@@ -791,7 +792,7 @@ def test_status_during_side_effecting_operations(self) -> None:
791792
master
792793
|
793794
| Some commit message.
794-
o-MERGING develop *
795+
o-MERGING develop@foo *
795796
"""
796797
)
797798
assert_success(['status', '-l'], expected_status_output)
@@ -807,7 +808,7 @@ def test_status_during_side_effecting_operations(self) -> None:
807808
master
808809
|
809810
| Some commit message.
810-
o-REVERTING develop *
811+
o-REVERTING develop@foo *
811812
"""
812813
)
813814
assert_success(['status', '-l'], expected_status_output)
@@ -829,7 +830,7 @@ def test_status_during_side_effecting_operations(self) -> None:
829830
| Some commit message.
830831
| Another commit message.
831832
| Yet another commit message.
832-
o-BISECTING develop *
833+
o-BISECTING develop@foo *
833834
"""
834835
)
835836
assert_success(['status', '-l'], expected_status_output)

0 commit comments

Comments
 (0)