Skip to content

Commit

Permalink
Check for pending commits; add code analyzers; add license
Browse files Browse the repository at this point in the history
  • Loading branch information
dswisher committed Jun 5, 2022
1 parent 6d22b7c commit 5a9de52
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 25 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@
bin
obj

src/nupkg

21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2022 Doug Swisher

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* [LibGit2Sharp](https://github.com/libgit2/libgit2sharp)
* [Blog post](https://edi.wang/post/2019/3/26/operate-git-with-net-core) with some examples
* [Spectre.Console](https://github.com/spectreconsole/spectre.console)
* [System.IO.Abstractions](https://github.com/TestableIO/System.IO.Abstractions)
* [Humanizer](https://github.com/Humanizr/Humanizer)


## Similar Tools
Expand Down
7 changes: 5 additions & 2 deletions src/Commands/CheckCommand.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Linq;
using GitUpdater.Helpers;
using GitUpdater.Settings;
Expand Down Expand Up @@ -45,11 +48,11 @@ public override int Execute(CommandContext context, CheckSettings settings)

if (problems.Any())
{
ansiConsole.MarkupLine($"{repoDir}:");
ansiConsole.MarkupLine($":cross_mark: {repoDir}:");

foreach (var issue in problems)
{
ansiConsole.MarkupLine($" :cross_mark: {issue}");
ansiConsole.MarkupLine($" - {issue}");
}
}
}
Expand Down
43 changes: 31 additions & 12 deletions src/GitUpdater.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>
</PropertyGroup>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>disable</Nullable>

<ItemGroup>
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Spectre.Console" Version="0.44.0" />
<PackageReference Include="Spectre.Console.Analyzer" Version="0.44.0" />
</ItemGroup>
<CodeAnalysisRuleSet>stylecop.ruleset</CodeAnalysisRuleSet>

<PackAsTool>true</PackAsTool>
<ToolCommandName>gup</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="LibGit2Sharp" Version="0.26.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.0" />
<PackageReference Include="Roslyn.System.IO.Abstractions.Analyzers" Version="12.2.19">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Spectre.Console" Version="0.44.0" />
<PackageReference Include="Spectre.Console.Analyzer" Version="0.44.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="17.0.15" />
</ItemGroup>

<ItemGroup>
<AdditionalFiles Include="stylecop.json" />
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions src/Helpers/IRepoFinder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;

namespace GitUpdater.Helpers
Expand Down
3 changes: 3 additions & 0 deletions src/Helpers/RepoFinder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using System.Collections.Generic;
using System.IO;
Expand Down
3 changes: 3 additions & 0 deletions src/Infrastructure/TypeRegistrar.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
Expand Down
3 changes: 3 additions & 0 deletions src/Infrastructure/TypeResolver.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using Spectre.Console.Cli;

Expand Down
15 changes: 15 additions & 0 deletions src/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

.PHONY: install uninstall update pack

pack:
dotnet pack

install: pack
dotnet tool install --global --add-source ./nupkg GitUpdater

update: pack
dotnet tool update --global --add-source ./nupkg GitUpdater

uninstall:
dotnet tool uninstall --global GitUpdater

7 changes: 5 additions & 2 deletions src/Program.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System;
using GitUpdater.Commands;
using GitUpdater.Infrastructure;
using Microsoft.Extensions.DependencyInjection;
using Spectre.Console.Cli;
using Spectre.Console;
using Spectre.Console.Cli;

namespace GitUpdater
{
Expand Down
3 changes: 3 additions & 0 deletions src/Settings/CheckSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.ComponentModel;
using Spectre.Console.Cli;

Expand Down
3 changes: 3 additions & 0 deletions src/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using GitUpdater.Commands;
using GitUpdater.Helpers;
using GitUpdater.Wrapper;
Expand Down
29 changes: 23 additions & 6 deletions src/Wrapper/GitChecker.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using System.Linq;
using Humanizer;
using LibGit2Sharp;

namespace GitUpdater.Wrapper
{
public class GitChecker : IGitChecker
{

public List<string> CheckRepo(IRepository repo)
{
// Keep a list of problems that have been found
Expand All @@ -18,11 +21,25 @@ public List<string> CheckRepo(IRepository repo)
// Check the branch
// TODO - branch check

// Check for un-pushed commits
// TODO - check un-pushed commits
// Check for un-pushed commits and un-merged commits
var ahead = repo.Head.TrackingDetails.AheadBy.GetValueOrDefault();
var behind = repo.Head.TrackingDetails.BehindBy.GetValueOrDefault();

// Check for un-merged commits
// TODO - check to un-merged commits
if (ahead > 0)
{
if (behind > 0)
{
problems.Add($"is ahead by {ahead} and behind by {behind} commits.");
}
else
{
problems.Add($"is ahead by {"commit".ToQuantity(ahead)}.");
}
}
else if (behind > 0)
{
problems.Add($"is behind by {"commit".ToQuantity(behind)}.");
}

// Return what has been found (if anything)
return problems;
Expand Down Expand Up @@ -58,7 +75,7 @@ private void CheckFiles(List<string> problems, IRepository repo)

if (total > 0)
{
problems.Add($"Has {total} uncommitted files.");
problems.Add($"has {total} uncommitted {"file".ToQuantity(total)}.");
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/Wrapper/IGitChecker.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Doug Swisher. All Rights Reserved.
// Licensed under the MIT License. See LICENSE in the project root for license information.

using System.Collections.Generic;
using LibGit2Sharp;

Expand Down
21 changes: 21 additions & 0 deletions src/stylecop.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
"settings": {
"documentationRules": {
"companyName": "Doug Swisher",
"copyrightText": "Copyright (c) {companyName}. All Rights Reserved.\nLicensed under the {licenseName} License. See {licenseFile} in the project root for license information.",
"variables": {
"licenseName": "MIT",
"licenseFile": "LICENSE"
},
"xmlHeader": false
},
"layoutRules": {
"newlineAtEndOfFile": "require"
},
"orderingRules": {
"blankLinesBetweenUsingGroups": "require",
"usingDirectivesPlacement": "outsideNamespace"
}
}
}
15 changes: 15 additions & 0 deletions src/stylecop.ruleset
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Main Rule Set" Description="Rule set for C# Code" ToolsVersion="14.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" /> <!-- XML comment analysis is disabled due to project configuration -->
<Rule Id="SA1025" Action="None" /> <!-- Code should not contain multiple whitespace characters in a row -->
<Rule Id="SA1101" Action="None" /> <!-- Prefix local calls with this -->
<Rule Id="SA1413" Action="None" /> <!-- Use trailing comma in multi-line initializers -->
<Rule Id="SA1502" Action="None" /> <!-- Element should not be on a single line -->
<Rule Id="SA1507" Action="None" /> <!-- Code should not contain multiple blank lines in a row -->
<Rule Id="SA1512" Action="None" /> <!-- Single-line comments should not be followed by blank line -->
<Rule Id="SA1516" Action="None" /> <!-- Elements should be separated by blank line -->
<Rule Id="SA1517" Action="None" /> <!-- Code should not contain blank lines at start of file -->
<Rule Id="SA1600" Action="None" /> <!-- Elements should be documented -->
</Rules>
</RuleSet>
7 changes: 4 additions & 3 deletions test/GitUpdater.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.7.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="System.IO.Abstractions.TestingHelpers" Version="17.0.15" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit 5a9de52

Please sign in to comment.