Skip to content
Merged
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
21 changes: 19 additions & 2 deletions src/GitVersionCore/GitPreparer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class GitPreparer
bool noFetch;
string targetPath;

const string defaultRemoteName = "origin";

public GitPreparer(string targetPath) : this(null, null, null, false, targetPath) { }
public GitPreparer(string targetUrl, string dynamicRepositoryLocation, Authentication authentication, bool noFetch, string targetPath)
{
Expand Down Expand Up @@ -76,10 +78,25 @@ public void Initialise(bool normaliseGitDirectory, string currentBranch, bool sh

private void CleanupDuplicateOrigin()
{
var remoteToKeep = defaultRemoteName;

var repo = new Repository(GetDotGitDirectory());
if (repo.Network.Remotes.Any(remote => remote.Name == "origin1"))

// check that we have a remote that matches defaultRemoteName if not take the first remote
if (!repo.Network.Remotes.Any(remote => remote.Name.Equals(defaultRemoteName, StringComparison.InvariantCultureIgnoreCase)))
{
remoteToKeep = repo.Network.Remotes.First().Name;
}

var duplicateRepos = repo.Network
.Remotes
.Where(remote => !remote.Name.Equals(remoteToKeep, StringComparison.InvariantCultureIgnoreCase))
.Select(remote => remote.Name);

// remove all remotes that are considered duplicates
foreach (var repoName in duplicateRepos)
{
repo.Network.Remotes.Remove("origin1");
repo.Network.Remotes.Remove(repoName);
}
}

Expand Down