public PersistentInfo( Repository r ) : this() { if( r == null ) RepositoryError = "No repository."; else { var branch = r.Head; if( branch.Tip == null ) RepositoryError = "Unitialized repository."; else { CommitSha = branch.Tip.Sha; var repositoryStatus = r.Index.RetrieveStatus(); IsDirty = repositoryStatus.Added.Any() || repositoryStatus.Missing.Any() || repositoryStatus.Modified.Any() || repositoryStatus.Removed.Any() || repositoryStatus.Staged.Any(); ReleasedTag = FindReleasedVersion( r, branch.Tip ); if( ReleasedTag.IsValid ) { BranchName = ReleasedTag.BranchName; } else { BranchName = branch.Name; } } } }
/// <summary> /// Initializes a new <see cref="PersistentInfo"/> independent from any git repository. /// </summary> /// <param name="validReleaseTag">A valid release tag.</param> /// <param name="anyCommitSha">Any commit SHA1 (can be any string).</param> public PersistentInfo( ReleaseTagVersion validReleaseTag, string anyCommitSha = null ) : this() { if( !validReleaseTag.IsValid ) throw new ArgumentException(); ReleasedTag = validReleaseTag; BranchName = validReleaseTag.BranchName; CommitSha = anyCommitSha; }
/// <summary> /// Attempts to parse a string like "v4.0.0-master" or "v1.0-5-develop-fix.14". /// Initial 'v' is required. /// Numbers can not start with a 0 (except if it is 0). /// The branch must start with a leter and followed by any number of a-z, A-Z, 0-9, including the _ ([a-zA-Z]\w* regular expression). /// The optional "-fix." must be followed by an integer greater than 0. /// </summary> /// <param name="s">String to parse.</param> /// <param name="v">Resulting version.</param> /// <returns>True on success, false otherwise.</returns> public static bool TryParse( string s, out ReleaseTagVersion v ) { v = TryParse( s ); return v.IsValid; }