diff --git a/src/GraphDeployer/Deployer.cs b/src/GraphDeployer/Deployer.cs
index e0a25903416206fa0802290abc97415ad3bee16c..3895d42ac6a7dbc1527a3180509b98309e41743e 100644
--- a/src/GraphDeployer/Deployer.cs
+++ b/src/GraphDeployer/Deployer.cs
@@ -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;
}
diff --git a/src/GraphDeployer/Models/ConfigurationModels/GraphDeployerConfiguration.cs b/src/GraphDeployer/Models/ConfigurationModels/GraphDeployerConfiguration.cs
index a8b1b9de1afe822cca04fba5d736ca5ddf203d5b..cf2e346374b4af78958f96d70fbdbd7ecf711920 100644
--- a/src/GraphDeployer/Models/ConfigurationModels/GraphDeployerConfiguration.cs
+++ b/src/GraphDeployer/Models/ConfigurationModels/GraphDeployerConfiguration.cs
@@ -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; }
};
}