diff --git a/CHANGELOG.md b/CHANGELOG.md index 4227f459..9d4cd417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [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 ### Added diff --git a/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepository.cs b/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepository.cs index 4009e577..ba012a58 100644 --- a/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepository.cs +++ b/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepository.cs @@ -79,7 +79,7 @@ public sealed class GitRepository : IGitRepository 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 {"clone"}; if (branch is not null) @@ -87,6 +87,11 @@ public sealed class GitRepository : IGitRepository args.AddRange(new[] {"-b", branch}); } + if (depth != 0) + { + args.AddRange(new[] {"--depth", depth.ToString()}); + } + args.AddRange(new[] {cloneUrl.ToString(), "."}); await RunGitCmd(args); } diff --git a/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepositoryFactory.cs b/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepositoryFactory.cs index 5dbb1ba5..06d54d64 100644 --- a/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepositoryFactory.cs +++ b/src/Recyclarr.TrashLib/Repo/VersionControl/GitRepositoryFactory.cs @@ -20,7 +20,7 @@ public class GitRepositoryFactory : IGitRepositoryFactory if (!repoPath.Exists) { _log.Information("Cloning '{RepoName}' repository...", repoPath.Name); - await repo.Clone(repoUrl, branch); + await repo.Clone(repoUrl, branch, 1); } else { diff --git a/src/Recyclarr.TrashLib/Repo/VersionControl/IGitRepository.cs b/src/Recyclarr.TrashLib/Repo/VersionControl/IGitRepository.cs index 300b9635..dbf8c5ec 100644 --- a/src/Recyclarr.TrashLib/Repo/VersionControl/IGitRepository.cs +++ b/src/Recyclarr.TrashLib/Repo/VersionControl/IGitRepository.cs @@ -6,6 +6,6 @@ public interface IGitRepository : IDisposable Task Fetch(string remote = "origin"); Task ResetHard(string toBranchOrSha1); 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(); }