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
6 changes: 3 additions & 3 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ stages:
'Windows':
VM_IMAGE: 'windows-latest'
'Linux':
VM_IMAGE: 'ubuntu-latest'
VM_IMAGE: 'ubuntu-16.04'
'macOS':
VM_IMAGE: 'macOS-latest'
pool:
Expand All @@ -26,7 +26,7 @@ stages:
- template: build/stages/artifacts-test.yml
parameters:
name: Linux
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-16.04'
- template: build/stages/artifacts-test.yml
parameters:
name: Windows
Expand All @@ -40,7 +40,7 @@ stages:
- template: build/stages/docker.yml
parameters:
name: Linux
vmImage: 'ubuntu-latest'
vmImage: 'ubuntu-16.04'
- template: build/stages/docker.yml
parameters:
name: Windows
Expand Down
3 changes: 1 addition & 2 deletions src/GitVersionCore/Configuration/NamedConfigFileLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class NamedConfigFileLocator : ConfigFileLocator
{
public NamedConfigFileLocator(IFileSystem fileSystem, ILog log, IOptions<Arguments> options) : base(fileSystem, log)
{
var arguments = options.Value;
var filePath = arguments.ConfigFile;
var filePath = options.Value.ConfigFile;
if (string.IsNullOrEmpty(filePath)) throw new ArgumentNullException(nameof(filePath), "Empty file path provided!");
FilePath = filePath;
}
Expand Down
52 changes: 25 additions & 27 deletions src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public class GitPreparer : IGitPreparer
private readonly ILog log;
private readonly IEnvironment environment;
private readonly string dynamicRepositoryLocation;
private readonly bool noFetch;
private readonly Arguments arguments;

private const string DefaultRemoteName = "origin";
Expand All @@ -29,7 +28,6 @@ public GitPreparer(ILog log, IEnvironment environment, IOptions<Arguments> optio
WorkingDirectory = arguments.TargetPath.TrimEnd('/', '\\');

dynamicRepositoryLocation = arguments.DynamicRepositoryLocation;
noFetch = arguments.NoFetch;
}

public void Prepare(bool normalizeGitDirectory, string currentBranch, bool shouldCleanUpRemotes = false)
Expand All @@ -39,23 +37,24 @@ public void Prepare(bool normalizeGitDirectory, string currentBranch, bool shoul
Username = arguments.Authentication?.Username,
Password = arguments.Authentication?.Password
};
if (string.IsNullOrWhiteSpace(TargetUrl))
if (!string.IsNullOrWhiteSpace(TargetUrl))
{
if (!normalizeGitDirectory) return;
using (log.IndentLog($"Normalizing git directory for branch '{currentBranch}'"))
var tempRepositoryPath = CalculateTemporaryRepositoryPath(TargetUrl, dynamicRepositoryLocation);

dynamicGitRepositoryPath = CreateDynamicRepository(tempRepositoryPath, authentication, TargetUrl, currentBranch);
}
else
{
if (normalizeGitDirectory)
{
if (shouldCleanUpRemotes)
{
CleanupDuplicateOrigin();
}
GitRepositoryHelper.NormalizeGitDirectory(log, environment, GetDotGitDirectory(), authentication, noFetch, currentBranch, IsDynamicGitRepository());

NormalizeGitDirectory(authentication, currentBranch, GetDotGitDirectory(), IsDynamicGitRepository());
}
return;
}

var tempRepositoryPath = CalculateTemporaryRepositoryPath(TargetUrl, dynamicRepositoryLocation);

dynamicGitRepositoryPath = CreateDynamicRepository(tempRepositoryPath, authentication, TargetUrl, currentBranch);
}

