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

fix: Throws on git remote call outside git repo #6586

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion GitCommands/Git/GitModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,7 +2183,7 @@ IReadOnlyList<Remote> ParseRemotes(IEnumerable<string> lines)
var fetchLine = enumerator.Current;

// An invalid module is not an error; we simply return an empty list of remotes
if (fetchLine.Contains("not a git repository"))
if (fetchLine.IndexOf("not a git repository", StringComparison.OrdinalIgnoreCase) >= 0)
{
return remotes;
}
Expand Down
49 changes: 37 additions & 12 deletions UnitTests/GitCommandsTests/GitModuleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,49 @@ public void GetCurrentCheckout_should_query_git_and_return_sha_for_HEAD()
Assert.AreEqual(headId, objectId.ToString());
}

[TestCase("fatal: not a git repository (or any of the parent directories): .git")] // git version 2.20.1 (Apple Git-117)
[TestCase("fatal: Not a git repository (or any of the parent directories): .git")] // git version 2.16.1.windows.4
public void GetRemotes_should_return_empty_list_not_inside_git_repo(string warning)
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
using (_executable.StageOutput("remote -v", warning))
{
var remotes = await _gitModule.GetRemotesAsync();

remotes.Should().BeEmpty();
}
});
}

[TestCase("fatal: not a git repository (or any of the parent directories): .git")] // git version 2.20.1 (Apple Git-117)
[TestCase("fatal: Not a git repository (or any of the parent directories): .git")] // git version 2.16.1.windows.4
public void GetRemotes_should_not_throw_if_not_inside_git_repo(string warning)
{
using (_executable.StageOutput("remote -v", warning))
{
Assert.DoesNotThrowAsync(async () => await _gitModule.GetRemotesAsync());
}
}

[Test]
public void GetRemotes()
public void GetRemotes_should_parse_correctly_configured_remotes()
{
ThreadHelper.JoinableTaskFactory.Run(async () =>
{
var lines = new[]
{
"RussKie\tgit://github.com/RussKie/gitextensions.git (fetch)",
"RussKie\tgit://github.com/RussKie/gitextensions.git (push)",
"origin\tgit@github.com:drewnoakes/gitextensions.git (fetch)",
"origin\tgit@github.com:drewnoakes/gitextensions.git (push)",
"upstream\tgit@github.com:gitextensions/gitextensions.git (fetch)",
"upstream\tgit@github.com:gitextensions/gitextensions.git (push)",
"asymmetrical\thttps://github.com/gitextensions/fetch.git (fetch)",
"asymmetrical\thttps://github.com/gitextensions/push.git (push)",
"with-space\tc:\\Bare Repo (fetch)",
"with-space\tc:\\Bare Repo (push)"
};
"RussKie\tgit://github.com/RussKie/gitextensions.git (fetch)",
"RussKie\tgit://github.com/RussKie/gitextensions.git (push)",
"origin\tgit@github.com:drewnoakes/gitextensions.git (fetch)",
"origin\tgit@github.com:drewnoakes/gitextensions.git (push)",
"upstream\tgit@github.com:gitextensions/gitextensions.git (fetch)",
"upstream\tgit@github.com:gitextensions/gitextensions.git (push)",
"asymmetrical\thttps://github.com/gitextensions/fetch.git (fetch)",
"asymmetrical\thttps://github.com/gitextensions/push.git (push)",
"with-space\tc:\\Bare Repo (fetch)",
"with-space\tc:\\Bare Repo (push)"
};

using (_executable.StageOutput("remote -v", string.Join("\n", lines)))
{
Expand Down