public List<Dependency> MergeDependencies(CompileDependencies rawDependencies, CompileDependencies userDefinedDependencies, CompileDependencies userDefinedAuth) { Log($"{nameof(MergeDependencies)}: user-authentication specified: {! string.IsNullOrEmpty(userDefinedAuth.Username)}"); Dependency userAuth = null; if (! string.IsNullOrEmpty(userDefinedAuth.Username)) { if (!string.IsNullOrEmpty(userDefinedAuth.AuthenticationType)) { Authentication = userDefinedAuth.AuthenticationType; } userAuth = new Dependency { Username = userDefinedAuth.Username, Password = userDefinedAuth.Password, Email = userDefinedAuth.Email }; } Log($"{nameof(MergeDependencies)}: raw dependencies count = {rawDependencies.Dependencies.Count}"); IDictionary<string, Dependency> transformedRawDependencies = rawDependencies.Dependencies.Select(p => new Dependency { Branch = p.Branch, Commit = p.Commit, DependencyName = p.DependencyName, TopFolder = p.TopFolder, Remote = p.Remote, Username = (userAuth == null) ? rawDependencies.Username : userAuth.Username, Password = (userAuth == null) ? rawDependencies.Password : userAuth.Password, Email = (userAuth == null) ? rawDependencies.Email : userAuth.Email, LocalFolder = p.LocalFolder }).ToDictionary(p => p.DependencyName); Log($"{nameof(MergeDependencies)}: user-defined dependencies specified: {userDefinedDependencies.Dependencies != null}"); var transformedUserDefinedDependencies = userDefinedDependencies.Dependencies.Select(p => new Dependency { Branch = p.Branch, Commit = p.Commit, DependencyName = p.DependencyName, TopFolder = p.TopFolder, Remote = string.Format(p.Remote, userDefinedDependencies.Username, userDefinedDependencies.Password), Username = (userAuth == null) ? userDefinedDependencies.Username : userAuth.Username, Password = (userAuth == null) ? userDefinedDependencies.Password : userAuth.Password, Email = (userAuth == null) ? userDefinedDependencies.Email : userAuth.Email, LocalFolder = p.LocalFolder }).ToDictionary(p => p.DependencyName); Log($"{nameof(MergeDependencies)}: performing..."); foreach (var p in transformedUserDefinedDependencies) { transformedRawDependencies[p.Key] = p.Value; } Log($"{nameof(MergeDependencies)}: dependencies count = {transformedUserDefinedDependencies.Count}"); return transformedRawDependencies.Select(p => p.Value).ToList(); }
protected virtual void HandleFixedVersioning_Branch(Dependency dependency, Repository otherRepository) { Log($"Dependency {dependency}: fixed versioning: checking current HEAD branch..."); var headBranch = otherRepository.Head.FriendlyName; if (headBranch != dependency.Branch) { Log($"Dependency {dependency}: fixed versioning: the current HEAD branch '{headBranch}' is different than the dependency branch '{dependency.Branch}' => checkout"); otherRepository.Checkout(dependency.Branch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force }); } // TODO: perform the pull only when necessary Log($"Dependency {dependency}: fixed versioning: pulling {dependency.Remote}"); var options = new PullOptions(); options.FetchOptions = new FetchOptions() { CredentialsProvider = new CredentialsHandler((url, usernameFromUrl, types) => dependency.GetCredentials(Authentication)) }; otherRepository.Network.Pull(new Signature(dependency.Username, dependency.Email, new DateTimeOffset(DateTime.Now)), options); }
protected virtual void HandleFixedVersioning(Dependency dependency, CloneOptions cloneOptions) { if (!string.IsNullOrEmpty(dependency.Branch) && !string.IsNullOrEmpty(dependency.Commit)) throw new InvalidOperationException($"Dependency {dependency}: fixed versioning: definition is incoherent: Branch = '{dependency.Branch}' != '' and Commit = '{dependency.Commit}' != '' => you can't have both set!"); if (!Directory.Exists(dependency.OutputFolder)) { Log($"Dependency {dependency}: fixed versioning: cloning fixed branch '{dependency.Branch}' of '{dependency.Remote}' into '{dependency.OutputFolder}'..."); cloneOptions.BranchName = dependency.Branch; Repository.Clone(dependency.Remote, dependency.OutputFolder, cloneOptions); } else if (Pull) { Log($"Dependency {dependency}: fixed versioning: repository '{dependency.Remote}' already cloned in '{dependency.OutputFolder}'"); try { IndentLevel++; using (var otherRepository = new Repository(dependency.OutputFolder)) { otherRepository.CheckoutAllRemoteBranches(); if (!string.IsNullOrEmpty(dependency.Commit)) HandleFixedVersioning_Commit(dependency, otherRepository); else HandleFixedVersioning_Branch(dependency, otherRepository); } } finally { IndentLevel--; } } }
protected virtual void HandleFixedVersioning_Commit(Dependency dependency, Repository otherRepository) { var dependencyCommit = otherRepository.Lookup(dependency.Commit) as Commit; if (dependencyCommit == null) throw new InvalidOperationException($"Dependency {dependency}: Commit '{dependency.Commit}' is invalid"); var buildBranch = (from branch in otherRepository.Branches where branch.FriendlyName == VersionResolver.BuildBranchName select branch).SingleOrDefault(); if (buildBranch == null) { Log($"Dependency {dependency}: fixed versioning: '{VersionResolver.BuildBranchName}' branch not found => creating it at Commit = '{dependency.Commit}'..."); otherRepository.CreateBranch(VersionResolver.BuildBranchName, dependency.Commit); } else { Log($"Dependency {dependency}: fixed versioning: '{VersionResolver.BuildBranchName}' branch found => checking it out and hard resetting it to Commit = '{dependency.Commit}'..."); otherRepository.Checkout(buildBranch, new CheckoutOptions() { CheckoutModifiers = CheckoutModifiers.Force }); otherRepository.Reset(ResetMode.Hard, dependencyCommit); } }
protected virtual void HandleAutoVersioning(Repository myRepository, string myShortName, Dependency dependency, CloneOptions cloneOptions) { if (!string.IsNullOrEmpty(dependency.Commit)) throw new InvalidOperationException($"Dependency {dependency}: autoversioning: definition is incoherent: Branch = '{dependency.Branch}' and a Commit = '{dependency.Commit}' => you can't have both set!"); if (Directory.Exists(dependency.OutputFolder)) { Log($"Dependency {dependency}: autoversioning: output folder already exists: removing..."); new DirectoryInfo(dependency.OutputFolder).ForceDelete(); } Log($"Dependency {dependency}: autoversioning: cloning default branch of '{dependency.Remote}' into '{dependency.OutputFolder}'"); Repository.Clone(dependency.Remote, dependency.OutputFolder, cloneOptions); try { IndentLevel++; using (var otherRepository = new Repository(dependency.OutputFolder)) { otherRepository.CheckoutAllRemoteBranches(); VersionResolver.CheckoutBranchInDependencyRepository(otherRepository, myRepository, myShortName, this); } } finally { IndentLevel--; } }