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 all 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

Large diffs are not rendered by default.

1,100 changes: 563 additions & 537 deletions Corgibytes.Freshli.Lib.Test/Acceptance.CpanfileDancer2.approved.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
results[0] = { Date: 2020-01-01T00:00:00, ManifestSHA: N/A, LibYear: { _packagesValues: [
{ Name: "drupal/composer_autoloader", RepoVersion: "1.0.0", RepoVersionPublishedAt: 2014-12-24T00:00:00, LatestVersion: "1.3.0", LatestPublishedAt: 2018-03-11T00:00:00, UpgradeAvailable: True, Value: 3.213698630136986 },
{ Name: "drupal/drupal", RepoVersion: "7.69.0", RepoVersionPublishedAt: 2020-05-20T00:00:00, LatestVersion: "8.8.1", LatestPublishedAt: 2019-12-18T00:00:00, UpgradeAvailable: True, Value: 0 },
], Total: 3.213698630136986 } }
results[0] = { Date: 2020-02-01T00:00:00.0000000+00:00, ManifestSHA: N/A, LibYear: { _packagesValues: [
{ Name: "drupal/composer_autoloader", RepoVersion: "1.0.0", RepoVersionPublishedAt: 2014-12-24T20:43:00.0000000+00:00, LatestVersion: "1.3.0", LatestPublishedAt: 2018-03-11T04:18:04.0000000+00:00, UpgradeAvailable: True, Value: 3.211824708269914 },
{ Name: "drupal/drupal", RepoVersion: "7.69.0", RepoVersionPublishedAt: 2020-05-20T16:06:39.0000000+00:00, LatestVersion: "8.8.1", LatestPublishedAt: 2019-12-18T10:34:03.0000000+00:00, UpgradeAvailable: True, Value: 0 },
], Total: 3.211824708269914 } }

3,283 changes: 1,664 additions & 1,619 deletions Corgibytes.Freshli.Lib.Test/Acceptance.RequirementsTxtPyspider.approved.txt

Large diffs are not rendered by default.

13,374 changes: 6,715 additions & 6,659 deletions Corgibytes.Freshli.Lib.Test/Acceptance.RubyGemsClearanceHistoryViaGitHub.approved.txt

Large diffs are not rendered by default.

26,458 changes: 13,372 additions & 13,086 deletions Corgibytes.Freshli.Lib.Test/Acceptance.RubyGemsFeedbinHistoryViaGitHub.approved.txt

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

11 changes: 4 additions & 7 deletions Corgibytes.Freshli.Lib.Test/Acceptance.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using ApprovalTests;
using ApprovalTests.Reporters;
using ApprovalTests.Reporters.TestFrameworks;
using Xunit;

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

private DateTime _testingBoundary =
new DateTime(2020, 01, 01, 0, 0, 0, DateTimeKind.Utc);
private DateTimeOffset _testingBoundary =
new DateTimeOffset(2020, 02, 01, 0, 0, 0, 0, TimeSpan.Zero);

[Fact]
public void RubyGemsWithGitHistory() {
Expand Down Expand Up @@ -50,7 +47,7 @@ public void RubyGemsClearanceHistoryViaGitHub() {
var runner = new Runner();
var results = runner.Run(
"https://github.com/thoughtbot/clearance",
asOf: new DateTime(2020, 06, 01, 00, 00, 00, DateTimeKind.Utc)
asOf: new DateTimeOffset(2020, 06, 01, 00, 00, 00, 00, TimeSpan.Zero)
);

Assert.True(runner.ManifestFinder.Successful);
Expand Down Expand Up @@ -111,7 +108,7 @@ public void SpaCyWithHistoryViaGitHub() {

var results = runner.Run(
"https://github.com/explosion/spaCy",
asOf: new DateTime(2017,6,1,0,0,0)
asOf: new DateTimeOffset(2017, 06, 01, 00, 00, 00, TimeSpan.Zero)
);

Assert.True(runner.ManifestFinder.Successful);
Expand Down
4 changes: 4 additions & 0 deletions Corgibytes.Freshli.Lib.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 Corgibytes.Freshli.Lib.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 Corgibytes.Freshli.Lib.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 Corgibytes.Freshli.Lib.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"
)
);
}
}
}
12 changes: 7 additions & 5 deletions Corgibytes.Freshli.Lib.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(2017, 01, 01, 00, 01, 29, TimeSpan.FromHours(-8)),
new(2018, 01, 01, 00, 00, 59, TimeSpan.FromHours(-8)),
new(2019, 01, 01, 00, 00, 46, TimeSpan.FromHours(-8))
};

