Skip to content

Commit

Permalink
Refactor Git branch retrieval and push operations
Browse files Browse the repository at this point in the history
Revised the Git branch retrieval process to include fetching remote branches if not found locally. Improved the Push method by refactoring branch retrieval and updating the PushOptions initialization for better readability and maintainability.
  • Loading branch information
torbacz committed Sep 5, 2024
1 parent 9f3757e commit 147ab2f
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/DependencyUpdated.Repositories.AzureDevOps/AzureDevOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ public void CommitChanges(string repositoryPath, string projectName, string grou
var author = new Signature(config.Value.AzureDevOps.Username, config.Value.AzureDevOps.Email,
timeProvider.GetUtcNow());
repo.Commit(GitCommitMessage, author, author);
var options = new PushOptions();
options.CredentialsProvider = CreateGitCredentialsProvider();
repo.Network.Push(repo.Branches[gitBranchName], options);
var branch = GetGitBranch(repo, gitBranchName);
var options = new PushOptions { CredentialsProvider = CreateGitCredentialsProvider() };
repo.Network.Push(branch, options);
}

public async Task SubmitPullRequest(IReadOnlyCollection<UpdateResult> updates, string projectName, string group)
Expand Down Expand Up @@ -149,14 +149,15 @@ private static string CreateGitBranchName(string projectName, string branchName,

private Branch? GetGitBranch(Repository repo, string branchName)
{
var options = new FetchOptions { CredentialsProvider = CreateGitCredentialsProvider() };
Commands.Fetch(repo, RemoteName, ArraySegment<string>.Empty, options, string.Empty);

var branch = repo.Branches[branchName];
if (branch is not null)
{
return branch;
}

var options = new FetchOptions { CredentialsProvider = CreateGitCredentialsProvider() };
Commands.Fetch(repo, RemoteName, ArraySegment<string>.Empty, options, string.Empty);

return repo.Branches[$"{RemoteName}/{branchName}"];
}

Expand Down

0 comments on commit 147ab2f

Please sign in to comment.