Skip to content

Commit

Permalink
Refactor: Add reset before switching to default branch (#41)
Browse files Browse the repository at this point in the history
Updated method `SwitchToDefaultBranch` to `CleanAndSwitchToDefaultBranch` to include a hard reset before switching branches. This ensures the repository is cleaned before branch switch to avoid conflicts and inconsistencies. Adjusted method calls and interface accordingly.
  • Loading branch information
torbacz authored Oct 3, 2024
1 parent 427b0a6 commit b6c157c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace DependencyUpdated.Core.Interfaces;

public interface IRepositoryProvider
{
public void SwitchToDefaultBranch(string repositoryPath);
public void CleanAndSwitchToDefaultBranch(string repositoryPath);

public void SwitchToUpdateBranch(string repositoryPath, string projectName, string group);

Expand Down
4 changes: 2 additions & 2 deletions src/DependencyUpdated.Core/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task DoUpdate()
var repositoryProvider =
serviceProvider.GetRequiredKeyedService<IRepositoryProvider>(config.Value.RepositoryType);
var repositoryPath = Environment.CurrentDirectory;
repositoryProvider.SwitchToDefaultBranch(repositoryPath);
repositoryProvider.CleanAndSwitchToDefaultBranch(repositoryPath);

foreach (var project in config.Value.Projects)
{
Expand Down Expand Up @@ -51,7 +51,7 @@ public async Task DoUpdate()
alreadyProcessed.AddRange(allDependenciesToUpdate);
repositoryProvider.CommitChanges(repositoryPath, projectName, group);
await repositoryProvider.SubmitPullRequest(allUpdates, projectName, group);
repositoryProvider.SwitchToDefaultBranch(repositoryPath);
repositoryProvider.CleanAndSwitchToDefaultBranch(repositoryPath);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ internal sealed class AzureDevOps(TimeProvider timeProvider, IOptions<UpdaterCon
private const string GitCommitMessage = "Bump dependencies";
private const string RemoteName = "origin";

public void SwitchToDefaultBranch(string repositoryPath)
public void CleanAndSwitchToDefaultBranch(string repositoryPath)
{
var branchName = config.Value.AzureDevOps.TargetBranchName;
logger.Information("Switching {Repository} to branch {Branch}", repositoryPath, branchName);
using var repo = new Repository(repositoryPath);
repo.Reset(ResetMode.Hard);
var branch = GetGitBranch(repo, branchName)
?? throw new InvalidOperationException($"Branch {branchName} doesn't exist");

Expand Down

0 comments on commit b6c157c

Please sign in to comment.