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

Removing dead code 'IsCheckoutWithFilePaths' #75

Merged
merged 1 commit into from
Aug 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
38 changes: 0 additions & 38 deletions Scalar.Common/GitCommandLineParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,44 +62,6 @@ public bool IsSerializedStatus()
this.HasArgumentPrefix("--serialize");
}

/// <summary>
/// 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.
/// </summary>
/// <returns>True if file paths were detected, otherwise false</returns>
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)
Expand Down
23 changes: 0 additions & 23 deletions Scalar.UnitTests/Common/GitCommandLineParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down