Skip to content

Commit 160716e

Browse files
committed
installer: refuse illegal default branch names
When the user wants to override the default branch name, it is all too easy to make a mistake and slip e.g. a trailing space in. Let's help users by preventing such mistakes. Note: technically the correct way would _not_ be to reimplement `check_ref_format()`, but at the stage when we want to let the user specify the branch name, we do not necessarily have a working `git.exe` to call. That's why the logic was reimplemented (without regular expressions! Yay Pascal!). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 2dc0a72 commit 160716e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

installer/install.iss

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1631,6 +1631,28 @@ begin
16311631
WizardForm.ActiveControl:=EdtDefaultBranch;
16321632
end;
16331633
1634+
procedure DefaultBranchNameChanged(Sender: TObject);
1635+
var
1636+
IsValidBranchName:Boolean;
1637+
begin
1638+
if EdtDefaultBranch.Enabled then begin
1639+
// Disallow illegal ref names
1640+
with EdtDefaultBranch do
1641+
IsValidBranchName:=(Text<>'') and (Text<>'@') and
1642+
(Pos('..',Text)=0) and (Pos('@{',Text)=0) and (Pos('//',Text)=0) and
1643+
(Pos(#8,Text)=0) and (Pos(' ',Text)=0) and (Pos(':',Text)=0) and
1644+
(Pos('?',Text)=0) and (Pos('[',Text)=0) and (Pos('\',Text)=0) and
1645+
(Pos('^',Text)=0) and (Pos('~',Text)=0) and (Pos(#127,Text)=0) and
1646+
(Pos('/.','/'+Text)=0) and (Pos('./',Text+'/')=0) and (Pos('.lock/',Text+'/')=0);
1647+
if (WizardForm.CurPageID=DefaultBranchPage.ID) then
1648+
Wizardform.NextButton.Enabled:=IsValidBranchName;
1649+
if IsValidBranchName then
1650+
EdtDefaultBranch.Color:=clWhite
1651+
else
1652+
EdtDefaultBranch.Color:=clRed;
1653+
end;
1654+
end;
1655+
16341656
procedure QueryUninstallValues; forward;
16351657
16361658
procedure InitializeWizard;
@@ -1888,6 +1910,7 @@ begin
18881910
TabOrder:=TabOrder+1;
18891911
EdtDefaultBranch.Text:='main';
18901912
EdtDefaultBranch.Enabled:=False;
1913+
EdtDefaultBranch.OnChange:=@DefaultBranchNameChanged;
18911914
Top:=Top+13+24;
18921915
18931916
LblInfo:=TLabel.Create(DefaultBranchPage);
@@ -1905,6 +1928,7 @@ begin
19051928
RdbDefaultBranch[DB_Manual].Checked:=True;
19061929
EdtDefaultBranch.Text:=Data;
19071930
EdtDefaultBranch.Enabled:=True;
1931+
DefaultBranchNameChanged(NIL);
19081932
end end;
19091933
19101934
(*

0 commit comments

Comments
 (0)