Skip to content

Commit 14890e9

Browse files
committed
Merge branch 'sb/submodule-update-reset-fix' into maint
When resetting the working tree files recursively, the working tree of submodules are now also reset to match. * sb/submodule-update-reset-fix: submodule: submodule_move_head omits old argument in forced case unpack-trees: oneway_merge to update submodules t/lib-submodule-update.sh: fix test ignoring ignored files in submodules t/lib-submodule-update.sh: clarify test
2 parents c1ab3b8 + 7dcc1f4 commit 14890e9

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

submodule.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1657,7 +1657,9 @@ int submodule_move_head(const char *path,
16571657
else
16581658
argv_array_push(&cp.args, "-m");
16591659

1660-
argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
1660+
if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
1661+
argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
1662+
16611663
argv_array_push(&cp.args, new ? new : EMPTY_TREE_SHA1_HEX);
16621664

16631665
if (run_command(&cp)) {

t/lib-submodule-update.sh

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ test_submodule_recursing_with_args_common() {
664664
cd submodule_update &&
665665
git -C sub1 checkout -b keep_branch &&
666666
git -C sub1 rev-parse HEAD >expect &&
667-
git branch -t check-keep origin/modify_sub1 &&
668-
$command check-keep &&
667+
git branch -t modify_sub1 origin/modify_sub1 &&
668+
$command modify_sub1 &&
669669
test_superproject_content origin/modify_sub1 &&
670670
test_submodule_content sub1 origin/modify_sub1 &&
671671
git -C sub1 rev-parse keep_branch >actual &&
@@ -885,6 +885,7 @@ test_submodule_switch_recursing_with_args () {
885885
(
886886
cd submodule_update &&
887887
git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
888+
echo ignored >.git/modules/sub1/info/exclude &&
888889
: >sub1/ignored &&
889890
$command replace_sub1_with_file &&
890891
test_superproject_content origin/replace_sub1_with_file &&
@@ -1014,4 +1015,18 @@ test_submodule_forced_switch_recursing_with_args () {
10141015
test_submodule_content sub1 origin/modify_sub1
10151016
)
10161017
'
1018+
1019+
test_expect_success "$command: changed submodule worktree is reset" '
1020+
prolog &&
1021+
reset_work_tree_to_interested add_sub1 &&
1022+
(
1023+
cd submodule_update &&
1024+
rm sub1/file1 &&
1025+
: >sub1/new_file &&
1026+
git -C sub1 add new_file &&
1027+
$command HEAD &&
1028+
test_path_is_file sub1/file1 &&
1029+
test_path_is_missing sub1/new_file
1030+
)
1031+
'
10171032
}

unpack-trees.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2139,6 +2139,9 @@ int oneway_merge(const struct cache_entry * const *src,
21392139
ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE))
21402140
update |= CE_UPDATE;
21412141
}
2142+
if (o->update && S_ISGITLINK(old->ce_mode) &&
2143+
should_update_submodules() && !verify_uptodate(old, o))
2144+
update |= CE_UPDATE;
21422145
add_entry(o, old, update, 0);
21432146
return 0;
21442147
}

0 commit comments

Comments
 (0)