CommitFile()

This commit is contained in:
Gerhard Hoffmann 2024-03-13 16:08:30 +01:00
parent b6ca18f053
commit 9d590039aa
7 changed files with 111 additions and 12 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

78
helloworld.lpi Normal file
View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<PathDelim Value="\"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="helloworld"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="LazUtils"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="helloworld.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="Unit1"/>
</Unit>
<Unit>
<Filename Value="tariffcalculator.pas"/>
<IsPartOfProject Value="True"/>
<UnitName Value="TariffCalculator"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<PathDelim Value="\"/>
<Target>
<Filename Value="helloworld"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf3"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -6,29 +6,44 @@ program helloworld(output);
uses
TariffCalculator, CTypes;
TariffCalculator, CTypes, LazUtils, LazFileUtils, LazUtf8;
var
TariffCalc: TariffCalculatorHandle;
//TariffCalc: TariffCalculatorHandle;
CustomerRepo: array[0..100] of char;
LocalCustomerRepo: array[0..100] of char;
LocalBranchName: array[0..32] of char;
FileToCommit: array[0..128] of char;
CommitMessage: array[0..256] of char;
begin
writeLn('Hello, World!') ;
// TariffCalc := NewTariffCalculator;
// DeleteTariffCalculator(TariffCalc);
if InitGitLibrary() > 0 then
begin
writeLn('init OK!') ;
CustomerRepo := 'https://git.mimbach49.de/GerhardHoffmann/customer_999.git';
LocalCustomerRepo := 'C:\\tmp\\customer_999';
CloneRepository(CustomerRepo, LocalCustomerRepo);
LocalBranchName := 'zg1/zone1';
FileToCommit := 'etc/psa_tariff/tariff01.json';
CommitMessage := 'TEST TEST';
if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo)) then
CreateDirUTF8(ExpandFilenameUtf8(LocalCustomerRepo));
ShutdownGitLibrary();
if InitGitLibrary() > 0 then
Try
writeLn('initialized git library') ;
if not DirectoryExistsUTF8(ExpandFilenameUtf8(LocalCustomerRepo+'\\.git')) then
CloneRepository(CustomerRepo, LocalCustomerRepo);
if not CheckoutLocalBranch(LocalCustomerRepo, LocalBranchName) = 0 then
writeLn('cannot check out') ;
if not CommitFile(LocalCustomerRepo, LocalBranchName, FileToCommit, CommitMessage) = 0 then
writeLn('cannot check out') ;
Finally
if ShutdownGitLibrary() >= 0 then
writeLn('shutdown git library') ;
end
else
begin
writeLn('init NOT OK!') ;
writeLn('initializing git library FAILED') ;
Readln;
end;
end.

View File

@ -1,6 +1,6 @@
unit TariffCalculator;
{$mode ObjFPC}{$H-}
{$mode ObjFPC}{$H+}
interface
@ -18,6 +18,9 @@ procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall;
function InitGitLibrary: cint32; stdcall;
function ShutdownGitLibrary: cint32; stdcall;
function CloneRepository(var url; var local_path) : cint32; stdcall;
function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall;
function CommitFile(var local_path; var branch_name;
var file_name; var comment) : cint32; stdcall;
implementation
@ -30,6 +33,9 @@ procedure DeleteTariffCalculator(handle: TariffCalculatorHandle); stdcall; exter
function InitGitLibrary: cint32; stdcall; external DLLName;
function ShutdownGitLibrary: cint32; stdcall; external DLLName;
function CloneRepository(var url; var local_path) : cint32; stdcall; external DLLName;
function CheckoutLocalBranch(var local_path; var branch_name) : cint32; stdcall; external DLLName;
function CommitFile(var local_path; var branch_name;
var file_name; var comment) : cint32; stdcall; external DLLName;
end.