summaryrefslogtreecommitdiff
path: root/gitupdateunit.pas
blob: 69346db24fba144e6f8e5954f7f884d29473688e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
unit gitupdateunit;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

implementation

uses
  process, systemunit, lowlevelunit, refreshExecutableUnit;

var
  updated:      boolean;
  output:       string;
  args,gitDirs: tStringArray;
  i:            longint;

initialization
  updated:=false;

  setlength(gitDirs,2);
  gitDirs[0]:=extractFilePath(paramstr(0));
  gitDirs[1]:=extractFilePath(leftStr(gitDirs[0],length(gitDirs[0])-1))+'units/';

  output:='';
  for i:=0 to length(gitDirs)-1 do begin
    setlength(args,2);
    args[0]:='pull';
    args[1]:='--all';
    if not runCommandInDir(gitDirs[i],'git',args,output) then continue;
    output:=trim(output);
    while pos(#10,output)>0 do
      erstesArgument(output,#10);
    updated:=updated or (output<>'Already up-to-date.') or (sourceSha512Sum(gitDirs[i])<>binarySha512Sum(i));
  end;
  if updated then
    refreshExecutable(gitDirs);
  setlength(args,0);
end.