feat(git-provider): Implement RemoveGitRepoCommand

This commit is contained in:
Scott 2026-08-25 11:18:03 +10:00
commit a666a49db0
2 changed files with 84 additions and 0 deletions

View file

@ -117,6 +117,54 @@ public class GitManager
});
}
public void UnregisterRepo(string registrationName)
{
_db.InConnection(conn =>
{
var existingRegistration = conn.Query<InternalGitRegistration>(
$"""
SELECT {nameof(InternalGitRegistration.Id)}
,{nameof(InternalGitRegistration.Name)}
,{nameof(InternalGitRegistration.Location)}
FROM {InternalGitRegistration.TableName}
WHERE {nameof(InternalGitRegistration.Name)} = ?
""",
registrationName)
.FirstOrDefault();
if (existingRegistration is null)
{
throw new Exception($"No registration exists for '{registrationName}'.")
{
Source = "unregister-repository",
};
}
var deleted = conn.Delete<InternalGitRegistration>(existingRegistration.Id);
// If we somehow found a registration but delete returned nothing, just return and assume we've already
// removed it from registrations.
// Seems a bit risky when you read it logically, but by this point the registration shouldn't exist so it doesn't
// matter.
if (deleted == 0)
{
return;
}
// Remove by the name we get from the database instead of what was passed in
if (_registrations.TryRemove(registrationName, out var removedItem))
{
_debugWriterDelegate?.Invoke($"Removed {registrationName}.");
}
// Weird error to throw, but by this stage we shouldn't have a git repo registered under this name
throw new Exception("Failed to remove registration - no registration exists.")
{
Source = "unregister-repository",
};
});
}
public List<GitRegistration> ListRepos()
{
return _registrations.Select(x =>