GitVersion.Logger.IndentLog C# (CSharp) Method

IndentLog() public static method

public static IndentLog ( string operationDescription ) : IDisposable
operationDescription string
return IDisposable
        public static IDisposable IndentLog(string operationDescription)
        {
            var start = DateTime.Now;
            WriteInfo("Begin: " + operationDescription);
            indent = indent + "  ";
            return new ActionDisposable(() =>
            {
                indent = indent.Substring(0, indent.Length - 2);
                WriteInfo(string.Format(CultureInfo.InvariantCulture, "End: {0} (Took: {1:N}ms)", operationDescription, DateTime.Now.Subtract(start).TotalMilliseconds));
            });
        }

Usage Example

Example #1
0
        /// <summary>
        /// Find the commit where the given branch was branched from another branch.
        /// If there are multiple such commits and branches, tries to guess based on commit histories.
        /// </summary>
        public BranchCommit FindCommitBranchWasBranchedFrom(Branch branch, params Branch[] excludedBranches)
        {
            if (branch == null)
            {
                throw new ArgumentNullException("branch");
            }

            using (Logger.IndentLog(string.Format("Finding branch source of '{0}'", branch.FriendlyName)))
            {
                if (branch.Tip == null)
                {
                    Logger.WriteWarning(string.Format(missingTipFormat, branch.FriendlyName));
                    return(BranchCommit.Empty);
                }

                var possibleBranches = GetMergeCommitsForBranch(branch, excludedBranches)
                                       .Where(b => !branch.IsSameBranch(b.Branch))
                                       .ToList();

                if (possibleBranches.Count > 1)
                {
                    var first = possibleBranches.First();
                    Logger.WriteInfo($"Multiple source branches have been found, picking the first one ({first.Branch.FriendlyName}).\n" +
                                     "This may result in incorrect commit counting.\nOptions were:\n " +
                                     string.Join(", ", possibleBranches.Select(b => b.Branch.FriendlyName)));
                    return(first);
                }

                return(possibleBranches.SingleOrDefault());
            }
        }
All Usage Examples Of GitVersion.Logger::IndentLog