Skip to content

Commit 2ff80a1

Browse files
authored
Merge pull request #307 from dscho/choose-default-branch
installer: offer to configure `init.defaultBranch`
2 parents 79bb341 + afbe82c commit 2ff80a1

File tree

1 file changed

+84
-5
lines changed

1 file changed

+84
-5
lines changed

installer/install.iss

Lines changed: 84 additions & 5 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;
@@ -676,14 +685,14 @@ begin
676685
// exit code 5 means it was already unset, so that's okay
677686
Result:=True
678687
else begin
679-
LogError('Unable to unset system config "'+Key+'": exit code '+IntToStr(i)+#10+#13+ReadFileAsString(OutPath)+#10+#13+'stderr:'+#10+#13+ReadFileAsString(ErrPath));
688+
LogError('Unable to unset system config "'+Key+'": exit code '+IntToStr(i)+#13+#10+ReadFileAsString(OutPath)+#13+#10+'stderr:'+#13+#10+ReadFileAsString(ErrPath));
680689
Result:=False
681690
end
682691
end else if Exec(ExpandConstant('{cmd}'),'/C .\{#MINGW_BITNESS}\bin\git.exe config --system '+ShellQuote(Key)+' '+ShellQuote(Value)+' >'+#34+OutPath+#34+' 2>'+#34+ErrPath+#34,
683692
AppDir,SW_HIDE,ewWaitUntilTerminated,i) And (i=0) then
684693
Result:=True
685694
else begin
686-
LogError('Unable to set system config "'+Key+'":="'+Value+'": exit code '+IntToStr(i)+#10+#13+ReadFileAsString(OutPath)+#10+#13+'stderr:'+#10+#13+ReadFileAsString(ErrPath));
695+
LogError('Unable to set system config "'+Key+'":="'+Value+'": exit code '+IntToStr(i)+#13+#10+ReadFileAsString(OutPath)+#13+#10+'stderr:'+#13+#10+ReadFileAsString(ErrPath));
687696
Result:=False;
688697
end;
689698
end;
@@ -1013,7 +1022,7 @@ end;
10131022
10141023
procedure RecordChoice(PreviousDataKey:Integer;Key,Data:String);
10151024
begin
1016-
ChosenOptions:=ChosenOptions+Key+': '+Data+#13#10;
1025+
ChosenOptions:=ChosenOptions+Key+': '+Data+#13+#10;
10171026
SetPreviousData(PreviousDataKey,Key,Data);
10181027
if ShouldSaveInf then begin
10191028
// .inf files do not like keys with spaces.
@@ -1259,7 +1268,10 @@ begin
12591268
end;
12601269
'<RED>': begin
12611270
Untagged:=Untagged+SubString(Description,1,i-1);
1262-
RowPrefix:=RowPrefix+SubString(Description,1,i-1);
1271+
if (Description[1]=#10) then
1272+
RowPrefix:=RowPrefix+SubString(Description,2,i-2)
1273+
else
1274+
RowPrefix:=RowPrefix+SubString(Description,1,i-1);
12631275
Description:=SubString(Description,i+5,-1);
12641276
i:=Pos('</RED>',Description);
12651277
if (i=0) then LogError('Could not find </RED> in '+Description);
@@ -1300,7 +1312,10 @@ begin
13001312
end;
13011313
'<A HREF=': begin
13021314
Untagged:=Untagged+SubString(Description,1,i-1);
1303-
RowPrefix:=RowPrefix+SubString(Description,1,i-1);
1315+
if Description[1]=#10 then
1316+
RowPrefix:=RowPrefix+SubString(Description,2,i-2)
1317+
else
1318+
RowPrefix:=RowPrefix+SubString(Description,1,i-1);
13041319
Description:=SubString(Description,i+8,-1);
13051320
i:=Pos('>',Description);
13061321
if (i=0) then LogError('Could not find > in '+Description);
@@ -1604,6 +1619,14 @@ begin
16041619
end;
16051620
end;
16061621
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+
16071630
procedure QueryUninstallValues; forward;
16081631
16091632
procedure InitializeWizard;
@@ -1612,6 +1635,7 @@ var
16121635
PuTTYSessions,EnvSSH:TArrayOfString;
16131636
BtnPlink:TButton;
16141637
Data:String;
1638+
LblInfo:TLabel;
16151639
begin
16161640
InferredDefaultKeys:=TStringList.Create;
16171641
InferredDefaultValues:=TStringList.Create;
@@ -1834,6 +1858,50 @@ begin
18341858
end;
18351859
EditorSelectionChanged(NIL);
18361860
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+
18371905
(*
18381906
* Create a custom page for modifying the environment.
18391907
*)
@@ -2867,6 +2935,11 @@ begin
28672935
end;
28682936
end;
28692937
2938+
if RdbDefaultBranch[DB_Manual].Checked then
2939+
GitSystemConfigSet('init.defaultBranch',EdtDefaultBranch.Text)
2940+
else
2941+
GitSystemConfigSet('init.defaultBranch',#0);
2942+
28702943
// Get the current user's directories in PATH.
28712944
EnvPath:=GetEnvStrings('PATH',IsAdminLoggedOn);
28722945
@@ -3084,6 +3157,12 @@ begin
30843157
RecordChoice(PreviousDataKey,'Editor Option',Data);
30853158
RecordChoice(PreviousDataKey,'Custom Editor Path',CustomEditorData);
30863159
3160+
// Default Branch options.
3161+
Data:='';
3162+
if RdbDefaultBranch[DB_Manual].Checked then
3163+
Data:=EdtDefaultBranch.Text;
3164+
RecordChoice(PreviousDataKey,'Default Branch Option',Data);
3165+
30873166
// Git Path options.
30883167
Data:='';
30893168
if RdbPath[GP_BashOnly].Checked then begin

0 commit comments

Comments
 (0)