Skip to content

Commit

Permalink
Merge pull request #6586 from RussKie/fix_6562_Throw_on_git_remote_ca…
Browse files Browse the repository at this point in the history
…ll_outside_git_repo

fix: Throws on `git remote` call outside git repo
  • Loading branch information
RussKie committed May 18, 2019
2 parents 2070ef7 + e545266 commit a41d418
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
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

0 comments on commit a41d418

Please sign in to comment.