string GetKey(IRepository repo, string gitDir) { // Maybe using timestamp in .git/refs directory is enough? var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs")); var configPath = Path.Combine(repo.GetRepositoryDirectory(), "GitVersionConfig.yaml"); var configText = fileSystem.Exists(configPath) ? fileSystem.ReadAllText(configPath) : null; var configHash = configText != null?GetHash(configText) : null; return(string.Join(":", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks, configHash)); }
public static void OverrideVersionManuallyIfNeeded(this SemanticVersion version, IRepository repository) { var nextVersionTxtFileFinder = new NextVersionTxtFileFinder(repository.GetRepositoryDirectory()); var manualNextVersion = nextVersionTxtFileFinder.GetNextVersion(); if (!manualNextVersion.IsEmpty()) { if (manualNextVersion > version) { version.Major = manualNextVersion.Major; version.Minor = manualNextVersion.Minor; version.Patch = manualNextVersion.Patch; } } }
public static void OverrideVersionManuallyIfNeeded(this SemanticVersion version, IRepository repository, Config configuration) { var nextVersionTxtFileFinder = new NextVersionTxtFileFinder(repository.GetRepositoryDirectory(), configuration); SemanticVersion manualNextVersion ; if (nextVersionTxtFileFinder.TryGetNextVersion(out manualNextVersion)) { if (manualNextVersion > version) { version.Major = manualNextVersion.Major; version.Minor = manualNextVersion.Minor; version.Patch = manualNextVersion.Patch; } } }
public static void OverrideVersionManuallyIfNeeded(this SemanticVersion version, IRepository repository, Config configuration) { var nextVersionTxtFileFinder = new NextVersionTxtFileFinder(repository.GetRepositoryDirectory(), configuration); SemanticVersion manualNextVersion; if (nextVersionTxtFileFinder.TryGetNextVersion(out manualNextVersion)) { if (manualNextVersion > version) { version.Major = manualNextVersion.Major; version.Minor = manualNextVersion.Minor; version.Patch = manualNextVersion.Patch; } } }
public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string branch = null) { if (configuration == null) { configuration = new Config(); configuration.Reset(); } repository ??= fixture.Repository; var options = Options.Create(new GitVersionOptions { WorkingDirectory = repository.GetRepositoryDirectory(), ConfigInfo = { OverrideConfig = configuration }, RepositoryInfo = { TargetBranch = branch, CommitId = commitId, }, Settings = { OnlyTrackedBranches = onlyTrackedBranches } }); var sp = ConfigureServices(services => { services.AddSingleton(options); }); var variableProvider = sp.GetService <IVariableProvider>(); var nextVersionCalculator = sp.GetService <INextVersionCalculator>(); var contextOptions = sp.GetService <Lazy <GitVersionContext> >(); var context = contextOptions.Value; try { var executeGitVersion = nextVersionCalculator.FindVersion(); var variables = variableProvider.GetVariablesFor(executeGitVersion, context.Configuration, context.IsCurrentCommitTagged); return(variables); } catch (Exception) { Console.WriteLine("Test failing, dumping repository graph"); repository.DumpGraph(); throw; } }
public static void CheckoutFilesIfExist(this IRepository repository, params string[] fileNames) { if (fileNames == null || fileNames.Length == 0) { return; } Logger.WriteInfo("Checking out files that might be needed later in dynamic repository"); foreach (var fileName in fileNames) { try { Logger.WriteInfo(string.Format(" Trying to check out '{0}'", fileName)); var headBranch = repository.Head; var tip = headBranch.Tip; var treeEntry = tip[fileName]; if (treeEntry == null) { continue; } var fullPath = Path.Combine(repository.GetRepositoryDirectory(), fileName); using (var stream = ((Blob)treeEntry.Target).GetContentStream()) { using (var streamReader = new BinaryReader(stream)) { File.WriteAllBytes(fullPath, streamReader.ReadBytes((int)stream.Length)); } } } catch (Exception ex) { Logger.WriteWarning(string.Format(" An error occurred while checking out '{0}': '{1}'", fileName, ex.Message)); } } }
string GetKey(IRepository repo, string gitDir) { // Maybe using timestamp in .git/refs directory is enough? var ticks = fileSystem.GetLastDirectoryWrite(Path.Combine(gitDir, "refs")); var configPath = Path.Combine(repo.GetRepositoryDirectory(), "GitVersionConfig.yaml"); var configText = fileSystem.Exists(configPath) ? fileSystem.ReadAllText(configPath) : null; var configHash = configText != null ? GetHash(configText) : null; return string.Join(":", gitDir, repo.Head.CanonicalName, repo.Head.Tip.Sha, ticks, configHash); }