Skip to content

Commit afbe82c

Browse files
committed
installer: offer to specify the initial branch in new repositories
Git actually supports `init.defaultBranch` already since v2.28.0. GitHub intends to switch the default name of initial branches to `main` Real Soon Now. Let's follow the crowd and let Git for Windows' users specify their preference explicitly (or leave the default to Git). Signed-off-by: Johannes Schindelin <[email protected]>
1 parent a0a51de commit afbe82c

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

installer/install.iss

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,10 @@ const
333333
GP_Cmd = 2;
334334
GP_CmdTools = 3;
335335
336+
// Default Branch options.
337+
DB_Unspecified = 1;
338+
DB_Manual = 2;
339+
336340
// Git SSH options.
337341
GS_OpenSSH = 1;
338342
GS_Plink = 2;
@@ -428,6 +432,11 @@ var
428432
CustomEditorPath:String;
429433
CustomEditorOptions:String;
430434
435+
// Wizard page and variables for the Default Branch options.
436+
DefaultBranchPage:TWizardPage;
437+
RdbDefaultBranch:array[DB_Unspecified..DB_Manual] of TRadioButton;
438+
EdtDefaultBranch:TEdit;
439+
431440
// Wizard page and variables for the Path options.
432441
PathPage:TWizardPage;
433442
RdbPath:array[GP_BashOnly..GP_CmdTools] of TRadioButton;
@@ -1610,6 +1619,14 @@ begin
16101619
end;
16111620
end;
16121621
1622+
procedure DefaultBranchOptionChanged(Sender: TObject);
1623+
begin
1624+
EdtDefaultBranch.Enabled:=RdbDefaultBranch[DB_Manual].Checked;
1625+
if EdtDefaultBranch.Enabled and (WizardForm.CurPageID=DefaultBranchPage.ID) then
1626+
// If the manual option was just checked, move the focus to the text box
1627+
WizardForm.ActiveControl:=EdtDefaultBranch;
1628+
end;
1629+
16131630
procedure QueryUninstallValues; forward;
16141631
16151632
procedure InitializeWizard;
@@ -1618,6 +1635,7 @@ var
16181635
PuTTYSessions,EnvSSH:TArrayOfString;
16191636
BtnPlink:TButton;
16201637
Data:String;
1638+
LblInfo:TLabel;
16211639
begin
16221640
InferredDefaultKeys:=TStringList.Create;
16231641
InferredDefaultValues:=TStringList.Create;
@@ -1840,6 +1858,50 @@ begin
18401858
end;
18411859
EditorSelectionChanged(NIL);
18421860
1861+
(*
1862+
* Create a custom page for modifying the default branch.
1863+
*)
1864+
1865+
DefaultBranchPage:=CreatePage(PrevPageID,'Adjusting the name of the initial branch in new repositories','What would you like Git to name the initial branch after "git init"?',TabOrder,Top,Left);
1866+
1867+
// 1st choice
1868+
RdbDefaultBranch[DB_Unspecified]:=CreateRadioButton(DefaultBranchPage,'Let Git decide','Let Git use its default branch name (currently: "master") for the initial branch'+#13+'in newly created repositories. The Git project <A HREF=https://sfconservancy.org/news/2020/jun/23/gitbranchname/>intends</A> to change this default to'+#13+'a more inclusive name in the near future.',TabOrder,Top,Left);
1869+
RdbDefaultBranch[DB_Unspecified].OnClick:=@DefaultBranchOptionChanged;
1870+
1871+
// 2nd choice
1872+
RdbDefaultBranch[DB_Manual]:=CreateRadioButton(DefaultBranchPage,'Override the default branch name for new repositories','<RED>NEW!</RED> Many teams already renamed their default branches; common choices are'+#13+'"main", "trunk" and "development". Specify the name "git init" should use for the'+#13+'initial branch:',TabOrder,Top,Left);
1873+
RdbDefaultBranch[DB_Manual].OnClick:=@DefaultBranchOptionChanged;
1874+
1875+
// Text field for the overridden branch name
1876+
Top:=Top-13;
1877+
EdtDefaultBranch:=TEdit.Create(DefaultBranchPage);
1878+
EdtDefaultBranch.Parent:=DefaultBranchPage.Surface;
1879+
EdtDefaultBranch.Left:=ScaleX(Left+24);
1880+
EdtDefaultBranch.Top:=ScaleY(Top);
1881+
EdtDefaultBranch.Width:=ScaleX(158);
1882+
EdtDefaultBranch.Height:=ScaleY(13);
1883+
EdtDefaultBranch.TabOrder:=TabOrder;
1884+
TabOrder:=TabOrder+1;
1885+
EdtDefaultBranch.Text:='main';
1886+
EdtDefaultBranch.Enabled:=False;
1887+
Top:=Top+13+24;
1888+
1889+
LblInfo:=TLabel.Create(DefaultBranchPage);
1890+
LblInfo.Parent:=DefaultBranchPage.Surface;
1891+
LblInfo.Caption:='This setting does not affect existing repositories.';
1892+
LblInfo.Left:=ScaleX(Left);
1893+
LblInfo.Top:=ScaleY(Top);
1894+
1895+
// Restore the setting chosen during a previous install.
1896+
Data:=ReplayChoice('Default Branch Option','');
1897+
case Data of
1898+
'': RdbDefaultBranch[DB_Unspecified].Checked:=True;
1899+
else begin
1900+
RdbDefaultBranch[DB_Manual].Checked:=True;
1901+
EdtDefaultBranch.Text:=Data;
1902+
EdtDefaultBranch.Enabled:=True;
1903+
end end;
1904+
18431905
(*
18441906
* Create a custom page for modifying the environment.
18451907
*)
@@ -2868,6 +2930,11 @@ begin
28682930
end;
28692931
end;
28702932
2933+
if RdbDefaultBranch[DB_Manual].Checked then
2934+
GitSystemConfigSet('init.defaultBranch',EdtDefaultBranch.Text)
2935+
else
2936+
GitSystemConfigSet('init.defaultBranch',#0);
2937+
28712938
// Get the current user's directories in PATH.
28722939
EnvPath:=GetEnvStrings('PATH',IsAdminLoggedOn);
28732940
@@ -3085,6 +3152,12 @@ begin
30853152
RecordChoice(PreviousDataKey,'Editor Option',Data);
30863153
RecordChoice(PreviousDataKey,'Custom Editor Path',CustomEditorData);
30873154
3155+
// Default Branch options.
3156+
Data:='';
3157+
if RdbDefaultBranch[DB_Manual].Checked then
3158+
Data:=EdtDefaultBranch.Text;
3159+
RecordChoice(PreviousDataKey,'Default Branch Option',Data);
3160+
30883161
// Git Path options.
30893162
Data:='';
30903163
if RdbPath[GP_BashOnly].Checked then begin

0 commit comments

Comments
 (0)