fix: Improve repo clone performance by using shallow clones

Fixes #201.
json-serializing-nullable-fields-issue
Robert Dailey 1 year ago
parent 7376cdbabc
commit a6e737fae9

@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
### Changed
- Reduce the time it takes to clone the config and trash repositories by performing shallow clones
(#201).
## [5.2.0] - 2023-08-06 ## [5.2.0] - 2023-08-06
### Added ### Added

@ -79,7 +79,7 @@ public sealed class GitRepository : IGitRepository
await RunGitCmd("remote", "set-url", name, newUrl.ToString()); await RunGitCmd("remote", "set-url", name, newUrl.ToString());
} }
public async Task Clone(Uri cloneUrl, string? branch = null) public async Task Clone(Uri cloneUrl, string? branch = null, int depth = 0)
{ {
var args = new List<string> {"clone"}; var args = new List<string> {"clone"};
if (branch is not null) if (branch is not null)
@ -87,6 +87,11 @@ public sealed class GitRepository : IGitRepository
args.AddRange(new[] {"-b", branch}); args.AddRange(new[] {"-b", branch});
} }
if (depth != 0)
{
args.AddRange(new[] {"--depth", depth.ToString()});
}
args.AddRange(new[] {cloneUrl.ToString(), "."}); args.AddRange(new[] {cloneUrl.ToString(), "."});
await RunGitCmd(args); await RunGitCmd(args);
} }

@ -20,7 +20,7 @@ public class GitRepositoryFactory : IGitRepositoryFactory
if (!repoPath.Exists) if (!repoPath.Exists)
{ {
_log.Information("Cloning '{RepoName}' repository...", repoPath.Name); _log.Information("Cloning '{RepoName}' repository...", repoPath.Name);
await repo.Clone(repoUrl, branch); await repo.Clone(repoUrl, branch, 1);
} }
else else
{ {

@ -6,6 +6,6 @@ public interface IGitRepository : IDisposable
Task Fetch(string remote = "origin"); Task Fetch(string remote = "origin");
Task ResetHard(string toBranchOrSha1); Task ResetHard(string toBranchOrSha1);
Task SetRemote(string name, Uri newUrl); Task SetRemote(string name, Uri newUrl);
Task Clone(Uri cloneUrl, string? branch = null); Task Clone(Uri cloneUrl, string? branch = null, int depth = 0);
Task Status(); Task Status();
} }

Loading…
Cancel
Save