Skip to content

Commit 106040f

Browse files
committed
Merge branch 'so/submodule-no-update-first-time' into maint
* so/submodule-no-update-first-time: t7406: "git submodule update {--merge|--rebase]" with new submodules submodule: no [--merge|--rebase] when newly cloned
2 parents eec8a51 + b200021 commit 106040f

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

git-submodule.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,7 @@ cmd_update()
423423
cmd_init "--" "$@" || return
424424
fi
425425

426+
cloned_modules=
426427
module_list "$@" |
427428
while read mode sha1 stage path
428429
do
@@ -442,6 +443,7 @@ cmd_update()
442443
if ! test -d "$path"/.git -o -f "$path"/.git
443444
then
444445
module_clone "$path" "$url" "$reference"|| exit
446+
cloned_modules="$cloned_modules;$name"
445447
subsha1=
446448
else
447449
subsha1=$(clear_local_git_env; cd "$path" &&
@@ -469,6 +471,13 @@ cmd_update()
469471
die "Unable to fetch in submodule path '$path'"
470472
fi
471473

474+
# Is this something we just cloned?
475+
case ";$cloned_modules;" in
476+
*";$name;"*)
477+
# then there is no local change to integrate
478+
update_module= ;;
479+
esac
480+
472481
case "$update_module" in
473482
rebase)
474483
command="git rebase"

t/t7406-submodule-update.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,56 @@ test_expect_success 'submodule init picks up merge' '
203203
)
204204
'
205205

206+
test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
207+
(cd super &&
208+
rm -rf submodule &&
209+
git submodule update submodule &&
210+
git status -s submodule >expect &&
211+
rm -rf submodule &&
212+
git submodule update --merge submodule &&
213+
git status -s submodule >actual &&
214+
test_cmp expect actual
215+
)
216+
'
217+
218+
test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
219+
(cd super &&
220+
rm -rf submodule &&
221+
git submodule update submodule &&
222+
git status -s submodule >expect &&
223+
rm -rf submodule &&
224+
git submodule update --rebase submodule &&
225+
git status -s submodule >actual &&
226+
test_cmp expect actual
227+
)
228+
'
229+
230+
test_expect_success 'submodule update ignores update=merge config for new submodules' '
231+
(cd super &&
232+
rm -rf submodule &&
233+
git submodule update submodule &&
234+
git status -s submodule >expect &&
235+
rm -rf submodule &&
236+
git config submodule.submodule.update merge &&
237+
git submodule update submodule &&
238+
git status -s submodule >actual &&
239+
git config --unset submodule.submodule.update &&
240+
test_cmp expect actual
241+
)
242+
'
243+
244+
test_expect_success 'submodule update ignores update=rebase config for new submodules' '
245+
(cd super &&
246+
rm -rf submodule &&
247+
git submodule update submodule &&
248+
git status -s submodule >expect &&
249+
rm -rf submodule &&
250+
git config submodule.submodule.update rebase &&
251+
git submodule update submodule &&
252+
git status -s submodule >actual &&
253+
git config --unset submodule.submodule.update &&
254+
test_cmp expect actual
255+
)
256+
'
257+
206258
test_done

0 commit comments

Comments
 (0)