Skip to content

Improve CanRetrieveValidVersionString() #697

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2014

Conversation

someoneigna
Copy link
Contributor

Enforces Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64 - capabilities) format.
The regex is based on the output I'm getting from Repository.Version, "0.17.0-unknown-06d772d (x86 - Threads, Https)".

string versionInfo = Repository.Version;

Assert.NotNull(versionInfo);

bool matched = Regex.IsMatch(versionInfo, @"^\d{1,}\.\d{1,2}\.\d{1,3}-\w+-\w+ \(\w+ - (?:\w*(?:, )*\w+)*\)$");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should structure this test as an example of how to extract version information with regex groups, e.g. "^(?<version>[\d\.]+)-(?<lg2s>\w+)-(?<lg2>\w+) \((?<arch>\w+) - (?<features>.+)\)$".

Then in addition to asserting a pattern match, we can assert that the various captured values aren't empty?

@dahlbyk
Copy link
Member

dahlbyk commented Apr 27, 2014

While we're here, I noticed libgit2/libgit2#2150 explicitly switches from "capabilities" to "features" to avoid confusion. Our documentation of the Version format should do the same.

@someoneigna
Copy link
Contributor Author

Something like: http://rubular.com/r/M3N5oHXxFt

@dahlbyk
Copy link
Member

dahlbyk commented Apr 28, 2014

Works for me :shipit:

string versionInfo = Repository.Version;

// The Repository.Version returned string should contain :
// version:'0.17.0' LibGit2Sharp version number.
// git2SharpHash:'unknown' ( Why is this unknown? ) LibGit2Sharp library hash.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unknown when built from the source code. Otherwise (when relying on a NuGet package for instance), will be the short sha of the LibGit2Sharp commit the assembly has been built from.

in RepositoryFixture

Updated Repository.Version documentation

Updated Repository.Version test
regex now checks each group.

Fixes libgit2#696
@nulltoken nulltoken merged commit d515546 into libgit2:vNext Apr 28, 2014
@nulltoken nulltoken added this to the v0.18.0 milestone Apr 28, 2014
@nulltoken
Copy link
Member

@someoneigna You're on a roll! ✨ ✨ ✨

@someoneigna
Copy link
Contributor Author

Thanks for starting me on this 😄. It's very engaging and entertaining 👍

@someoneigna someoneigna deleted the issue_696 branch April 28, 2014 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants