Skip to content
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
12 changes: 9 additions & 3 deletions backend/LexBoxApi/Services/HgService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,21 @@ public async Task<string[]> CleanupResetBackups(bool dryRun = false)


/// <summary>
/// deletes all files and folders in the repo folder except for .hg
/// deletes all files and folders in the repo folder except for .hg, and drops .hg/hgrc
/// </summary>
private async Task CleanupRepoFolder(DirectoryInfo repoDir)
{
await Task.Run(() =>
{
foreach (var info in repoDir.EnumerateFileSystemInfos())
{
if (info.Name == ".hg") continue;
if (info.Name == ".hg")
{
// Mercurial would trust an uploaded hgrc (hooks, extensions) on the server, and nothing here needs one.
if (info is DirectoryInfo hg)
foreach (var hgrc in hg.EnumerateFiles("hgrc")) hgrc.Delete();
continue;
}
if (info is DirectoryInfo dir) dir.Delete(true);
else info.Delete();
}
Expand Down Expand Up @@ -323,7 +329,7 @@ public Task RevertRepo(ProjectCode code, string revHash)
// 1. Rename repo to repo-backup-date (verifying first that it does not exist, adding -NNN at the end (001, 002, 003) if it does)
// 2. Make empty directory (NOT a repo yet) with this project code
// 3. Clone repo-backup-date-NNN into empty directory, passing "-r revHash" param
// 4. Copy .hg/hgrc from backup dir, overwriting the one in the cloned dir
// 4. Delete the .hg/hgrc that the clone writes (it only points back at the backup); server repos don't keep one
//
// Will need an SSH key as a k8s secret, put it into authorized_keys on the hgweb side so that lexbox can do "ssh hgweb hg clone ..."
}
Expand Down
23 changes: 23 additions & 0 deletions backend/Testing/LexCore/Services/HgServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,29 @@ public async Task CanFinishResetByUnZippingAnArchive(string filePath)
.Should().ContainSingle().Which.Should().Be(Path.Join(".hg", "important-file.bin"));
}

[Theory]
[InlineData("")]
[InlineData("unzip-test/")]
public async Task FinishResetDropsUploadedHgrc(string prefix)
{
var code = "unzip-test-hgrc";
await _hgService.InitRepo(code);

using var stream = new MemoryStream();
using (var zipArchive = new ZipArchive(stream, ZipArchiveMode.Create, true))
{
CreateSimpleEntry(zipArchive, prefix + ".hg/hgrc");
CreateSimpleEntry(zipArchive, prefix + ".hg/important-file.bin");
}
stream.Position = 0;
await _hgService.FinishReset(code, stream);

var repoPath = Path.GetFullPath(Path.Join(_hgConfig.RepoPath, "u", code));
Directory.EnumerateFiles(repoPath, "*", SearchOption.AllDirectories)
.Select(p => Path.GetRelativePath(repoPath, p))
.Should().ContainSingle().Which.Should().Be(Path.Join(".hg", "important-file.bin"));
}

[Theory]
[InlineData("-xy")]
[InlineData("-x-y-z")]
Expand Down
Loading