public void reading_repository_info_xml_file_Branches() { string s = @"<?xml version=""1.0"" encoding=""utf-8""?> <RepositoryInfo xmlns=""http://csemver.org/schemas/2015""> <Branches> <Branch Name=""develop"" CIVersionMode=""LastReleaseBased"" /> <Branch Name=""exploratory"" CIVersionMode=""ZeroTimed"" VersionName=""Preview"" /> </Branches> </RepositoryInfo>"; XDocument d = XDocument.Parse(s); ValidateAgainstSchema(d); RepositoryInfoOptions opt = RepositoryInfoOptions.Read(d.Root); Assert.That(opt.StartingVersionForCSemVer, Is.Null); Assert.That(opt.IgnoreModifiedFiles, Is.Empty); Assert.That(opt.Branches.Count, Is.EqualTo(2)); Assert.That(opt.Branches[0].Name, Is.EqualTo("develop")); Assert.That(opt.Branches[0].CIVersionMode, Is.EqualTo(CIBranchVersionMode.LastReleaseBased)); Assert.That(opt.Branches[0].VersionName, Is.Null); Assert.That(opt.Branches[1].Name, Is.EqualTo("exploratory")); Assert.That(opt.Branches[1].CIVersionMode, Is.EqualTo(CIBranchVersionMode.ZeroTimed)); Assert.That(opt.Branches[1].VersionName, Is.EqualTo("Preview")); }
/// <summary> /// Gets the simple git version <see cref="RepositoryInfo"/> from a branch. /// Returns null if an error occurred or if RepositoryInfo.xml has not been successfully read. /// </summary> /// <param name="m">The monitor to use.</param> /// <param name="branchName">Defaults to <see cref="CurrentBranchName"/>.</param> /// <returns>The RepositoryInfo or null if it it cannot be obtained.</returns> public RepositoryInfo ReadRepositoryVersionInfo(IActivityMonitor m, string branchName = null) { if (branchName == null) { branchName = CurrentBranchName; } try { Branch b = Git.Branches[branchName]; if (b == null) { m.Error($"Unknown branch {branchName}."); return(null); } var pathOpt = b.IsRemote ? SubPath.AppendPart("remotes").Combine(b.FriendlyName) : SubPath.AppendPart("branches").AppendPart(branchName); pathOpt = pathOpt.AppendPart("RepositoryInfo.xml"); var fOpt = FileSystem.GetFileInfo(pathOpt); if (!fOpt.Exists) { m.Error($"Missing required {pathOpt} file."); return(null); } var opt = RepositoryInfoOptions.Read(fOpt.ReadAsXDocument().Root); opt.StartingBranchName = branchName; var result = new RepositoryInfo(Git, opt); if (result.RepositoryError != null) { m.Error($"Unable to read RepositoryInfo. RepositoryError: {result.RepositoryError}."); return(null); } if (result.Error != null) { m.Error(result.ReleaseTagError); return(null); } return(result); } catch (Exception ex) { m.Fatal($"While reading version info for branch '{branchName}'.", ex); return(null); } }
public void reading_repository_info_xml_file_StartingVersionForCSemVer_and_IgnoreModifiedFiles() { string s = @"<?xml version=""1.0"" encoding=""utf-8""?> <RepositoryInfo xmlns=""http://csemver.org/schemas/2015""> <StartingVersionForCSemVer>v4.2.0</StartingVersionForCSemVer> <IgnoreModifiedFiles> <Add>SharedKey.snk</Add> </IgnoreModifiedFiles> </RepositoryInfo>"; XDocument d = XDocument.Parse(s); ValidateAgainstSchema(d); RepositoryInfoOptions opt = RepositoryInfoOptions.Read(d.Root); Assert.That(opt.Branches, Is.Empty); Assert.That(opt.StartingVersionForCSemVer, Is.EqualTo("v4.2.0")); Assert.That(opt.StartingCommitSha, Is.Null); CollectionAssert.AreEquivalent(opt.IgnoreModifiedFiles, new[] { "SharedKey.snk" }); }
public void full_repository_info_to_xml_is_valid_according_to_schema() { string s = @"<?xml version=""1.0"" encoding=""utf-8""?> <RepositoryInfo xmlns=""http://csemver.org/schemas/2015""> <Debug IgnoreDirtyWorkingFolder=""true"" /> <Branches> <Branch Name=""develop"" CIVersionMode=""LastReleaseBased"" /> <Branch Name=""exploratory"" CIVersionMode=""ZeroTimed"" VersionName=""Preview"" /> <Branch Name=""other"" CIVersionMode=""None"" /> </Branches> <StartingVersionForCSemVer>v4.2.0</StartingVersionForCSemVer> <OnlyPatch>true</OnlyPatch> <SingleMajor>3</SingleMajor> <IgnoreModifiedFiles> <Add>SharedKey.snk</Add> </IgnoreModifiedFiles> <RemoteName>not-the-origin</RemoteName> </RepositoryInfo>"; XDocument d = XDocument.Parse(s); ValidateAgainstSchema(d); RepositoryInfoOptions opt = RepositoryInfoOptions.Read(d.Root); XDocument d2 = new XDocument(opt.ToXml()); ValidateAgainstSchema(d2); RepositoryInfoOptions opt2 = RepositoryInfoOptions.Read(d2.Root); Assert.That(opt.IgnoreDirtyWorkingFolder, Is.EqualTo(opt2.IgnoreDirtyWorkingFolder)); Assert.That(opt.RemoteName, Is.EqualTo(opt2.RemoteName)); Assert.That(opt.StartingVersionForCSemVer, Is.EqualTo(opt2.StartingVersionForCSemVer)); Assert.That(opt.Branches.Count, Is.EqualTo(opt2.Branches.Count)); Assert.That(opt.IgnoreModifiedFiles.Count, Is.EqualTo(opt2.IgnoreModifiedFiles.Count)); Assert.That(opt.OnlyPatch, Is.True); Assert.That(opt.SingleMajor, Is.EqualTo(3)); }