Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions KtsuBuild.Tests/Metadata/MetadataServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public Task PushAsync(string workingDirectory, CancellationToken cancellationTok
public Task<bool> HasUncommittedChangesAsync(string workingDirectory, CancellationToken cancellationToken = default)
=> Task.FromResult(false);

public Task<bool> HasStagedChangesAsync(string workingDirectory, CancellationToken cancellationToken = default)
=> Task.FromResult(false);

public Task SetIdentityAsync(string workingDirectory, string name, string email, CancellationToken cancellationToken = default)
=> Task.CompletedTask;
}
Expand Down
8 changes: 8 additions & 0 deletions KtsuBuild/Abstractions/IGitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public interface IGitService
/// <returns>True if there are uncommitted changes.</returns>
public Task<bool> HasUncommittedChangesAsync(string workingDirectory, CancellationToken cancellationToken = default);

/// <summary>
/// Checks if there are staged changes ready to be committed.
/// </summary>
/// <param name="workingDirectory">The repository directory.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <returns>True if there are staged changes.</returns>
public Task<bool> HasStagedChangesAsync(string workingDirectory, CancellationToken cancellationToken = default);

/// <summary>
/// Sets the git user identity for commits.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions KtsuBuild/Git/GitService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ public async Task<bool> HasUncommittedChangesAsync(string workingDirectory, Canc
return !string.IsNullOrWhiteSpace(result.StandardOutput);
}

/// <inheritdoc/>
public async Task<bool> HasStagedChangesAsync(string workingDirectory, CancellationToken cancellationToken = default)
{
Ensure.NotNull(workingDirectory);
// --cached limits the diff to staged changes, which is exactly what `git commit` would commit.
// --name-only keeps the output empty when nothing is staged so we can detect a no-op commit.
ProcessResult result = await processRunner.RunAsync("git", "diff --cached --name-only", workingDirectory, cancellationToken).ConfigureAwait(false);
return !string.IsNullOrWhiteSpace(result.StandardOutput);
}

/// <inheritdoc/>
public async Task SetIdentityAsync(string workingDirectory, string name, string email, CancellationToken cancellationToken = default)
{
Expand Down
5 changes: 4 additions & 1 deletion KtsuBuild/Metadata/MetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ public async Task<MetadataUpdateResult> UpdateAllAsync(MetadataUpdateOptions opt
logger.WriteInfo($"Adding files to git: {string.Join(", ", filesToAdd)}");
await gitService.StageFilesAsync(config.WorkspacePath, filesToAdd, cancellationToken).ConfigureAwait(false);

hasChanges = await gitService.HasUncommittedChangesAsync(config.WorkspacePath, cancellationToken).ConfigureAwait(false);
// Only the staged metadata files are committed, so check for staged changes specifically.
// If the generated files are identical to what's already committed, nothing is staged
// and committing would fail with "nothing to commit", erroring the whole process.
hasChanges = await gitService.HasStagedChangesAsync(config.WorkspacePath, cancellationToken).ConfigureAwait(false);

if (hasChanges)
{
Expand Down
Loading