public TResult WithRepository<TResult>(Func<IRepository, TResult> action)
Expand Down Expand Up @@ -108,7 +107,7 @@ private void CleanupDuplicateOrigin()
{
var remoteToKeep = DefaultRemoteName;

var repo = new Repository(GetDotGitDirectory());
using var repo = new Repository(GetDotGitDirectory());

// check that we have a remote that matches defaultRemoteName if not take the first remote
if (!repo.Network.Remotes.Any(remote => remote.Name.Equals(DefaultRemoteName, StringComparison.InvariantCultureIgnoreCase)))
Expand Down Expand Up @@ -176,29 +175,28 @@ private string CreateDynamicRepository(string targetPath, AuthenticationInfo aut
using (log.IndentLog($"Creating dynamic repository at '{targetPath}'"))
{
var gitDirectory = Path.Combine(targetPath, ".git");
if (Directory.Exists(targetPath))
if (!Directory.Exists(targetPath))
{
log.Info("Git repository already exists");
using (log.IndentLog($"Normalizing git directory for branch '{targetBranch}'"))
{
GitRepositoryHelper.NormalizeGitDirectory(log, environment, gitDirectory, auth, noFetch, targetBranch, true);
}

return gitDirectory;
CloneRepository(repositoryUrl, gitDirectory, auth);
}

CloneRepository(repositoryUrl, gitDirectory, auth);

using (log.IndentLog($"Normalizing git directory for branch '{targetBranch}'"))
else
{
// Normalize (download branches) before using the branch
GitRepositoryHelper.NormalizeGitDirectory(log, environment, gitDirectory, auth, noFetch, targetBranch, true);
log.Info("Git repository already exists");
}

NormalizeGitDirectory(auth, targetBranch, gitDirectory, true);
return gitDirectory;
}
}

private void NormalizeGitDirectory(AuthenticationInfo auth, string targetBranch, string gitDirectory, bool isDynamicRepository)
{
using (log.IndentLog($"Normalizing git directory for branch '{targetBranch}'"))
{
// Normalize (download branches) before using the branch
GitRepositoryHelper.NormalizeGitDirectory(log, environment, gitDirectory, auth, arguments.NoFetch, targetBranch, isDynamicRepository);
}
}

private void CloneRepository(string repositoryUrl, string gitDirectory, AuthenticationInfo auth)
{
Credentials credentials = null;
Expand Down
8 changes: 4 additions & 4 deletions src/GitVersionCore/Helpers/GitRepositoryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace GitVersion.Helpers
public static class GitRepositoryHelper
{
/// <summary>
/// Normalisation of a git directory turns all remote branches into local branches, turns pull request refs into a real branch and a few other things. This is designed to be run *only on the build server* which checks out repositories in different ways.
/// It is not recommended to run normalisation against a local repository
/// Normalization of a git directory turns all remote branches into local branches, turns pull request refs into a real branch and a few other things. This is designed to be run *only on the build server* which checks out repositories in different ways.
/// It is not recommended to run normalization against a local repository
/// </summary>
public static void NormalizeGitDirectory(ILog log, IEnvironment environment, string gitDirectory, AuthenticationInfo authentication,
bool noFetch, string currentBranch, bool isDynamicRepository)
Expand Down Expand Up @@ -265,7 +265,7 @@ private static IEnumerable<DirectReference> GetRemoteTipsForAnonymousUser(Reposi
private static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(ILog log, Repository repo, string remoteName)
{
var prefix = $"refs/remotes/{remoteName}/";
var remoteHeadCanonicalName = $"{prefix}{"HEAD"}";
var remoteHeadCanonicalName = $"{prefix}HEAD";

foreach (var remoteTrackingReference in repo.Refs.FromGlob(prefix + "*").Where(r => r.CanonicalName != remoteHeadCanonicalName))
{
Expand Down Expand Up @@ -299,7 +299,7 @@ private static void CreateOrUpdateLocalBranchesFromRemoteTrackingOnes(ILog log,
}
}

public static Remote EnsureOnlyOneRemoteIsDefined(ILog log, IRepository repo)
private static Remote EnsureOnlyOneRemoteIsDefined(ILog log, IRepository repo)
{
var remotes = repo.Network.Remotes;
var howMany = remotes.Count();
Expand Down