Skip to content

Commit 2e2d2bf

Browse files
authored
Merge pull request #264 from dscho/upgrading-from-rc-versions-isnt-a-downgrade
Installer: stop complaining about "downgrading" when upgrading from an rc version
2 parents d2db86e + dbbfe25 commit 2e2d2bf

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

installer/install.iss

+42-1
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,10 @@ begin
649649
Result:='(no output)'
650650
else
651651
Result:=Contents;
652+
if (Length(Result)>0) and (Result[Length(Result)]=#10) then
653+
SetLength(Result,Length(Result)-1);
654+
if (Length(Result)>0) and (Result[Length(Result)]=#13) then
655+
SetLength(Result,Length(Result)-1);
652656
end;
653657
654658
function GitSystemConfigSet(Key,Value:String):Boolean;
@@ -812,6 +816,13 @@ begin
812816
if Previous<0 then begin
813817
if Current>=0 then
814818
Result:=+1;
819+
Result:=Ord(CurrentVersion[i])-Ord(PreviousVersion[j]);
820+
if (Result=0) then begin
821+
// skip identical non-numerical characters
822+
i:=i+1;
823+
j:=j+1;
824+
Continue;
825+
end;
815826
Exit;
816827
end;
817828
if Current<0 then begin
@@ -858,6 +869,36 @@ begin
858869
ExitProcess(0);
859870
end;
860871
872+
function CountDots(S:String):Integer;
873+
var
874+
i:Integer;
875+
begin
876+
Result:=0;
877+
for i:=1 to Length(S) do
878+
if (S[i]=#46) then
879+
Result:=Result+1;
880+
end;
881+
882+
function IsDowngrade(CurrentVersion,PreviousVersion:String):Boolean;
883+
var
884+
Path:String;
885+
i,j,CurrentLength,PreviousLength:Integer;
886+
begin
887+
Result:=(VersionCompare(CurrentVersion,PreviousVersion)<0);
888+
#ifdef GIT_VERSION
889+
if Result or (CountDots(CurrentVersion)>3) or (CountDots(PreviousVersion)>3) then begin
890+
// maybe the previous version was a prerelease (prereleases have five numbers: v2.24.0-rc1.windows.1 reduces to '2.24.0.1.1')?
891+
if (RegQueryStringValue(HKEY_LOCAL_MACHINE,'Software\GitForWindows','InstallPath',Path))
892+
and (Exec(ExpandConstant('{cmd}'),'/c ""'+Path+'\cmd\git.exe" version >"'+ExpandConstant('{tmp}')+'\previous.version""','',SW_HIDE,ewWaitUntilTerminated,i))
893+
and (i=0) then begin
894+
CurrentVersion:='{#GIT_VERSION}';
895+
PreviousVersion:=ReadFileAsString(ExpandConstant('{tmp}\previous.version'));
896+
Result:=(VersionCompare(CurrentVersion,PreviousVersion)<0);
897+
end;
898+
end;
899+
#endif
900+
end;
901+
861902
function InitializeSetup:Boolean;
862903
var
863904
CurrentVersion,Msg:String;
@@ -886,7 +927,7 @@ begin
886927
#if APP_VERSION!='0-test'
887928
if Result and not ParamIsSet('ALLOWDOWNGRADE') then begin
888929
CurrentVersion:=ExpandConstant('{#APP_VERSION}');
889-
if (VersionCompare(CurrentVersion,PreviousGitForWindowsVersion)<0) then begin
930+
if IsDowngrade(CurrentVersion,PreviousGitForWindowsVersion) then begin
890931
if WizardSilent() and (ParamIsSet('SKIPDOWNGRADE') or ParamIsSet('VSNOTICE')) then begin
891932
Msg:='Skipping downgrade from '+PreviousGitForWindowsVersion+' to '+CurrentVersion;
892933
if ParamIsSet('SKIPDOWNGRADE') or (ExpandConstant('{log}')='') then

installer/release.sh

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ else
119119
die "Could not generate file list"
120120
fi
121121

122+
cmd_git="$(echo "$LIST" | grep '^cmd/git\.exe$')"
123+
test -z "$cmd_git" ||
124+
inno_defines="$inno_defines$LF#define GIT_VERSION '$("/$cmd_git" version)'" ||
125+
die "Could not execute 'git version'"
126+
122127
printf '; List of files\n%s\n%s\n%s\n%s\n%s\n%s\n' \
123128
"Source: \"mingw$BITNESS\\bin\\blocked-file-util.exe\"; Flags: dontcopy" \
124129
"Source: \"{#SourcePath}\\package-versions.txt\"; DestDir: {app}\\etc; Flags: replacesameversion restartreplace; AfterInstall: DeleteFromVirtualStore" \

0 commit comments

Comments
 (0)