@@ -246,7 +246,6 @@ cmd_add()
246
246
url=" $repo "
247
247
;;
248
248
esac
249
- git config submodule." $path " .url " $url "
250
249
else
251
250
252
251
module_clone " $path " " $realrepo " " $reference " || exit
@@ -260,6 +259,7 @@ cmd_add()
260
259
esac
261
260
) || die " Unable to checkout submodule '$path '"
262
261
fi
262
+ git config submodule." $path " .url " $url "
263
263
264
264
git add $force " $path " ||
265
265
die " Failed to add submodule '$path '"
@@ -359,25 +359,26 @@ cmd_init()
359
359
do
360
360
# Skip already registered paths
361
361
name=$( module_name " $path " ) || exit
362
- url=$( git config submodule." $name " .url)
363
- test -z " $url " || continue
364
-
365
- url=$( git config -f .gitmodules submodule." $name " .url)
366
- test -z " $url " &&
367
- die " No url found for submodule path '$path ' in .gitmodules"
368
-
369
- # Possibly a url relative to parent
370
- case " $url " in
371
- ./* |../* )
372
- url=$( resolve_relative_url " $url " ) || exit
373
- ;;
374
- esac
375
-
376
- git config submodule." $name " .url " $url " ||
377
- die " Failed to register url for submodule path '$path '"
362
+ if test -z " $( git config " submodule.$name .url" ) "
363
+ then
364
+ url=$( git config -f .gitmodules submodule." $name " .url)
365
+ test -z " $url " &&
366
+ die " No url found for submodule path '$path ' in .gitmodules"
367
+
368
+ # Possibly a url relative to parent
369
+ case " $url " in
370
+ ./* |../* )
371
+ url=$( resolve_relative_url " $url " ) || exit
372
+ ;;
373
+ esac
374
+ git config submodule." $name " .url " $url " ||
375
+ die " Failed to register url for submodule path '$path '"
376
+ fi
378
377
378
+ # Copy "update" setting when it is not set yet
379
379
upd=" $( git config -f .gitmodules submodule." $name " .update) "
380
380
test -z " $upd " ||
381
+ test -n " $( git config submodule." $name " .update) " ||
381
382
git config submodule." $name " .update " $upd " ||
382
383
die " Failed to register update mode for submodule path '$path '"
383
384
@@ -878,17 +879,20 @@ cmd_sync()
878
879
;;
879
880
esac
880
881
881
- say " Synchronizing submodule url for '$name '"
882
- git config submodule." $name " .url " $url "
883
-
884
- if test -e " $path " /.git
882
+ if git config " submodule.$name .url" > /dev/null 2> /dev/null
885
883
then
886
- (
887
- clear_local_git_env
888
- cd " $path "
889
- remote=$( get_default_remote)
890
- git config remote." $remote " .url " $url "
891
- )
884
+ say " Synchronizing submodule url for '$name '"
885
+ git config submodule." $name " .url " $url "
886
+
887
+ if test -e " $path " /.git
888
+ then
889
+ (
890
+ clear_local_git_env
891
+ cd " $path "
892
+ remote=$( get_default_remote)
893
+ git config remote." $remote " .url " $url "
894
+ )
895
+ fi
892
896
fi
893
897
done
894
898
}
0 commit comments