summaryrefslogtreecommitdiff
path: root/gitupdateunit.pas
blob: 66d0201c78c89d46d6004c9480bd97eb80570e12 (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
44
45
46
47
48
49
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
    updated:=updated or (sourceSha512Sum(gitDirs[i])<>binarySha512Sum(i));
    setLength(args,3);
    args[0]:='status';
    args[1]:='-sb';
    args[2]:='--porcelain';
    if not runCommandInDir(gitDirs[i],'git',args,output) then continue;
    output:=trim(output);
    if pos(' [behind ',output)=0 then
      continue;
    setLength(args,2);
    args[0]:='pull';
    args[1]:='--all';
    if not runCommandInDir(gitDirs[i],'git',args,output) then continue;
    updated:=true;
  end;
  if updated then
    refreshExecutable(gitDirs);
  setLength(args,0);
end.