# HG changeset patch # User Anton Shestakov # Date 2023-01-28 14:26:28 # Node ID 566f7dd563c19d3ca535c140fd1e41208fedf156 # Parent c3a76efd0b1cd8432c040c240669b45cef72cb1f scmutil: make checknewlabel() allow "_" in otherwise numeric names (issue6737) diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -278,6 +278,11 @@ def checknewlabel(repo, lbl, kind): ) try: int(lbl) + if b'_' in lbl: + # If label contains underscores, Python might consider it an + # integer (with "_" as visual separators), but we do not. + # See PEP 515 - Underscores in Numeric Literals. + raise ValueError raise error.InputError(_(b"cannot use an integer as a name")) except ValueError: pass diff --git a/tests/test-branches.t b/tests/test-branches.t --- a/tests/test-branches.t +++ b/tests/test-branches.t @@ -82,6 +82,11 @@ trailing or leading spaces should be str (use 'hg update' to switch to it) [10] +underscores in numeric branch names (issue6737) + + $ hg branch 2700_210 + marked working directory as branch 2700_210 + verify update will accept invalid legacy branch names $ hg init test-invalid-branch-name