Skip to content

Commit

Permalink
feat(core): show error message when pushing fails
Browse files Browse the repository at this point in the history
  • Loading branch information
jonisavo committed Aug 20, 2023
1 parent 0c3c8af commit b7a87b8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
using System.Threading.Tasks;
using NUnit.Framework;
using NSubstitute;
using LibGit2Sharp;
using UnityGit.Core.Services;
Expand Down Expand Up @@ -33,6 +34,11 @@ public void Push_Pushes_WhenConfirmed()
branch.RemoteName.Returns("origin");
branch.FriendlyName.Returns("feature/stuff");
_dialogService.Confirm(Arg.Any<string>()).Returns(true);
_gitCommandService.Run(Arg.Any<GitCommandInfo>()).Returns(Task.FromResult(new GitProcessResult()
{
ExitCode = 0,
Started = true
}));

_pushService.Push(repository, branch);

Expand All @@ -45,6 +51,25 @@ public void Push_Pushes_WhenConfirmed()
}));
}

[Test]
public void Push_Informs_On_Error()
{
var repository = Substitute.For<IRepository>();
var branch = Substitute.For<Branch>();
branch.RemoteName.Returns("origin");
branch.FriendlyName.Returns("feature/stuff");
_dialogService.Confirm(Arg.Any<string>()).Returns(true);
_gitCommandService.Run(Arg.Any<GitCommandInfo>()).Returns(Task.FromResult(new GitProcessResult()
{
ExitCode = 128,
Started = true
}));

_pushService.Push(repository, branch);

_dialogService.Received(1).Error(Arg.Any<string>());
}

[Test]
public void Push_DoesNotPush_WhenNotConfirmed()
{
Expand Down
7 changes: 5 additions & 2 deletions Packages/io.savolainen.unitygit/Core/Services/PushService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void Push(IRepository repository, Branch branch)
DoPush(repository, branch);
}

private void DoPush(IRepository repository, Branch branch)
private async void DoPush(IRepository repository, Branch branch)
{
var pushCommandInfo = new GitCommandInfo(
$"push {branch.RemoteName} {branch.FriendlyName}",
Expand All @@ -33,7 +33,10 @@ private void DoPush(IRepository repository, Branch branch)
repository
);

_gitCommandService.Run(pushCommandInfo);
var result = await _gitCommandService.Run(pushCommandInfo);

if (result.ExitCode != 0)
_dialogService.Error("Pushing failed. Refer to the UnityGit log for more information.");
}
}
}

0 comments on commit b7a87b8

Please sign in to comment.