Skip to content
Snippets Groups Projects
Commit 73963725 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Fix: Added support for reference too

parent 3ee45d34
No related branches found
No related tags found
1 merge request!20Fix: Added support for reference too
......@@ -66,7 +66,7 @@ public class Deployer(ILogger<Deployer> logger, IOptionsMonitor<GraphDeployerCon
_logger.LogInformation("Working with {repoName}", graphRepo.Name);
// Clone the repository inside the Working Folder
var success = CloneRepo(graphRepo.Url, WorkingFolder, _graphDeployerConfiguration.GitLab.Token, graphRepo.Branch);
var success = CloneRepo(graphRepo.Url, WorkingFolder, _graphDeployerConfiguration.GitLab.Token, graphRepo.Ref);
if (success)
{
......@@ -180,16 +180,21 @@ public class Deployer(ILogger<Deployer> logger, IOptionsMonitor<GraphDeployerCon
try
{
var cloneOptions = new CloneOptions();
if (!string.IsNullOrWhiteSpace(branchName))
{
cloneOptions.BranchName = branchName;
}
// Perform the clone operation
_logger.LogDebug("Starting clone of repository: \"{projectUrl}\" into \"{projectPath}\"", projectUrl, projectPath);
var repo = Repository.Clone(url, projectPath, cloneOptions);
var repo = Repository.Clone(url, projectPath);
var localRepo = new Repository(repo);
_logger.LogDebug("Repository successfully cloned on branch \"{branch}\".", localRepo.Head.FriendlyName);
// First clone on, then checkout, as direct cloning of commit SHA is not supported
if (!string.IsNullOrWhiteSpace(branchName))
{
Commands.Checkout(localRepo, branchName);
}
// Retrieve the reference of the repository, either the branch name or the commit hash
var repoRef = localRepo.Head.IsTracking ? localRepo.Head.FriendlyName : localRepo.Head.Tip.Sha;
_logger.LogInformation("Repository successfully cloned and switched on ref \"{ref}\".", repoRef);
return true;
}
......
......@@ -52,6 +52,6 @@ public class GraphDeployerConfiguration
{
public required string Name { get; init; }
public required Uri Url { get; init; }
public string? Branch { get; init; }
public string? Ref { get; init; }
};
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment