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

Commit 76ce995

Browse files
committed
feat: добавил метод GC в GitRepository
1 parent 04cc50a commit 76ce995

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Cement.Cli.Common.Exceptions;
2+
3+
public sealed class GitGCException : CementException
4+
{
5+
public GitGCException(string message)
6+
: base(message)
7+
{
8+
}
9+
}

src/Cement.Cli.Common/GitRepository.cs

+18
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,24 @@ public void Init()
9595
IsGitRepo = true;
9696
}
9797

98+
/// <summary>
99+
/// Cleanup unnecessary files and optimize the local repository
100+
/// </summary>
101+
public void GC()
102+
{
103+
using var workspaceScope = logger.BeginScope("{Workspace}", Workspace);
104+
using var moduleScope = logger.BeginScope("{ModuleName}", ModuleName);
105+
logger.LogInformation("git-gc");
106+
107+
const string cmd = "git gc";
108+
109+
var (exitCode, _, errors) = shellRunner.Run(cmd);
110+
if (exitCode != 0)
111+
{
112+
throw new GitGCException("Failed to collect garbage, details:\n" + errors);
113+
}
114+
}
115+
98116
public CurrentTreeish CurrentLocalTreeish()
99117
{
100118
logger.LogInformation($"{"[" + ModuleName + "]",-30}Getting current treeish");

0 commit comments

Comments
 (0)