/// <summary> /// Converts a GitDescribeTag command result into its component parts in a RecordGitDescribeTag /// <para>The record-->tag value is the actual tag contents</para> /// <para>The record-->commitsSince is the number of commits since this tag was created.</para> /// <para>The record-->commitHash is the id of the commit that this tag is a part of</para> /// </summary> /// <param name="gitDescribeOutput">The output from the Git Describe --Tags command</param> /// <returns>RecordGitDescribeTag</returns> internal static RecordGitDescribeTag GetGitDescribeTag(string gitDescribeOutput) { int gitMetaIndexStart = gitDescribeOutput.LastIndexOf("-g"); ControlFlow.Assert(gitMetaIndexStart != -1, "Git Describe out was not in expected format: [" + gitDescribeOutput + "]"); gitMetaIndexStart += 2; string hash = gitDescribeOutput.Substring(gitMetaIndexStart); // Find the commit count string substr = gitDescribeOutput.Substring(0, gitMetaIndexStart - 2); int commitCountIndex = substr.LastIndexOf('-'); ControlFlow.Assert(commitCountIndex != -1, "Git Describe was not in in expected format. Trying to find CommitCount: [" + gitDescribeOutput + "]"); bool foundCommitCount = int.TryParse(substr.Substring(commitCountIndex + 1), out int commitCount); if (!foundCommitCount) { ControlFlow.Assert(foundCommitCount, "Git Descrive was not in expected format. Unable to determine the Git Commit Count Since. [" + gitDescribeOutput + "]"); } string tag = gitDescribeOutput.Substring(0, commitCountIndex); RecordGitDescribeTag record = new RecordGitDescribeTag(tag, commitCount, hash); return(record); }
/// <summary> /// Finds the latest Ver#.#.# tag on the specified branch returning it in SemVersion format. /// If it cannot find the Version tag it will set SemVer to 0.0.0 /// </summary> /// <param name="branchName"></param> /// <returns></returns> public SemVersion FindLatestSemVersionOnBranch(string branchName) { RecordGitDescribeTag record = FindLatestGitVersionTagOnBranch(branchName); if (record.tag == string.Empty) { return(new SemVersion(0, 0, 0)); } return(ConvertVersionToSemVersion(record.tag)); }
public void GetGitDescribeTag_Success(string output, bool throwsError, string tag, int commits, string hash) { RecordGitDescribeTag record = new RecordGitDescribeTag("", 0, ""); // Test if (!throwsError) { Assert.DoesNotThrow(() => record = GitProcessor.GetGitDescribeTag(output), "A10:"); } else { Assert.Throws <Exception>(() => GitProcessor.GetGitDescribeTag(output), "A20:"); return; } // Validate Assert.AreEqual(tag, record.tag, "A30:"); Assert.AreEqual(commits, record.commitsSince, "A40:"); Assert.AreEqual(hash, record.commitHash, "A50:"); }