Skip to content

Commit 0591c0a

Browse files
committed
Merge branch 'jc/submodule-sync-no-auto-vivify'
* jc/submodule-sync-no-auto-vivify: submodule add: always initialize .git/config entry submodule sync: do not auto-vivify uninteresting submodule Conflicts: git-submodule.sh
2 parents 765c7e4 + 2cd9de3 commit 0591c0a

File tree

3 files changed

+47
-30
lines changed

3 files changed

+47
-30
lines changed

Documentation/git-submodule.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ commit for each submodule.
167167

168168
sync::
169169
Synchronizes submodules' remote URL configuration setting
170-
to the value specified in .gitmodules. This is useful when
170+
to the value specified in .gitmodules. It will only affect those
171+
submodules which already have an url entry in .git/config (that is the
172+
case when they are initialized or freshly added). This is useful when
171173
submodule URLs change upstream and you need to update your local
172174
repositories accordingly.
173175
+

git-submodule.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ Use -f if you really want to add it." &&
250250
url="$repo"
251251
;;
252252
esac
253-
git config submodule."$path".url "$url"
254253
else
255254

256255
module_clone "$path" "$realrepo" "$reference" || exit
@@ -264,6 +263,7 @@ Use -f if you really want to add it." &&
264263
esac
265264
) || die "$(eval_gettext "Unable to checkout submodule '\$path'")"
266265
fi
266+
git config submodule."$path".url "$url"
267267

268268
git add $force "$path" ||
269269
die "$(eval_gettext "Failed to add submodule '\$path'")"
@@ -363,25 +363,26 @@ cmd_init()
363363
do
364364
# Skip already registered paths
365365
name=$(module_name "$path") || exit
366-
url=$(git config submodule."$name".url)
367-
test -z "$url" || continue
368-
369-
url=$(git config -f .gitmodules submodule."$name".url)
370-
test -z "$url" &&
371-
die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
372-
373-
# Possibly a url relative to parent
374-
case "$url" in
375-
./*|../*)
376-
url=$(resolve_relative_url "$url") || exit
377-
;;
378-
esac
379-
380-
git config submodule."$name".url "$url" ||
381-
die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
366+
if test -z "$(git config "submodule.$name.url")"
367+
then
368+
url=$(git config -f .gitmodules submodule."$name".url)
369+
test -z "$url" &&
370+
die "$(eval_gettext "No url found for submodule path '\$path' in .gitmodules")"
371+
372+
# Possibly a url relative to parent
373+
case "$url" in
374+
./*|../*)
375+
url=$(resolve_relative_url "$url") || exit
376+
;;
377+
esac
378+
git config submodule."$name".url "$url" ||
379+
die "$(eval_gettext "Failed to register url for submodule path '\$path'")"
380+
fi
382381

382+
# Copy "update" setting when it is not set yet
383383
upd="$(git config -f .gitmodules submodule."$name".update)"
384384
test -z "$upd" ||
385+
test -n "$(git config submodule."$name".update)" ||
385386
git config submodule."$name".update "$upd" ||
386387
die "$(eval_gettext "Failed to register update mode for submodule path '\$path'")"
387388

@@ -925,17 +926,20 @@ cmd_sync()
925926
;;
926927
esac
927928

928-
say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
929-
git config submodule."$name".url "$url"
930-
931-
if test -e "$path"/.git
929+
if git config "submodule.$name.url" >/dev/null 2>/dev/null
932930
then
933-
(
934-
clear_local_git_env
935-
cd "$path"
936-
remote=$(get_default_remote)
937-
git config remote."$remote".url "$url"
938-
)
931+
say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
932+
git config submodule."$name".url "$url"
933+
934+
if test -e "$path"/.git
935+
then
936+
(
937+
clear_local_git_env
938+
cd "$path"
939+
remote=$(get_default_remote)
940+
git config remote."$remote".url "$url"
941+
)
942+
fi
939943
fi
940944
done
941945
}

t/t7403-submodule-sync.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ test_expect_success setup '
2525
git clone super super-clone &&
2626
(cd super-clone && git submodule update --init) &&
2727
git clone super empty-clone &&
28-
(cd empty-clone && git submodule init)
28+
(cd empty-clone && git submodule init) &&
29+
git clone super top-only-clone
2930
'
3031

3132
test_expect_success 'change submodule' '
@@ -66,12 +67,22 @@ test_expect_success '"git submodule sync" should update submodule URLs' '
6667
)
6768
'
6869

69-
test_expect_success '"git submodule sync" should update submodule URLs if not yet cloned' '
70+
test_expect_success '"git submodule sync" should update known submodule URLs' '
7071
(cd empty-clone &&
7172
git pull &&
7273
git submodule sync &&
7374
test -d "$(git config submodule.submodule.url)"
7475
)
7576
'
7677

78+
test_expect_success '"git submodule sync" should not vivify uninteresting submodule' '
79+
(cd top-only-clone &&
80+
git pull &&
81+
git submodule sync &&
82+
test -z "$(git config submodule.submodule.url)" &&
83+
git submodule sync submodule &&
84+
test -z "$(git config submodule.submodule.url)"
85+
)
86+
'
87+
7788
test_done

0 commit comments

Comments
 (0)