Skip to content
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

Experiments with wrapping git CLI command with CliWrap #243

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
4fff864
Adds GitRepository class that wraps git command line
mscottford Feb 19, 2021
c045c29
Merge branch 'main' into git-cli
mscottford Feb 19, 2021
e4fa46b
Switches to XUnit diff reporter to get better output in CI
mscottford Feb 19, 2021
f7ff34e
Adds missing references
mscottford Feb 19, 2021
187b1a6
Switches path separator to Unix-style
mscottford Feb 19, 2021
afbcc9a
Sorts contents to get consistent output across platforms
mscottford Feb 19, 2021
e32d552
Wraps long line
mscottford Feb 19, 2021
e5a642b
Adjusts approvals configuration
mscottford Feb 19, 2021
c50ce29
Adds support for parsing platform specific ruby gem version names
mscottford Mar 1, 2021
c85f976
TODO: squash with previous
mscottford Mar 1, 2021
59ce93b
TODO: squash with previous
mscottford Mar 1, 2021
a35fb3e
Use DateTimeOffset instead of DateTime
mscottford Mar 1, 2021
9e764c1
Use .atom endpoint for retrieving ruby version information
mscottford Mar 1, 2021
e1002c8
Switches to compare against DateTimeOffset
mscottford Mar 1, 2021
e811369
Merge branch 'main' into git-cli
mscottford Mar 8, 2021
100f321
Switches to DateTimeOffset
mscottford Mar 8, 2021
04c9df7
Changes date format
mscottford Mar 8, 2021
ff1eafe
Switches date format
mscottford Mar 8, 2021
2b437d7
Use DateTimeOffset instead of DateTime
mscottford Mar 8, 2021
0fe4796
Adds test to evaluate calling the RubyGems repository repeatedly
mscottford Mar 8, 2021
d84d05b
Uses DateTimeOffset instead of DateTime
mscottford Mar 8, 2021
76c752b
Removes versions and adds more packages to better stress test
mscottford Mar 12, 2021
a029f8a
Replaces uses of `DateTime` with `DateTimeOffset`
mscottford Mar 12, 2021
26538ea
Fixes bug with caching
mscottford Mar 13, 2021
90af1f5
Updates approved files to reflect recent changes
mscottford Mar 15, 2021
9f1f218
Adjusts date ranges so they start with the date of oldest file change
mscottford Mar 19, 2021
268de94
Uses time zone from `asOf` value to compute date range increments
mscottford Mar 19, 2021
aa7cc06
Adds more gems to the rubygems stress test
mscottford Mar 19, 2021
52b1339
Adjusts the testing boundary used for acceptance tests
mscottford Mar 19, 2021
901af52
Updates approvals based on recent changes
mscottford Mar 19, 2021
e75fdc3
Merge branch 'main' into git-cli
mscottford Mar 20, 2021
0823b13
Committing auto generated change log.
mscottford Mar 20, 2021
9fde253
Wraps lines longer than 80 characters
mscottford Mar 20, 2021
e85b623
Merge branch 'main' into git-cli
mscottford Mar 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
272 changes: 136 additions & 136 deletions Freshli.Test/Acceptance.ComposerWithoutGitHistory.approved.txt

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions Freshli.Test/Acceptance.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System;
using ApprovalTests;
using ApprovalTests.Reporters;
using ApprovalTests.Reporters.TestFrameworks;
using Xunit;

