Example #1
0
        public void options_can_contain_IgnoreModified_files()
        {
            var    repoTest     = TestHelper.TestGitRepository;
            string fileToChange = Directory.EnumerateFiles(repoTest.Path).FirstOrDefault();

            Assume.That(fileToChange, Is.Not.Null);

            Console.WriteLine("Modifiying '{0}'.", fileToChange);

            byte[] original = File.ReadAllBytes(fileToChange);

            try
            {
                var options = new RepositoryInfoOptions();

                RepositoryInfo info;

                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False);

                File.WriteAllText(fileToChange, "!MODIFIED!");
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.True);

                options.IgnoreModifiedFiles.Add(fileToChange.Substring(repoTest.Path.Length + 1));
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False);
            }
            finally
            {
                File.WriteAllBytes(fileToChange, original);
            }
        }
        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"));
        }
Example #3
0
        /// <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));
        }
Example #6
0
        public void options_IgnoreModified_files_filter()
        {
            var repoTest = TestHelper.TestGitRepository;
            repoTest.CheckOut( "origin/parallel-world" );

            string devPath = Path.Combine( repoTest.Path, "Dev in Alpha.txt" );
            string devTxt = File.ReadAllText( devPath );
            Assume.That( devTxt, Is.EqualTo( "Dev in Aplpha." ) );

            string realDevPath = Path.Combine( repoTest.Path, "Real Dev in Alpha.txt" ); ;
            string realDevTxt = File.ReadAllText( realDevPath );
            Assume.That( realDevTxt, Is.EqualTo( "Real Dev in Alpha." ) );

            try
            {
                RepositoryInfo info;
                var options = new RepositoryInfoOptions();
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False, "Working folder is clean." );

                File.WriteAllText( devPath, "!MODIFIED!" + devTxt );
                File.WriteAllText( realDevPath, "!MODIFIED!" + realDevTxt );

                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, "Working folder is dirty." );

                options.IgnoreModifiedFiles.Add( "Dev in Alpha.txt" );
                options.IgnoreModifiedFiles.Add( "Real Dev in Alpha.txt" );
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFiles explicitly ignores the 2 files." );

                int nbCall = 0;
                options.IgnoreModifiedFiles.Clear();
                options.IgnoreModifiedFilePredicate = m =>
                {
                    // Always returns true: the file is NOT modified.
                    ++nbCall;
                    return true;
                };
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFilePredicate explicitly ignores all files." );
                Assert.That( nbCall, Is.EqualTo( 2 ) );

                nbCall = 0;
                options.IgnoreModifiedFilePredicate = m =>
                {
                    // Returns false: the file is actually modified.
                    // without IgnoreModifiedFileFullProcess, this stops the lookups.
                    ++nbCall;
                    return false;
                };
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, "Working folder is dirty (IgnoreModifiedFilePredicate returned false)." );
                Assert.That( nbCall, Is.EqualTo( 1 ), "As soon as the predicate returns false, the lookup stops." );

                nbCall = 0;
                options.IgnoreModifiedFileFullProcess = true;
                options.IgnoreModifiedFilePredicate = m =>
                {
                    // Returns false: the file is actually modified.
                    // with IgnoreModifiedFileFullProcess = true, the process continues.
                    ++nbCall;
                    return false;
                };
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, "Working folder is dirty (IgnoreModifiedFilePredicate returned false)." );
                Assert.That( nbCall, Is.EqualTo( 2 ), "Thanks to IgnoreModifiedFileFullProcess, all modified files are processed." );

                nbCall = 0;
                options.IgnoreModifiedFiles.Add( "Dev in Alpha.txt" );
                options.IgnoreModifiedFilePredicate = m =>
                {
                    ++nbCall;
                    Assert.That( m.Path, Is.Not.EqualTo( "Dev in Alpha.txt" ), "This has been filtered by IgnoreModifiedFiles set." );
                    Assert.That( m.CommittedText, Is.EqualTo( "Real Dev in Alpha." ) );
                    return m.Path == "Real Dev in Alpha.txt";
                };
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFiles ignores one file and ModifiedFileFilter ignores the other one." );
                Assert.That( nbCall, Is.EqualTo( 1 ) );
            }
            finally
            {
                File.WriteAllText( devPath, devTxt );
                File.WriteAllText( realDevPath, realDevTxt );
            }
        }
Example #7
0
        public void options_can_contain_IgnoreModified_files()
        {
            var repoTest = TestHelper.TestGitRepository;
            string fileToChange = Directory.EnumerateFiles( repoTest.Path ).FirstOrDefault();
            Assume.That( fileToChange, Is.Not.Null );

            Console.WriteLine( "Modifiying '{0}'.", fileToChange );

            byte[] original = File.ReadAllBytes( fileToChange );

            try
            {
                var options = new RepositoryInfoOptions();

                RepositoryInfo info;

                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False );

                File.WriteAllText( fileToChange, "!MODIFIED!" );
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.True );

                options.IgnoreModifiedFiles.Add( fileToChange.Substring( repoTest.Path.Length + 1 ) );
                info = repoTest.GetRepositoryInfo( options );
                Assert.That( info.IsDirty, Is.False );
            }
            finally
            {
                File.WriteAllBytes( fileToChange, original );
            }
        }
Example #8
0
        public void options_IgnoreModified_files_filter()
        {
            var repoTest = TestHelper.TestGitRepository;

            repoTest.CheckOut("origin/parallel-world");

            string devPath = Path.Combine(repoTest.Path, "Dev in Alpha.txt");
            string devTxt  = File.ReadAllText(devPath);

            Assume.That(devTxt, Is.EqualTo("Dev in Aplpha."));

            string realDevPath = Path.Combine(repoTest.Path, "Real Dev in Alpha.txt");;
            string realDevTxt  = File.ReadAllText(realDevPath);

            Assume.That(realDevTxt, Is.EqualTo("Real Dev in Alpha."));

            try
            {
                RepositoryInfo info;
                var            options = new RepositoryInfoOptions();
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False, "Working folder is clean.");

                File.WriteAllText(devPath, "!MODIFIED!" + devTxt);
                File.WriteAllText(realDevPath, "!MODIFIED!" + realDevTxt);

                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, "Working folder is dirty.");

                options.IgnoreModifiedFiles.Add("Dev in Alpha.txt");
                options.IgnoreModifiedFiles.Add("Real Dev in Alpha.txt");
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFiles explicitly ignores the 2 files.");

                int nbCall = 0;
                options.IgnoreModifiedFiles.Clear();
                options.IgnoreModifiedFilePredicate = m =>
                {
                    // Always returns true: the file is NOT modified.
                    ++nbCall;
                    return(true);
                };
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFilePredicate explicitly ignores all files.");
                Assert.That(nbCall, Is.EqualTo(2));

                nbCall = 0;
                options.IgnoreModifiedFilePredicate = m =>
                {
                    // Returns false: the file is actually modified.
                    // without IgnoreModifiedFileFullProcess, this stops the lookups.
                    ++nbCall;
                    return(false);
                };
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, "Working folder is dirty (IgnoreModifiedFilePredicate returned false).");
                Assert.That(nbCall, Is.EqualTo(1), "As soon as the predicate returns false, the lookup stops.");

                nbCall = 0;
                options.IgnoreModifiedFileFullProcess = true;
                options.IgnoreModifiedFilePredicate   = m =>
                {
                    // Returns false: the file is actually modified.
                    // with IgnoreModifiedFileFullProcess = true, the process continues.
                    ++nbCall;
                    return(false);
                };
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, "Working folder is dirty (IgnoreModifiedFilePredicate returned false).");
                Assert.That(nbCall, Is.EqualTo(2), "Thanks to IgnoreModifiedFileFullProcess, all modified files are processed.");

                nbCall = 0;
                options.IgnoreModifiedFiles.Add("Dev in Alpha.txt");
                options.IgnoreModifiedFilePredicate = m =>
                {
                    ++nbCall;
                    Assert.That(m.Path, Is.Not.EqualTo("Dev in Alpha.txt"), "This has been filtered by IgnoreModifiedFiles set.");
                    Assert.That(m.CommittedText, Is.EqualTo("Real Dev in Alpha."));
                    return(m.Path == "Real Dev in Alpha.txt");
                };
                info = repoTest.GetRepositoryInfo(options);
                Assert.That(info.IsDirty, Is.False, "Working folder is dirty but IgnoreModifiedFiles ignores one file and ModifiedFileFilter ignores the other one.");
                Assert.That(nbCall, Is.EqualTo(1));
            }
            finally
            {
                File.WriteAllText(devPath, devTxt);
                File.WriteAllText(realDevPath, realDevTxt);
            }
        }