Skip to content

Commit 49a32e5

Browse files
authored
Allow Git LFS to share storage path (#46)
1 parent 98fa2ff commit 49a32e5

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

UET/Redpoint.Uet.Workspace/Descriptors/GitWorkspaceDescriptor.cs

+2
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,7 @@ public record class GitWorkspaceDescriptor : IWorkspaceDescriptor
2525
public string? ProjectFolderName { get; set; }
2626

2727
public GitWorkspaceDescriptorBuildType BuildType { get; set; }
28+
29+
public string? LfsStoragePath { get; set; }
2830
}
2931
}

UET/Redpoint.Uet.Workspace/PhysicalGit/DefaultPhysicalGitCheckout.cs

+49-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public DefaultPhysicalGitCheckout(
5555
/// </summary>
5656
private async Task InitGitWorkspaceIfNeededAsync(
5757
string repositoryPath,
58+
GitWorkspaceDescriptor workspaceDescriptor,
5859
GitExecutionContext gitContext,
5960
CancellationToken cancellationToken)
6061
{
@@ -91,6 +92,7 @@ private async Task InitGitWorkspaceIfNeededAsync(
9192
"-C",
9293
repositoryPath,
9394
"config",
95+
"set",
9496
"core.symlinks",
9597
"true"
9698
],
@@ -101,9 +103,51 @@ private async Task InitGitWorkspaceIfNeededAsync(
101103
cancellationToken).ConfigureAwait(false);
102104
if (exitCode != 0)
103105
{
104-
throw new InvalidOperationException($"'git -C ... config core.symlinks true' exited with non-zero exit code {exitCode}");
106+
throw new InvalidOperationException($"'git -C ... config set core.symlinks true' exited with non-zero exit code {exitCode}");
105107
}
106108
}
109+
110+
if (workspaceDescriptor.LfsStoragePath != null)
111+
{
112+
exitCode = await _processExecutor.ExecuteAsync(
113+
new ProcessSpecification
114+
{
115+
FilePath = gitContext.Git,
116+
Arguments =
117+
[
118+
"-C",
119+
repositoryPath,
120+
"config",
121+
"set",
122+
"lfs.storage",
123+
workspaceDescriptor.LfsStoragePath
124+
],
125+
WorkingDirectory = repositoryPath,
126+
EnvironmentVariables = gitContext.GitEnvs,
127+
},
128+
CaptureSpecification.Sanitized,
129+
cancellationToken).ConfigureAwait(false);
130+
}
131+
else
132+
{
133+
exitCode = await _processExecutor.ExecuteAsync(
134+
new ProcessSpecification
135+
{
136+
FilePath = gitContext.Git,
137+
Arguments =
138+
[
139+
"-C",
140+
repositoryPath,
141+
"config",
142+
"unset",
143+
"lfs.storage"
144+
],
145+
WorkingDirectory = repositoryPath,
146+
EnvironmentVariables = gitContext.GitEnvs,
147+
},
148+
CaptureSpecification.Sanitized,
149+
cancellationToken).ConfigureAwait(false);
150+
}
107151
}
108152

109153
/// <summary>
@@ -700,6 +744,7 @@ private async Task CheckoutTargetCommitAsync(
700744
"-c",
701745
"advice.detachedHead=false",
702746
"checkout",
747+
"--progress",
703748
"-f",
704749
resolvedReference.TargetCommit,
705750
],
@@ -731,6 +776,7 @@ await DetectGitLfsAndReconfigureIfNecessaryAsync(
731776
"-c",
732777
"advice.detachedHead=false",
733778
"checkout",
779+
"--progress",
734780
"-f",
735781
resolvedReference.TargetCommit,
736782
],
@@ -1223,6 +1269,7 @@ private async Task CheckoutSubmoduleAsync(
12231269
"-c",
12241270
"advice.detachedHead=false",
12251271
"checkout",
1272+
"--progress",
12261273
"-f",
12271274
submoduleCommit,
12281275
],
@@ -1504,7 +1551,7 @@ public async Task PrepareGitWorkspaceAsync(
15041551
};
15051552

15061553
// Initialize the Git repository if needed.
1507-
await InitGitWorkspaceIfNeededAsync(repositoryPath, gitContext, cancellationToken).ConfigureAwait(false);
1554+
await InitGitWorkspaceIfNeededAsync(repositoryPath, descriptor, gitContext, cancellationToken).ConfigureAwait(false);
15081555

15091556
// Resolve tags and refs if needed.
15101557
var potentiallyResolvedReference = await AttemptResolveReferenceToCommitWithoutFetchAsync(

UET/uet/Commands/Internal/EngineCheckout/EngineCheckoutCommand.cs

+3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@ internal sealed class Options
1515
public Option<string> Path;
1616
public Option<string> RepositoryUri;
1717
public Option<string> Branch;
18+
public Option<string> LfsStoragePath;
1819

1920
public Options()
2021
{
2122
Path = new Option<string>("--path");
2223
RepositoryUri = new Option<string>("--uri");
2324
Branch = new Option<string>("--branch");
25+
LfsStoragePath = new Option<string>("--lfs-storage-path");
2426
}
2527
}
2628

@@ -66,6 +68,7 @@ await _physicalGitCheckout.PrepareGitWorkspaceAsync(
6668
MacSharedGitCachePath = null,
6769
ProjectFolderName = null,
6870
BuildType = GitWorkspaceDescriptorBuildType.EngineLfs,
71+
LfsStoragePath = context.ParseResult.GetValueForOption(_options.LfsStoragePath),
6972
},
7073
context.GetCancellationToken()).ConfigureAwait(false);
7174
return 0;

0 commit comments

Comments
 (0)