Skip to content

Commit

Permalink
Improve workaround for EOL problems on Windows (#3389)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Mar 11, 2024
1 parent a134ac1 commit 287772f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/Microsoft.DotNet.Darc/DarcLib/ILocalGitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,13 @@ Task StageAsync(
/// </summary>
/// <param name="args">Where to add the new argument into</param>
/// <param name="envVars">Where to add the new variables into</param>
public void AddGitAuthHeader(IList<string> args, IDictionary<string, string> envVars, string repoUri);
void AddGitAuthHeader(IList<string> args, IDictionary<string, string> envVars, string repoUri);

/// <summary>
/// Runs git with the given arguments and returns the result.
/// </summary>
Task<ProcessExecutionResult> RunGitCommandAsync(
string repoPath,
string[] args,
CancellationToken cancellationToken = default);
}
8 changes: 8 additions & 0 deletions src/Microsoft.DotNet.Darc/DarcLib/LocalGitClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,12 @@ public void AddGitAuthHeader(IList<string> args, IDictionary<string, string> env
};
envVars["GIT_TERMINAL_PROMPT"] = "0";
}

public async Task<ProcessExecutionResult> RunGitCommandAsync(
string repoPath,
string[] args,
CancellationToken cancellationToken = default)
{
return await _processManager.ExecuteGit(repoPath, args, cancellationToken: cancellationToken);
}
}
31 changes: 30 additions & 1 deletion src/Microsoft.DotNet.Darc/DarcLib/VirtualMonoRepo/VmrUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,36 @@ private async Task<bool> UpdateRepositoryRecursively(
if (vmrPatchesToReapply.Any() && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
cancellationToken.ThrowIfCancellationRequested();
await _localGitClient.CheckoutAsync(_vmrInfo.VmrPath, ".");
var result = await _localGitClient.RunGitCommandAsync(
_vmrInfo.VmrPath,
["diff", "--exit-code"],
cancellationToken: cancellationToken);

if (result.ExitCode != 0)
{
cancellationToken.ThrowIfCancellationRequested();
await _localGitClient.CheckoutAsync(_vmrInfo.VmrPath, ".");

// Sometimes not even checkout helps, so we check again
result = await _localGitClient.RunGitCommandAsync(
_vmrInfo.VmrPath,
["diff", "--exit-code"],
cancellationToken: cancellationToken);

if (result.ExitCode != 0)
{
cancellationToken.ThrowIfCancellationRequested();
await _localGitClient.RunGitCommandAsync(
_vmrInfo.VmrPath,
["add", "--u", "."],
cancellationToken: default);

await _localGitClient.RunGitCommandAsync(
_vmrInfo.VmrPath,
["commit", "--amend", "--no-edit"],
cancellationToken: default);
}
}
}
}

Expand Down

0 comments on commit 287772f

Please sign in to comment.