Skip to content

Commit 7dcc1f4

Browse files
stefanbellergitster
authored andcommitted
submodule: submodule_move_head omits old argument in forced case
When using hard reset or forced checkout with the option to recurse into submodules, the submodules need to be reset, too. It turns out that we need to omit the duplicate old argument to read-tree in all forced cases to omit the 2 way merge and use the more assertive behavior of reading the specific new tree into the index and updating the working tree. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad17312 commit 7dcc1f4

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,4 +1015,18 @@ test_submodule_forced_switch_recursing_with_args () {
10151015
test_submodule_content sub1 origin/modify_sub1
10161016
)
10171017
'
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+
'
10181032
}

0 commit comments

Comments
 (0)