Skip to content

Commit 4a5a800

Browse files
committed
Merge branch 'jc/submodule-sync-no-auto-vivify' into maint
* jc/submodule-sync-no-auto-vivify: submodule add: always initialize .git/config entry submodule sync: do not auto-vivify uninteresting submodule
2 parents a35d78c + 2cd9de3 commit 4a5a800

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
@@ -246,7 +246,6 @@ cmd_add()
246246
url="$repo"
247247
;;
248248
esac
249-
git config submodule."$path".url "$url"
250249
else
251250

252251
module_clone "$path" "$realrepo" "$reference" || exit
@@ -260,6 +259,7 @@ cmd_add()
260259
esac
261260
) || die "Unable to checkout submodule '$path'"
262261
fi
262+
git config submodule."$path".url "$url"
263263

264264
git add $force "$path" ||
265265
die "Failed to add submodule '$path'"
@@ -359,25 +359,26 @@ cmd_init()
359359
do
360360
# Skip already registered paths
361361
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
378377

378+
# Copy "update" setting when it is not set yet
379379
upd="$(git config -f .gitmodules submodule."$name".update)"
380380
test -z "$upd" ||
381+
test -n "$(git config submodule."$name".update)" ||
381382
git config submodule."$name".update "$upd" ||
382383
die "Failed to register update mode for submodule path '$path'"
383384

@@ -878,17 +879,20 @@ cmd_sync()
878879
;;
879880
esac
880881

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
885883
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
892896
fi
893897
done
894898
}

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)