namespace Freshli.Test {
[UseReporter(typeof(XUnit2Reporter))]
public class Acceptance {

private DateTime _testingBoundary =
Expand Down
4 changes: 4 additions & 0 deletions Freshli.Test/ApprovalTestsConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using ApprovalTests.Reporters;
using Freshli.Test;

[assembly: UseReporter(typeof(FreshliApprovalsReporter))]
14 changes: 14 additions & 0 deletions Freshli.Test/FreshliApprovalsReporter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using ApprovalTests.Reporters;
using ApprovalTests.Reporters.TestFrameworks;

namespace Freshli.Test {
class FreshliApprovalsReporter : FirstWorkingReporter {
public FreshliApprovalsReporter() : base(
RiderReporter.INSTANCE,
BeyondCompareReporter.INSTANCE,
VisualStudioReporter.INSTANCE,
XUnit2Reporter.INSTANCE,
DiffReporter.INSTANCE
) { }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
files[0] = /.git/config
files[1] = /.git/description
files[2] = /.git/HEAD
files[3] = /.git/hooks/applypatch-msg.sample
files[4] = /.git/hooks/commit-msg.sample
files[5] = /.git/hooks/fsmonitor-watchman.sample
files[6] = /.git/hooks/post-update.sample
files[7] = /.git/hooks/pre-applypatch.sample
files[8] = /.git/hooks/pre-commit.sample
files[9] = /.git/hooks/pre-merge-commit.sample
files[10] = /.git/hooks/pre-push.sample
files[11] = /.git/hooks/pre-rebase.sample
files[12] = /.git/hooks/pre-receive.sample
files[13] = /.git/hooks/prepare-commit-msg.sample
files[14] = /.git/hooks/push-to-checkout.sample
files[15] = /.git/hooks/update.sample
files[16] = /.git/index
files[17] = /.git/info/exclude
files[18] = /.git/logs/HEAD
files[19] = /.git/logs/refs/heads/master
files[20] = /.git/logs/refs/remotes/origin/HEAD
files[21] = /.git/objects/pack/pack-e4a774ac9dbfc86d77f95bc8244ac029df16663d.idx
files[22] = /.git/objects/pack/pack-e4a774ac9dbfc86d77f95bc8244ac029df16663d.pack
files[23] = /.git/packed-refs
files[24] = /.git/refs/heads/master
files[25] = /.git/refs/remotes/origin/HEAD
files[26] = /Gemfile
files[27] = /Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"

gem 'nokogiri', '1.8.1'

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
GEM
remote: https://rubygems.org/
specs:
mini_portile2 (2.1.0)
nokogiri (1.7.0)
mini_portile2 (~> 2.1.0)

PLATFORMS
ruby

DEPENDENCIES
nokogiri (= 1.7.0)

BUNDLED WITH
2.1.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Gemfile[0] = [1/1/2019 8:00:46 AM, 017031627f36deb582d69cddd381718be0044b02]
Gemfile[1] = [1/1/2018 8:00:59 AM, 902a3082740f83776eec419c59a56e54424fdec5]
Gemfile[2] = [1/1/2017 8:01:29 AM, 13963f09081c175c66d20f7dd15d23fedc789ce4]
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2017-01-01T00:01:29.0000000-08:00 => 13963f09081c175c66d20f7dd15d23fedc789ce4
2018-01-01T00:00:59.0000000-08:00 => 902a3082740f83776eec419c59a56e54424fdec5
2019-01-01T00:00:46.0000000-08:00 => 017031627f36deb582d69cddd381718be0044b02
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
2017-01-01T00:01:29.0000000-08:00 => 13963f09081c175c66d20f7dd15d23fedc789ce4
2018-01-01T00:00:59.0000000-08:00 => 902a3082740f83776eec419c59a56e54424fdec5
2019-01-01T00:00:46.0000000-08:00 => 017031627f36deb582d69cddd381718be0044b02
112 changes: 112 additions & 0 deletions Freshli.Test/Integration/GitCliRepositoryTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using System.IO;
using System.Linq;
using ApprovalTests;
using Xunit;

namespace Freshli.Test.Integration {
public class GitCliRepositoryTest {
[Fact]
public void IsValidReturnsTrue() {
var fixturePath = Fixtures.Path("ruby", "nokotest");
Assert.True(GitCliRepository.IsValid(fixturePath));
}

[Fact]
public void IsValidReturnsFalse() {
var fixturePath = Fixtures.Path("empty");
Assert.False(GitCliRepository.IsValid(fixturePath));
}

[Fact]
public void IsCloneableReturnsTrue() {
var path = "https://github.com/corgibytes/freshli-fixture-ruby-nokotest";
Assert.True(GitCliRepository.IsCloneable(path));
}

[Fact]
public void IsCloneableReturnsFalse() {
var path = "invalid";
Assert.False(GitCliRepository.IsCloneable(path));
}

private void ForceDelete(string path) {
var directory = new DirectoryInfo(path);
directory.DeleteReadOnly();
}

[Fact]
public void CloneValidRepo() {
var repoUrl =
"https://github.com/corgibytes/freshli-fixture-ruby-nokotest";
var targetDir = Path.Combine(Path.GetTempPath(), "clone-valid-repo");

if (Directory.Exists(targetDir)) {
ForceDelete(targetDir);
}

GitCliRepository.Clone(repoUrl, targetDir);
var files = Directory.GetFiles(
targetDir,
"*",
new EnumerationOptions() {
AttributesToSkip = 0,
RecurseSubdirectories = true
}
);
Approvals.VerifyAll(
files.Select(f =>
f.Replace(targetDir, "").Replace("\\", "/")).OrderBy(f => f),
"files"
);
ForceDelete(targetDir);
}

[Fact]
public void LogEntriesForRubyGemfile() {
var fixturePath = Fixtures.Path("ruby", "nokotest");
var repository = new GitCliRepository(fixturePath);

Approvals.VerifyAll(
repository.LogEntriesFor("Gemfile"),
(date, sha) => $"{date.ToString("O")} => {sha}"
);
}

[Fact]
public void LogEntriesForRubyGemfileDotLock() {
var fixturePath = Fixtures.Path("ruby", "nokotest");
var repository = new GitCliRepository(fixturePath);

Approvals.VerifyAll(
repository.LogEntriesFor("Gemfile.lock"),
(date, sha) => $"{date.ToString("O")} => {sha}"
);
}

[Fact]
public void FileContentsForShaForRubyGemfile() {
var fixturePath = Fixtures.Path("ruby", "nokotest");
var repository = new GitCliRepository(fixturePath);

Approvals.Verify(
repository.FileContentsFromSha(
"Gemfile",
"902a3082740f83776eec419c59a56e54424fdec5"
)
);
}

[Fact]
public void FileContentsForShaForRubyGemfileDotLock() {
var fixturePath = Fixtures.Path("ruby", "nokotest");
var repository = new GitCliRepository(fixturePath);

Approvals.Verify(
repository.FileContentsFromSha(
"Gemfile.lock",
"13963f09081c175c66d20f7dd15d23fedc789ce4"
)
);
}
}
}
8 changes: 4 additions & 4 deletions Freshli.Test/Integration/GitFileHistoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public void Dates() {
var rubyFixturePath = Fixtures.Path("ruby", "nokotest");
var history = new GitFileHistory(rubyFixturePath, "Gemfile.lock");

var expectedDates = new List<DateTime>() {
new DateTime(2017, 01, 01),
new DateTime(2018, 01, 01),
new DateTime(2019, 01, 01)
var expectedDates = new List<DateTimeOffset>() {
new(new DateTime(2017, 01, 01, 00, 01, 29), TimeSpan.FromHours(-8)),
new(new DateTime(2018, 01, 01, 00, 00, 59), TimeSpan.FromHours(-8)),
new(new DateTime(2019, 01, 01, 00, 00, 46), TimeSpan.FromHours(-8))
};

Assert.Equal(expectedDates, history.Dates);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ public void VersionInfo() {
);
var versionInfo = repository.VersionInfo("monolog/monolog", "1.11.0");

Assert.Equal(new DateTime(2014, 09, 30), versionInfo.DatePublished);
Assert.Equal(
new DateTimeOffset(2014, 09, 30, 13, 30, 58, TimeSpan.Zero),
versionInfo.DatePublished
);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class RubyGemsRepositoryTest {
public void VersionInfoCorrectlyCreatesVersion() {
var repository = new RubyGemsRepository();
var versionInfo = repository.VersionInfo("tzinfo", "1.2.7");
var expectedDate = new DateTime(2020, 04, 02);
var expectedDate =
new DateTimeOffset(2020, 04, 02, 21, 42, 11, TimeSpan.Zero);

Assert.Equal("1.2.7", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -19,7 +20,8 @@ public void VersionInfoCorrectlyCreatesVersion() {
public void VersionInfoCorrectlyCreatesPreReleaseVersion() {
var repository = new RubyGemsRepository();
var versionInfo = repository.VersionInfo("git", "1.6.0.pre1");
var expectedDate = new DateTime(2020, 01, 20);
var expectedDate =
new DateTimeOffset(2020, 01, 20, 20, 50, 43, TimeSpan.Zero);

Assert.Equal("1.6.0.pre1", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -30,7 +32,8 @@ public void LatestAsOfCorrectlyFindsLatestVersion() {
var repository = new RubyGemsRepository();
var targetDate = new DateTime(2020, 02, 01);
var versionInfo = repository.Latest("git", targetDate, false);
var expectedDate = new DateTime(2018, 08, 10);
var expectedDate =
new DateTimeOffset(2018, 08, 10, 07, 58, 25, TimeSpan.Zero);

Assert.Equal("1.5.0", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -42,7 +45,8 @@ public void
var repository = new RubyGemsRepository();
var targetDate = new DateTime(2020, 02, 01);
var versionInfo = repository.Latest("git", targetDate, true);
var expectedDate = new DateTime(2020, 01, 20);
var expectedDate =
new DateTimeOffset(2020, 01, 20, 20, 50, 43, TimeSpan.Zero);

Assert.Equal("1.6.0.pre1", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand Down
32 changes: 18 additions & 14 deletions Freshli.Test/Integration/LibYearCalculatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ public void ComputeAsOf() {
Assert.Equal(0.0, results["mini_portile2"].Value, 3);
Assert.Equal("2.1.0", results["mini_portile2"].Version);
Assert.Equal(
new DateTime(2016, 01, 06),
new DateTimeOffset(2016, 01, 06, 19, 10, 42, TimeSpan.Zero),
results["mini_portile2"].PublishedAt
);
Assert.Equal("2.1.0", results["mini_portile2"].LatestVersion);
Assert.Equal(
new DateTime(2016, 01, 06),
new DateTimeOffset(2016, 01, 06, 19, 10, 42, TimeSpan.Zero),
results["mini_portile2"].LatestPublishedAt
);
Assert.False(results["mini_portile2"].UpgradeAvailable);
Assert.Equal(0.227, results["nokogiri"].Value, 3);
Assert.Equal("1.7.0", results["nokogiri"].Version);
Assert.Equal(
new DateTime(2016, 12, 27),
new DateTimeOffset(2016, 12, 27, 03, 49, 28, TimeSpan.Zero),
results["nokogiri"].PublishedAt);
Assert.Equal("1.7.1", results["nokogiri"].LatestVersion);
Assert.Equal(
new DateTime(2017, 03, 20),
new DateTimeOffset(2017, 03, 20, 03, 39, 14, TimeSpan.Zero),
results["nokogiri"].LatestPublishedAt);
Assert.True(results["nokogiri"].UpgradeAvailable);
}
Expand Down Expand Up @@ -96,14 +96,16 @@ public void ComputeAsOfOtherEdgeCase() {

var calculator = new LibYearCalculator(repository, manifest);

var results = calculator.ComputeAsOf(new DateTime(2018, 02, 01));
var results = calculator.ComputeAsOf(
new DateTimeOffset(2018, 02, 01, 00, 00, 00, TimeSpan.FromHours(-5))
);

Assert.Equal(0.362, results.Total, 3);
Assert.Equal(0.361, results.Total, 3);

Assert.Equal(0.0, results["mini_portile2"].Value, 3);
Assert.Equal("2.3.0", results["mini_portile2"].LatestVersion);
Assert.False(results["mini_portile2"].UpgradeAvailable);
Assert.Equal(0.362, results["nokogiri"].Value, 3);
Assert.Equal(0.361, results["nokogiri"].Value, 3);
Assert.Equal("1.8.2", results["nokogiri"].LatestVersion);
Assert.True(results["nokogiri"].UpgradeAvailable);
}
Expand Down Expand Up @@ -151,12 +153,12 @@ public void ComputeAsOfWithPreReleaseVersion() {
Assert.Equal(0.063, results["google-protobuf"].Value, 3);
Assert.Equal("3.12.0.rc.1", results["google-protobuf"].Version);
Assert.Equal(
new DateTime(2020, 05, 04),
new DateTimeOffset(2020, 05, 04, 22, 46, 23, TimeSpan.Zero),
results["google-protobuf"].PublishedAt
);
Assert.Equal("3.12.2", results["google-protobuf"].LatestVersion);
Assert.Equal(
new DateTime(2020, 05, 27),
new DateTimeOffset(2020, 05, 27, 18, 50, 26, TimeSpan.Zero),
results["google-protobuf"].LatestPublishedAt
);
Assert.True(results["google-protobuf"].UpgradeAvailable);
Expand All @@ -169,18 +171,20 @@ public void ComputeAsOfWithLatestVersionBeingPreReleaseVersion() {
var repository = new RubyGemsRepository();
var calculator = new LibYearCalculator(repository, manifest);

var results = calculator.ComputeAsOf(new DateTime(2019, 11, 25));
var results = calculator.ComputeAsOf(
new DateTimeOffset(2019, 11, 25, 00, 00, 00, TimeSpan.FromHours(-5))
);

Assert.Equal(0.216, results.Total, 3);
Assert.Equal(0.216, results["google-protobuf"].Value, 3);
Assert.Equal(0.214, results.Total, 3);
Assert.Equal(0.214, results["google-protobuf"].Value, 3);
Assert.Equal("3.10.0.rc.1", results["google-protobuf"].Version);
Assert.Equal(
new DateTime(2019, 09, 05),
new DateTimeOffset(2019, 09, 05, 19, 43, 14, TimeSpan.Zero),
results["google-protobuf"].PublishedAt
);
Assert.Equal("3.11.0.rc.2", results["google-protobuf"].LatestVersion);
Assert.Equal(
new DateTime(2019, 11, 23),
new DateTimeOffset(2019, 11, 23, 00, 10, 38, TimeSpan.Zero),
results["google-protobuf"].LatestPublishedAt
);
Assert.True(results["google-protobuf"].UpgradeAvailable);
Expand Down
2 changes: 1 addition & 1 deletion Freshli.Test/Integration/LocalFileHistoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void Dates() {
var emptyFixturePath = Fixtures.Path("empty");
var history = new LocalFileHistory(emptyFixturePath, "readme.md");

Assert.Equal(new List<DateTime> {DateTime.Today}, history.Dates);
Assert.Equal(new List<DateTimeOffset> {DateTime.Today}, history.Dates);
}

[Fact]
Expand Down
Loading