@@ -15,6 +15,8 @@ public class GitPreparer
15
15
bool noFetch ;
16
16
string targetPath ;
17
17
18
+ const string defaultRemoteName = "origin" ;
19
+
18
20
public GitPreparer ( string targetPath ) : this ( null , null , null , false , targetPath ) { }
19
21
public GitPreparer ( string targetUrl , string dynamicRepositoryLocation , Authentication authentication , bool noFetch , string targetPath )
20
22
{
@@ -76,10 +78,25 @@ public void Initialise(bool normaliseGitDirectory, string currentBranch, bool sh
76
78
77
79
private void CleanupDuplicateOrigin ( )
78
80
{
81
+ var remoteToKeep = defaultRemoteName ;
82
+
79
83
var repo = new Repository ( GetDotGitDirectory ( ) ) ;
80
- if ( repo . Network . Remotes . Any ( remote => remote . Name == "origin1" ) )
84
+
85
+ // check that we have a remote that matches defaultRemoteName if not take the first remote
86
+ if ( ! repo . Network . Remotes . Any ( remote => remote . Name . Equals ( defaultRemoteName , StringComparison . InvariantCultureIgnoreCase ) ) )
87
+ {
88
+ remoteToKeep = repo . Network . Remotes . First ( ) . Name ;
89
+ }
90
+
91
+ var duplicateRepos = repo . Network
92
+ . Remotes
93
+ . Where ( remote => ! remote . Name . Equals ( remoteToKeep , StringComparison . InvariantCultureIgnoreCase ) )
94
+ . Select ( remote => remote . Name ) ;
95
+
96
+ // remove all remotes that are considered duplicates
97
+ foreach ( var repoName in duplicateRepos )
81
98
{
82
- repo . Network . Remotes . Remove ( "origin1" ) ;
99
+ repo . Network . Remotes . Remove ( repoName ) ;
83
100
}
84
101
}
85
102
0 commit comments