@@ -59,6 +59,29 @@ def testNewBranch(tempDir, mainWindow, method, switch):
5959 assert repo .head_branch_shorthand == 'master'
6060
6161
62+ def testNewBranchNaming (tempDir , mainWindow ):
63+ """Test that spaces in branch names are automatically replaced with dashes"""
64+ wd = unpackRepo (tempDir )
65+ rw = mainWindow .openRepo (wd )
66+ sb = rw .sidebar
67+ repo = rw .repo
68+
69+ node = sb .findNodeByKind (SidebarItem .LocalBranchesHeader )
70+ menu = sb .makeNodeMenu (node )
71+ triggerMenuAction (menu , "new branch" )
72+
73+ dlg : NewBranchDialog = findQDialog (rw , "new branch" )
74+ nameEdit = dlg .ui .nameEdit
75+
76+ nameEdit .setText ("hello branch" )
77+
78+ assert nameEdit .text () == "hello-branch"
79+
80+ dlg .accept ()
81+
82+ assert 'hello-branch' in repo .branches .local
83+
84+
6285def testNewBranchThenSwitchBlockedByConflicts (tempDir , mainWindow ):
6386 wd = unpackRepo (tempDir )
6487 reposcenario .statelessConflictingChange (wd )
@@ -182,13 +205,22 @@ def testRenameBranch(tempDir, mainWindow, method):
182205 "nope.lock" , "nope/" , "nope." ,
183206 "nope/.nope" , "nope//nope" , "nope@{nope" , "no..pe" ,
184207 ".nope" , "/nope" ,
185- "no pe" , "no ~pe" , "no^pe" , "no:pe" , "no[pe" , "no?pe" , "no*pe" , "no\\ pe" ,
208+ "no~pe" , "no^pe" , "no:pe" , "no[pe" , "no?pe" , "no*pe" , "no\\ pe" ,
186209 "nul" , "nope/nul" , "nul/nope" , "lpt3" , "com2" ,
187210 ]
211+ fixableNames = [
212+ # Illegal patterns that can be automatically fixed by the input field
213+ "no pe" ,
214+ ]
188215 for bad in badNames :
189216 nameEdit .setText (bad )
190217 assert not okButton .isEnabled (), f"name shouldn't pass validation: { bad } "
191218 QTest .qWait (1 ) # go through ValidatorMultiplexer's tooltip code path for coverage
219+ for fixable in fixableNames :
220+ nameEdit .setText (fixable )
221+ nameEdit .textEdited .emit (fixable )
222+ assert okButton .isEnabled (), f"name should pass validation: { fixable } "
223+ QTest .qWait (1 ) # go through ValidatorMultiplexer's tooltip code path for coverage
192224
193225 nameEdit .setText ("mainbranch" )
194226 assert okButton .isEnabled ()
@@ -305,13 +337,20 @@ def testRenameBranchFolder(tempDir, mainWindow, method, newName):
305337 "nope.lock" , "nope/" , "nope." ,
306338 "nope/.nope" , "nope//nope" , "nope@{nope" , "no..pe" ,
307339 ".nope" , "/nope" ,
308- "no pe" , "no ~pe" , "no^pe" , "no:pe" , "no[pe" , "no?pe" , "no*pe" , "no\\ pe" ,
340+ "no~pe" , "no^pe" , "no:pe" , "no[pe" , "no?pe" , "no*pe" , "no\\ pe" ,
309341 "nul" , "nope/nul" , "nul/nope" , "lpt3" , "com2" ,
310342 ]
343+ fixableNames = [
344+ # Illegal patterns that can be automatically fixed by the input field
345+ "no pe" ,
346+ ]
311347 for bad in badNames :
312348 nameEdit .setText (bad )
313349 assert not okButton .isEnabled (), f"name shouldn't pass validation: { bad } "
314350 print (bad , "-->" , nameEdit .actions ()[0 ].toolTip ())
351+ for fixable in fixableNames :
352+ nameEdit .setText (fixable )
353+ assert okButton .isEnabled (), f"name should pass validation: { fixable } "
315354
316355 nameEdit .setText (newName )
317356 assert okButton .isEnabled ()
0 commit comments