init-repository: avoid failure when combining `--force' and mirrors
authorRohan McGovern <rohan.mcgovern@nokia.com>
Fri, 6 May 2011 07:12:16 +0000 (17:12 +1000)
committerRohan McGovern <rohan.mcgovern@nokia.com>
Fri, 6 May 2011 07:22:45 +0000 (17:22 +1000)
Avoid a fatal error if the `mirror' remote already exists.

Reviewed-by: Sunil Thaha
Change-Id: Id6225fad265abb575f6f35f750ba7aed7729e0dc

init-repository

index df3cf5f..423fc85 100755 (executable)
@@ -479,6 +479,13 @@ sub git_clone_one_submodule
 
     if ($mirror) {
         $self->exe('git', 'config', 'remote.origin.url', $url);
+
+        # In `force' mode, remove the mirror if it already exists,
+        # since we may be reinitializing the module.
+        if ($self->{force}) {
+            eval { $self->exe('git', 'remote', 'rm', 'mirror'); }; # failure is OK
+        }
+
         $self->exe('git', 'remote', 'add', 'mirror', $mirror);
     }