fix: Set repo URL from settings

If a user changed the repo URL after a clone was performed, it would not
get used.

Fixes #90
pull/92/head
Robert Dailey 2 years ago
parent 3c9a2d3337
commit 4cf8731efb

@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Sonarr: Invalid release profile JSON files no longer cause the program to exit. Instead, it just
skips them and prints a warning to the user. (#87)
- Radarr: Do not crash when `quality_profiles` is empty. (#89)
- Settings: Use repo URL after initial clone (#90)
## [2.2.0] - 2022-06-03

@ -54,6 +54,8 @@ public class RepoUpdater : IRepoUpdater
var cloneUrl = repoSettings.CloneUrl;
const string branch = "master";
_log.Debug("Using Branch & Clone URL: {Branch}, {Url}", branch, cloneUrl);
try
{
using var repo = _repositoryFactory.CreateAndCloneIfNeeded(cloneUrl, RepoPath, branch);

@ -47,4 +47,13 @@ public class GitRepositoryFactoryTest
fileUtils.DidNotReceiveWithAnyArgs().DeleteReadOnlyDirectory(default!);
wrapper.DidNotReceiveWithAnyArgs().Clone(default!, default!, default!);
}
[Test, AutoMockData]
public void Set_remote_when_creating_repository(
[Frozen] IGitRepository repo,
GitRepositoryFactory sut)
{
sut.CreateAndCloneIfNeeded("repo_url", "repo_path", "branch");
repo.Received().SetRemote("origin", "repo_url");
}
}

@ -40,4 +40,9 @@ public sealed class GitRepository : IGitRepository
var commit = _repo.Value.Branches[toBranch].Tip;
_repo.Value.Reset(ResetMode.Hard, commit);
}
public void SetRemote(string name, string newUrl)
{
_repo.Value.Network.Remotes.Update(name, updater => updater.Url = newUrl);
}
}

@ -27,7 +27,9 @@ public class GitRepositoryFactory : IGitRepositoryFactory
DeleteAndCloneRepo(repoUrl, repoPath, branch);
}
return _repoFactory(repoPath);
var repo = _repoFactory(repoPath);
repo.SetRemote("origin", repoUrl);
return repo;
}
private void DeleteAndCloneRepo(string repoUrl, string repoPath, string branch)

@ -5,4 +5,5 @@ public interface IGitRepository : IDisposable
void ForceCheckout(string branch);
void Fetch(string remote = "origin");
void ResetHard(string toBranch);
void SetRemote(string name, string newUrl);
}

Loading…
Cancel
Save