Assert.Equal(expectedDates, history.Dates);
Expand All @@ -40,7 +40,9 @@ public void ContentsAsOf2017() {

var rubyFixturePath = Fixtures.Path("ruby", "nokotest");
var history = new GitFileHistory(rubyFixturePath, "Gemfile.lock");
var contents = history.ContentsAsOf(new DateTime(2017, 02, 01));
var contents = history.ContentsAsOf(
new DateTimeOffset(2017, 02, 01, 00, 00, 00, TimeSpan.Zero)
);

Assert.Equal(expectedContents, contents);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class NuGetRepositoryTest {
public void VersionInfo() {
var versionInfo = _repository.VersionInfo("Newtonsoft.Json", "12.0.3");
var expectedDate =
new DateTime(2019, 11, 09, 01, 27, 30, 723, DateTimeKind.Utc);
new DateTimeOffset(2019, 11, 09, 01, 27, 30, 723, TimeSpan.Zero);

Assert.Equal("12.0.3", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -27,7 +27,7 @@ public void VersionInfoThrowsExceptionIfNotFound() {
[Fact]
public void Latest() {
var asOfDate =
new DateTime(2019, 11, 10, 01, 27, 30, 723, DateTimeKind.Utc);
new DateTimeOffset(2019, 11, 10, 01, 27, 30, 723, TimeSpan.Zero);
var latest = _repository.Latest("Newtonsoft.Json", asOfDate, false);

Assert.Equal("12.0.3", latest.Version);
Expand All @@ -38,7 +38,7 @@ public void LatestThrowsExceptionIfNotFound() {
Assert.Throws<LatestVersionNotFoundException>(testCode: () =>
new NuGetRepository().Latest(
"Newtonsoft.Json",
new DateTime(1900, 11, 10, 01, 27, 30, 723, DateTimeKind.Utc),
new DateTimeOffset(1900, 11, 10, 01, 27, 30, 723, TimeSpan.Zero),
false
)
);
Expand All @@ -47,14 +47,14 @@ public void LatestThrowsExceptionIfNotFound() {
[Fact]
public void VersionsBetween() {
var asOfDate =
new DateTime(2019, 11, 10, 01, 27, 30, 723, DateTimeKind.Utc);
new DateTimeOffset(2019, 11, 10, 01, 27, 30, 723, TimeSpan.Zero);
var versionsBetween = _repository.VersionsBetween(
"Newtonsoft.Json",
asOfDate,
new FreshliNuGetVersionInfo(
new NuGetVersion("11.0.2"), DateTime.UtcNow),
new NuGetVersion("11.0.2"), DateTimeOffset.UtcNow),
new FreshliNuGetVersionInfo(
new NuGetVersion("12.0.3"), DateTime.UtcNow),
new NuGetVersion("12.0.3"), DateTimeOffset.UtcNow),
false
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public void VersionInfoWithoutModuleSeparator() {
var repository = new MetaCpanRepository();
var versionInfo = repository.VersionInfo("Plack", "1.0026");
var expectedDate =
new DateTime(2013, 06, 13, 06, 01, 17, DateTimeKind.Utc);
new DateTimeOffset(2013, 06, 13, 06, 01, 17, TimeSpan.Zero);

Assert.Equal("1.0026", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -20,7 +20,7 @@ public void VersionInfoWithModuleSeparator() {
var repository = new MetaCpanRepository();
var versionInfo = repository.VersionInfo("Test::More", "1.301001_048");
var expectedDate =
new DateTime(2014, 09, 25, 03, 39, 01, DateTimeKind.Utc);
new DateTimeOffset(2014, 09, 25, 03, 39, 01, TimeSpan.Zero);

Assert.Equal("1.301001_048", versionInfo.Version);
Assert.Equal(expectedDate, versionInfo.DatePublished);
Expand All @@ -29,17 +29,17 @@ public void VersionInfoWithModuleSeparator() {
[Fact]
public void LatestAsOf() {
var repository = new MetaCpanRepository();
var targetDate = new DateTime(2018, 01, 01, 0, 0, 0, DateTimeKind.Utc);
var targetDate = new DateTimeOffset(2018, 01, 01, 0, 0, 0, TimeSpan.Zero);
var versionInfo = repository.Latest(
"Plack", targetDate, includePreReleases: false);
var expectedDate = new DateTime(
var expectedDate = new DateTimeOffset(
2017,
12,
31,
20,
42,
50,
DateTimeKind.Utc
TimeSpan.Zero
);

Assert.Equal("1.0045", versionInfo.Version);
Expand Down Expand Up @@ -72,20 +72,20 @@ public void LatestMatchingVersionExpression(
string expectedVersion
) {
var repository = new MetaCpanRepository();
var targetDate = new DateTime(2018, 01, 01, 0, 0, 0, DateTimeKind.Utc);
var targetDate = new DateTimeOffset(2018, 01, 01, 0, 0, 0, TimeSpan.Zero);
var versionInfo = repository.Latest(
packageName,
asOf: targetDate,
thatMatches: versionExpression
);
var expectedDate = new DateTime(
var expectedDate = new DateTimeOffset(
expectedYear,
expectedMonth,
expectedDay,
expectedHour,
expectedMinute,
expectedSecond,
DateTimeKind.Utc
TimeSpan.Zero
);

Assert.Equal(expectedVersion, versionInfo.Version);
Expand All @@ -95,7 +95,8 @@ string expectedVersion
[Fact]
public void VersionsBetween() {
var repository = new MetaCpanRepository();
var targetDate = new DateTime(2015, 01, 01);
var targetDate =
new DateTimeOffset(2015, 01, 01, 00, 00, 00, TimeSpan.Zero);
var earlierVersion = new SemVerVersionInfo("1.0027");
var laterVersion = new SemVerVersionInfo("1.0045");

Expand Down
Loading