From 0ea87df0aff83dc3ccf3bfbc2f0b000537eea94e Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Tue, 20 Aug 2019 14:15:25 -0400 Subject: [PATCH] Removing dead code 'IsCheckoutWithFilePaths' Signed-off-by: Derrick Stolee --- Scalar.Common/GitCommandLineParser.cs | 38 ------------------- .../Common/GitCommandLineParserTests.cs | 23 ----------- 2 files changed, 61 deletions(-) diff --git a/Scalar.Common/GitCommandLineParser.cs b/Scalar.Common/GitCommandLineParser.cs index d813247aeb..ef2b7fac69 100644 --- a/Scalar.Common/GitCommandLineParser.cs +++ b/Scalar.Common/GitCommandLineParser.cs @@ -62,44 +62,6 @@ public bool IsSerializedStatus() this.HasArgumentPrefix("--serialize"); } - /// - /// This method currently just makes a best effort to detect file paths. Only use this method for optional optimizations - /// related to file paths. Do NOT use this method if you require a reliable answer. - /// - /// True if file paths were detected, otherwise false - public bool IsCheckoutWithFilePaths() - { - if (this.IsVerb(Verbs.Checkout)) - { - int numArguments = this.parts.Length - ArgumentsOffset; - - // The simplest way to know that we're dealing with file paths is if there are any arguments after a -- - // e.g. git checkout branchName -- fileName - int dashDashIndex; - if (this.HasAnyArgument(arg => arg == "--", out dashDashIndex) && - numArguments > dashDashIndex + 1) - { - return true; - } - - // We also special case one usage with HEAD, as long as there are no other arguments with - or -- that might - // result in behavior we haven't tested. - // e.g. git checkout HEAD fileName - if (numArguments >= 2 && - !this.HasAnyArgument(arg => arg.StartsWith("-")) && - this.HasArgumentAtIndex(ScalarConstants.DotGit.HeadName, argumentIndex: 0)) - { - return true; - } - - // Note: we have definitely missed some cases of file paths, e.g.: - // git checkout branchName fileName (detecting this reliably requires more complicated parsing) - // git checkout --patch (we currently have no need to optimize this scenario) - } - - return false; - } - public bool IsVerb(Verbs verbs) { if (!this.IsValidGitCommand) diff --git a/Scalar.UnitTests/Common/GitCommandLineParserTests.cs b/Scalar.UnitTests/Common/GitCommandLineParserTests.cs index e41b534e6a..f4bd3cca0b 100644 --- a/Scalar.UnitTests/Common/GitCommandLineParserTests.cs +++ b/Scalar.UnitTests/Common/GitCommandLineParserTests.cs @@ -61,29 +61,6 @@ public void IsResetSoftOrMixedTests() new GitCommandLineParser("git status").IsResetSoftOrMixed().ShouldEqual(false); } - [TestCase] - public void IsCheckoutWithFilePathsTests() - { - new GitCommandLineParser("gits checkout branch -- file").IsCheckoutWithFilePaths().ShouldEqual(false); - - new GitCommandLineParser("git checkout branch -- file").IsCheckoutWithFilePaths().ShouldEqual(true); - new GitCommandLineParser("git checkout branch -- file1 file2").IsCheckoutWithFilePaths().ShouldEqual(true); - new GitCommandLineParser("git checkout HEAD -- file").IsCheckoutWithFilePaths().ShouldEqual(true); - - new GitCommandLineParser("git checkout HEAD file").IsCheckoutWithFilePaths().ShouldEqual(true); - new GitCommandLineParser("git checkout HEAD file1 file2").IsCheckoutWithFilePaths().ShouldEqual(true); - - new GitCommandLineParser("git checkout branch file").IsCheckoutWithFilePaths().ShouldEqual(false); - new GitCommandLineParser("git checkout branch").IsCheckoutWithFilePaths().ShouldEqual(false); - new GitCommandLineParser("git checkout HEAD").IsCheckoutWithFilePaths().ShouldEqual(false); - - new GitCommandLineParser("git checkout -b topic").IsCheckoutWithFilePaths().ShouldEqual(false); - - new GitCommandLineParser("git checkout -b topic --").IsCheckoutWithFilePaths().ShouldEqual(false); - new GitCommandLineParser("git checkout HEAD --").IsCheckoutWithFilePaths().ShouldEqual(false); - new GitCommandLineParser("git checkout HEAD -- ").IsCheckoutWithFilePaths().ShouldEqual(false); - } - [TestCase] public void IsSerializedStatusTests() {