Skip to content

Commit

Permalink
Merge branch 'dev' into V6
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Nov 12, 2023
2 parents 66b1b71 + d9e80ac commit 9ea704b
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build/package/deb/debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi

#DEBHELPER#

if [ "$1" = "configure" ]; then
if [ -z "$2" ]; then
deb-systemd-helper stop 'tgstation-server.service' >/dev/null || true

echo " _ _ _ _ "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ await Task.Factory.StartNew(
OnTransferProgress = TransferProgressHandler(progressReporter.CreateSection("Fetch Origin", 1.0), cancellationToken),
OnUpdateTips = (a, b, c) => !cancellationToken.IsCancellationRequested,
CredentialsProvider = credentialsProvider.GenerateCredentialsHandler(username, password),
TagFetchMode = TagFetchMode.All,
},
"Fetch origin commits");
}
Expand Down
80 changes: 78 additions & 2 deletions tests/Tgstation.Server.Tests/TestRepository.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

using LibGit2Sharp;

using Microsoft.Extensions.Logging;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Expand All @@ -28,15 +31,15 @@ public async Task TestRepoParentLookup()
{
LibGit2Sharp.Repository.Clone("https://github.com/Cyberboss/test", tempPath);
var libGit2Repo = new LibGit2Sharp.Repository(tempPath);
using var repo = new Repository(
using var repo = new Host.Components.Repository.Repository(
libGit2Repo,
new LibGit2Commands(),
Mock.Of<IIOManager>(),
Mock.Of<IEventConsumer>(),
Mock.Of<ICredentialsProvider>(),
Mock.Of<IPostWriteHandler>(),
Mock.Of<IGitRemoteFeaturesFactory>(),
Mock.Of<ILogger<Repository>>(),
Mock.Of<ILogger<Host.Components.Repository.Repository>>(),
new GeneralConfiguration(),
() => { });

Expand All @@ -56,5 +59,78 @@ public async Task TestRepoParentLookup()
CancellationToken.None);
}
}

[TestMethod]
public async Task TestFetchingAdditionalCommits()
{
var tempPath = Path.Combine(Path.GetTempPath(), "TGS-Repository-Integration-Test", Guid.NewGuid().ToString());
var repoFac =
new LibGit2RepositoryFactory(
Mock.Of<ILogger<LibGit2RepositoryFactory>>());
var commands = new LibGit2Commands();
using var manager = new RepositoryManager(
repoFac,
commands,
new ResolvingIOManager(
new DefaultIOManager(),
tempPath),
Mock.Of<IEventConsumer>(),
new WindowsPostWriteHandler(),
Mock.Of<IGitRemoteFeaturesFactory>(),
Mock.Of<ILogger<Host.Components.Repository.Repository>>(),
Mock.Of<ILogger<RepositoryManager>>(),
new GeneralConfiguration());
try
{
using (await manager.CloneRepository(
new Uri("https://github.com/Cyberboss/common_core"),
null,
null,
null,
new JobProgressReporter(Mock.Of<ILogger<JobProgressReporter>>(), null, (_, _) => { }),
true,
default))
{
}

using (var repo = await repoFac.CreateFromPath(tempPath, default))
{
repo.Network.Remotes.Update("origin", updater =>
{
updater.Url = "https://github.com/tgstation/common_core";
});

var targetCommit = repo.Lookup<Commit>("5b0d0a38057a2c8306a852ccbd6cd6f4ae766a33");
Assert.IsNull(targetCommit);
}

using (var repo2 = await manager.LoadRepository(default))
{
await repo2.FetchOrigin(
new JobProgressReporter(Mock.Of<ILogger<JobProgressReporter>>(), null, (_, _) => { }),
null,
null,
false,
default);
}

using var repo3 = await repoFac.CreateFromPath(tempPath, default);
var remote = repo3.Network.Remotes.First();
commands.Fetch(repo3, remote.FetchRefSpecs.Select(x => x.Specification), remote, new FetchOptions
{
TagFetchMode = TagFetchMode.All,
Prune = true,
}, "test");

var targetCommit2 = repo3.Lookup<Commit>("5b0d0a38057a2c8306a852ccbd6cd6f4ae766a33");
Assert.IsNotNull(targetCommit2);
}
finally
{
await new DefaultIOManager().DeleteDirectory(
Path.GetDirectoryName(tempPath),
CancellationToken.None);
}
}
}
}

0 comments on commit 9ea704b

Please sign in to comment.