30
update=
31
prefix=
32
33
-# Resolve relative url by appending to parent's url
33
+# The function takes at most 2 arguments. The first argument is the
34
+# URL that navigates to the submodule origin repo. When relative, this URL
35
+# is relative to the superproject origin URL repo. The second up_path
36
+# argument, if specified, is the relative path that navigates
37
+# from the submodule working tree to the superproject working tree.
38
+#
39
+# The output of the function is the origin URL of the submodule.
40
+#
41
+# The output will either be an absolute URL or filesystem path (if the
42
+# superproject origin URL is an absolute URL or filesystem path,
43
+# respectively) or a relative file system path (if the superproject
44
+# origin URL is a relative file system path).
45
+#
46
+# When the output is a relative file system path, the path is either
47
+# relative to the submodule working tree, if up_path is specified, or to
48
+# the superproject working tree otherwise.
49
resolve_relative_url ()
50
{
51
remote=$(get_default_remote)
54
url="$1"
55
remoteurl=${remoteurl%/}
56
sep=/
57
+ up_path="$2"
58
+
59
+ case "$remoteurl" in
60
+ *:*|/*)
61
+ is_relative=
62
+ ;;
63
+ *)
64
+ is_relative=t
65
+ ;;
66
+ esac
67
+
68
while test -n "$url"
69
do
70
case "$url" in
90
break;;
91
esac
92
done
67
- echo "$remoteurl$sep${url%/}"
93
+ echo "${is_relative:+${up_path}}$remoteurl$sep${url%/}"
94
}
95
96
#
990
# Possibly a url relative to parent
991
case "$url" in
992
./*|../*)
967
- url=$(resolve_relative_url "$url") || exit
993
+ # rewrite foo/bar as ../.. to find path from
994
+ # submodule work tree to superproject work tree
995
+ up_path="$(echo "$sm_path" | sed "s/[^/][^/]*/../g")" &&
996
+ # guarantee a trailing /
997
+ up_path=${up_path%/}/ &&
998
+ # path from submodule work tree to submodule origin repo
999
+ sub_origin_url=$(resolve_relative_url "$url" "$up_path") &&
1000
+ # path from superproject work tree to submodule origin repo
1001
+ super_config_url=$(resolve_relative_url "$url") || exit
1002
+ ;;
1003
+ *)
1004
+ sub_origin_url="$url"
1005
+ super_config_url="$url"
1006
;;
1007
esac
1008
1009
if git config "submodule.$name.url" >/dev/null 2>/dev/null
1010
then
1011
say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
974
- git config submodule."$name".url "$url"
1012
+ git config submodule."$name".url "$super_config_url"
1013
1014
if test -e "$sm_path"/.git
1015
then
1017
clear_local_git_env
1018
cd "$sm_path"
1019
remote=$(get_default_remote)
982
- git config remote."$remote".url "$url"
1020
+ git config remote."$remote".url "$sub_origin_url"
1021
)
1022
fi
1023
fi