-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
209 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
PowerType.Tests/PowerTypePredictionSummaryCollectorTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation.Subsystem.Prediction; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace PowerType.Tests; | ||
|
||
public class PowerTypePredictionSummaryCollectorTests | ||
{ | ||
|
||
[Fact] | ||
public void TestGetOne() | ||
{ | ||
var collector = new PowerTypePredictionSummaryCollector(); | ||
var suggestionPackage = new SuggestionPackage(new List<PredictiveSuggestion> { new PredictiveSuggestion("git checkout main") }); | ||
collector.Add(DateTime.Now, PredictionContext.Create("git checkout"), null, suggestionPackage, TimeSpan.Zero); | ||
var result = collector.Get(); | ||
result.Count.Should().Be(1); | ||
} | ||
|
||
[Fact] | ||
public void TestGetCap() | ||
{ | ||
var collector = new PowerTypePredictionSummaryCollector(5); | ||
for (var i = 0; i < 10; i++) | ||
{ | ||
var suggestionPackage = new SuggestionPackage(new List<PredictiveSuggestion> { new PredictiveSuggestion("git checkout main") }); | ||
collector.Add(DateTime.Now, PredictionContext.Create("git checkout"), null, suggestionPackage, TimeSpan.Zero); | ||
} | ||
var result = collector.Get(); | ||
result.Count.Should().Be(5); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,11 +123,13 @@ $stashes = [DynamicSource]@{ | |
Keys = @("--all", "-A", "--no-ignore-removal"); | ||
Name = "no-ignore-removal"; | ||
Description = "Update the index not only where the working tree has a file matching <pathspec> but also where the index already has an entry. This adds, modifies, and removes index entries to match the working tree."; | ||
Condition = [ExclusiveParameterCondition]::new("ignore-removal") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--ignore-removal", "--no-all"); | ||
Name = "ignore-removal"; | ||
Description = "Update the index by adding new files that are unknown to the index and files modified in the working tree, but ignore files that have been removed from the working tree. This option is a no-op when no <pathspec> is used."; | ||
Condition = [ExclusiveParameterCondition]::new("no-ignore-removal") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--intent-to-add", "-N"); | ||
|
@@ -306,13 +308,20 @@ $stashes = [DynamicSource]@{ | |
[ValueParameter]@{ | ||
Keys = @("--trailer"); | ||
Name = "trailer"; | ||
Description = "Specify a (<token>, <value>) pair that should be applied as a trailer. (e.g. git commit --trailer `"Signed-off-by:C O Mitter \ <[email protected]>`" --trailer `"Helped-by:C O Mitter \ <[email protected]>`" will add the `"Signed-off-by`" trailer and the `"Helped-by`" trailer to the commit message.) The trailer.* configuration variables ( git-interpret-trailers1 ) can be used to define if a duplicated trailer is omitted, where in the run of trailers each trailer would appear, and other details."; | ||
Description = "Specify a (<token>, <value>) pair that should be applied as a trailer. (e.g. git commit --trailer `"Signed-off-by:C O Mitter \ <[email protected]>`" --trailer `"Helped-by:C O Mitter \ <[email protected]>`" will add the `"Signed-off-by`" trailer and the `"Helped-by`" trailer to the commit message.) The trailer.* configuration variables ( git-interpret-trailers1 ) can be used to define if a duplicated trailer is omitted, where in the run of trailers each trailer would appear, and other details."; | ||
Condition = [LargerOrEqualCondition]::new($version, [Version]'2.32.0') | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--verify", "--no-verify", "-n"); | ||
Keys = @("--verify"); | ||
Name = "verify"; | ||
Description = "By default, the pre-commit and commit-msg hooks are run. When any of --no-verify or -n is given, these are bypassed. See also githooks5 ."; | ||
Description = "By default, the pre-commit and commit-msg hooks are run. When any of --no-verify or -n is given, these are bypassed. See also githooks."; | ||
Condition = [ExclusiveParameterCondition]::new("no verify") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-verify", "-n"); | ||
Name = "no verify"; | ||
Description = "By default, the pre-commit and commit-msg hooks are run. When any of --no-verify or -n is given, these are bypassed. See also githooks."; | ||
Condition = [ExclusiveParameterCondition]::new("verify") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--allow-empty"); | ||
|
@@ -334,11 +343,13 @@ $stashes = [DynamicSource]@{ | |
Keys = @("--edit", "-e"); | ||
Name = "edit"; | ||
Description = "The message taken from file with -F, command line with -m, and from commit object with -C are usually used as the commit log message unmodified. This option lets you further edit the message taken from these sources."; | ||
Condition = [ExclusiveParameterCondition]::new("no-edit") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-edit"); | ||
Name = "no-edit"; | ||
Description = "Use the selected commit message without launching an editor. For example, git commit --amend --no-edit amends a commit without changing its commit message."; | ||
Condition = [ExclusiveParameterCondition]::new("edit") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--amend"); | ||
|
@@ -412,21 +423,25 @@ $stashes = [DynamicSource]@{ | |
Keys = @("--status"); | ||
Name = "status"; | ||
Description = "Include the output of git-status1 in the commit message template when using an editor to prepare the commit message. Defaults to on, but can be used to override configuration variable commit.status."; | ||
Condition = [ExclusiveParameterCondition]::new("no-status") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-status"); | ||
Name = "no-status"; | ||
Description = "Do not include the output of git-status1 in the commit message template when using an editor to prepare the default commit message."; | ||
Condition = [ExclusiveParameterCondition]::new("status") | ||
}, | ||
[ValueParameter]@{ | ||
Keys = @("--gpg-sign", "-S"); | ||
Name = "gpg-sign"; | ||
Description = "GPG-sign commits. The keyid argument is optional and defaults to the committer identity; if specified, it must be stuck to the option without a space. --no-gpg-sign is useful to countermand both commit.gpgSign configuration variable, and earlier --gpg-sign."; | ||
Condition = [ExclusiveParameterCondition]::new("no-gpg-sign") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-gpg-sign"); | ||
Name = "no-gpg-sign"; | ||
Description = "Don't gpg sign"; | ||
Condition = [ExclusiveParameterCondition]::new("gpg-sign") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--"); | ||
|
@@ -481,16 +496,25 @@ $stashes = [DynamicSource]@{ | |
Keys = @("--track", "-t"); | ||
Name = "track"; | ||
Description = "When creating a new branch, set up `"upstream`" configuration. See `"--track`" in git-branch1 for details."; | ||
Condition = [ExclusiveParameterCondition]::new("no-track") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-track"); | ||
Name = "no-track"; | ||
Description = "Do not set up `"upstream`" configuration, even if the branch.autoSetupMerge configuration variable is true."; | ||
Condition = [ExclusiveParameterCondition]::new("track") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-guess", "--guess"); | ||
Keys = @("--guess"); | ||
Name = "guess"; | ||
Description = "If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to"; | ||
Condition = [ExclusiveParameterCondition]::new("no-guess") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-guess"); | ||
Name = "no-guess"; | ||
Description = "If <branch> is not found but there does exist a tracking branch in exactly one remote (call it <remote>) with a matching name, treat as equivalent to"; | ||
Condition = [ExclusiveParameterCondition]::new("guess") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("-l"); | ||
|
@@ -554,9 +578,16 @@ $stashes = [DynamicSource]@{ | |
Description = "Using --recurse-submodules will update the content of all active submodules according to the commit recorded in the superproject. If local modifications in a submodule would be overwritten the checkout will fail unless -f is used. If nothing (or --no-recurse-submodules) is used, submodules working trees will not be updated. Just like git-submodule1 , this will detach HEAD of the submodule."; | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--overlay", "--no-overlay"); | ||
Keys = @("--overlay"); | ||
Name = "overlay"; | ||
Description = "In the default overlay mode, git checkout never removes files from the index or the working tree. When specifying --no-overlay, files that appear in the index and working tree, but not in <tree-ish> are removed, to make them match <tree-ish> exactly."; | ||
Condition = [ExclusiveParameterCondition]::new("no-overlay") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-overlay"); | ||
Name = "no-overlay"; | ||
Description = "In the default overlay mode, git checkout never removes files from the index or the working tree. When specifying --no-overlay, files that appear in the index and working tree, but not in <tree-ish> are removed, to make them match <tree-ish> exactly."; | ||
Condition = [ExclusiveParameterCondition]::new("overlay") | ||
}, | ||
[ValueParameter]@{ | ||
Keys = @("--pathspec-from-file"); | ||
|
@@ -601,9 +632,16 @@ $stashes = [DynamicSource]@{ | |
Name = "show"; | ||
Parameters = @( | ||
[FlagParameter]@{ | ||
Keys = @("--include-untracked", "--no-include-untracked", "-u"); | ||
Name = "no-include-untracked"; | ||
Keys = @("--include-untracked", "-u"); | ||
Name = "include-untracked"; | ||
Description = "All untracked files are also stashed and then cleaned up with git clean."; | ||
Condition = [ExclusiveParameterCondition]::new("no-include-untracked") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-include-untracked"); | ||
Name = "no-include-untracked"; | ||
Description = "No untracked files are stashed and then cleaned up with git clean."; | ||
Condition = [ExclusiveParameterCondition]::new("include-untracked") | ||
}, | ||
[ValueParameter]@{ | ||
Name = "stash"; | ||
|
@@ -665,17 +703,29 @@ $stashes = [DynamicSource]@{ | |
[FlagParameter]@{ | ||
Keys = @("--patch", "-p"); | ||
Name = "patch"; | ||
Description = "This option is only valid for push and save commands."; | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--keep-index", "--no-keep-index", "-k"); | ||
Keys = @("--keep-index", "-k"); | ||
Name = "keep-index"; | ||
Description = "All changes already added to the index are left intact."; | ||
Condition = [ExclusiveParameterCondition]::new("no-keep-index") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-keep-index"); | ||
Name = "no-keep-index"; | ||
Description = "This option is only valid for push and save commands."; | ||
Condition = [ExclusiveParameterCondition]::new("keep-index") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--include-untracked", "--no-include-untracked", "-u"); | ||
Name = "no-include-untracked"; | ||
Keys = @("--include-untracked", "-u"); | ||
Name = "include-untracked"; | ||
Description = "All untracked files are also stashed and then cleaned up with git clean."; | ||
Condition = [ExclusiveParameterCondition]::new("no-include-untracked") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--no-include-untracked"); | ||
Name = "no-include-untracked"; | ||
Description = "No untracked files are stashed and then cleaned up with git clean."; | ||
Condition = [ExclusiveParameterCondition]::new("include-untracked") | ||
}, | ||
[FlagParameter]@{ | ||
Keys = @("--all", "-a"); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,30 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace PowerType.Model | ||
namespace PowerType.Model; | ||
|
||
public class CommandParameter : Parameter | ||
{ | ||
public class CommandParameter : Parameter | ||
{ | ||
public List<Parameter> Parameters { get; set; } = new List<Parameter>(); | ||
public List<Parameter> Parameters { get; set; } = new List<Parameter>(); | ||
|
||
internal override void Initialize(ISystemTime systemTime) | ||
{ | ||
base.Initialize(systemTime); | ||
foreach(var parameter in Parameters) | ||
{ | ||
parameter.Initialize(systemTime); | ||
} | ||
internal override void Initialize(ISystemTime systemTime) | ||
{ | ||
base.Initialize(systemTime); | ||
foreach (var parameter in Parameters) | ||
{ | ||
parameter.Initialize(systemTime); | ||
} | ||
} | ||
|
||
internal override void Validate() | ||
internal override void Validate() | ||
{ | ||
base.Validate(); | ||
if (Parameters == null) | ||
{ | ||
throw new ArgumentNullException(nameof(Parameters)); | ||
} | ||
foreach (var parameter in Parameters) | ||
{ | ||
base.Validate(); | ||
if (Parameters == null) | ||
{ | ||
throw new ArgumentNullException(nameof(Parameters)); | ||
} | ||
foreach (var parameter in Parameters) | ||
{ | ||
parameter.Validate(); | ||
} | ||
parameter.Validate(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,6 +37,5 @@ public abstract class Condition | |
|
||
public virtual void Validate() | ||
{ | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using PowerType.Parsing; | ||
|
||
namespace PowerType.Model.Conditions; | ||
|
||
public class ExclusiveParameterCondition : Condition | ||
{ | ||
private readonly string[] parameterNames; | ||
|
||
public ExclusiveParameterCondition(params string[] parameterNames) | ||
{ | ||
if (parameterNames == null) | ||
{ | ||
throw new ArgumentNullException(nameof(parameterNames)); | ||
} | ||
else if (parameterNames.Length == 0) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(parameterNames), "Must have at least one name"); | ||
} | ||
this.parameterNames = parameterNames; | ||
} | ||
|
||
public override bool Evaluate(Dictionary<string, object> parameters) | ||
{ | ||
var dictionaryParsingContext = (DictionaryParsingContext)parameters[nameof(DictionaryParsingContext)]; | ||
return !dictionaryParsingContext.Parameters.Any(x => parameterNames.Contains(x.Parameter?.Name)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.