Skip to content

Commit ccee608

Browse files
committed
submodule sync: do not auto-vivify uninteresting submodule
Earlier 33f072f (submodule sync: Update "submodule.<name>.url" for empty directories, 2010-10-08) attempted to fix a bug where "git submodule sync" command does not update the URL if the current superproject does not have a checkout of the submodule. However, it did so by unconditionally registering submodule.$name.url to every submodule in the project, even the ones that the user has never showed interest in at all by running 'git submodule init' command. This caused subsequent 'git submodule update' to start cloning/updating submodules that are not interesting to the user at all. Update the code so that the URL is updated from the .gitmodules file only for submodules that already have submodule.$name.url entries, i.e. the ones the user has showed interested in having a checkout. Acked-by: Jens Lehmann <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33f072f commit ccee608

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

Documentation/git-submodule.txt

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

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

git-submodule.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -836,17 +836,20 @@ cmd_sync()
836836
;;
837837
esac
838838

839-
say "Synchronizing submodule url for '$name'"
840-
git config submodule."$name".url "$url"
841-
842-
if test -e "$path"/.git
839+
if git config "submodule.$name.url" >/dev/null 2>/dev/null
843840
then
844-
(
845-
clear_local_git_env
846-
cd "$path"
847-
remote=$(get_default_remote)
848-
git config remote."$remote".url "$url"
849-
)
841+
say "Synchronizing submodule url for '$name'"
842+
git config submodule."$name".url "$url"
843+
844+
if test -e "$path"/.git
845+
then
846+
(
847+
clear_local_git_env
848+
cd "$path"
849+
remote=$(get_default_remote)
850+
git config remote."$remote".url "$url"
851+
)
852+
fi
850853
fi
851854
done
852855
}

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)