Skip to content
This repository was archived by the owner on Sep 30, 2023. It is now read-only.

Commit 09fa172

Browse files
Merge branch 'issues/111'
2 parents bf1ba0c + 4b5a82e commit 09fa172

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

Common/Helper.cs

+14
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ public static string GetPackagePath(string packageName)
7676
return Path.Combine(GetGlobalCementDirectory(), packageName + ".cmpkg");
7777
}
7878

79+
public static string GetPackageCommitHash(string packageName)
80+
{
81+
var path = Path.Combine(GetGlobalCementDirectory(), packageName + ".cmpkg.hash");
82+
if (!File.Exists(path))
83+
return "";
84+
return File.ReadAllText(path);
85+
}
86+
87+
public static void WritePackageCommitHash(string packageName, string commitHash)
88+
{
89+
var path = Path.Combine(GetGlobalCementDirectory(), packageName + ".cmpkg.hash");
90+
File.WriteAllText(path, commitHash);
91+
}
92+
7993
public static string GetServerRepositoriesPath()
8094
{
8195
return Path.Combine(Directory.GetDirectoryRoot(HomeDirectory()), "CementServer", "Repositories");

Common/PackageUpdater.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.IO;
3+
using System.Linq;
34
using Common.Logging;
45
using Microsoft.Extensions.Logging;
56

@@ -37,9 +38,13 @@ private static void UpdateFilePackage(Package package)
3738
private static void UpdateGitPackage(Package package)
3839
{
3940
var runner = new ShellRunner(Log);
40-
4141
var timeout = TimeSpan.FromMinutes(1);
4242

43+
var remoteHash = GetRepositoryHeadHash(package);
44+
var localHash = Helper.GetPackageCommitHash(package.Name);
45+
if (remoteHash != null && remoteHash.Equals(localHash))
46+
return;
47+
4348
for (int i = 0; i < 3; i++)
4449
{
4550
using (var tempDir = new TempDirectory())
@@ -66,10 +71,23 @@ private static void UpdateGitPackage(Package package)
6671
Directory.CreateDirectory(Helper.GetGlobalCementDirectory());
6772
File.Copy(Path.Combine(tempDir.Path, package.Name, "modules"),
6873
Helper.GetPackagePath(package.Name), true);
74+
Helper.WritePackageCommitHash(package.Name, remoteHash);
6975
}
7076
break;
7177
}
7278
}
7379
}
80+
81+
private static string GetRepositoryHeadHash(Package package)
82+
{
83+
var runner = new ShellRunner(Log);
84+
var timeout = TimeSpan.FromMinutes(1);
85+
86+
runner.RunOnce($"git ls-remote {package.Url} HEAD", Directory.GetCurrentDirectory(), timeout);
87+
88+
var output = runner.Output;
89+
90+
return output.Split().FirstOrDefault();
91+
}
7492
}
7593
}

0 commit comments

Comments
 (0)