Merge branch 'sb/submodule-update-reset-fix' into maint
authorJunio C Hamano <gitster@pobox.com>
Tue, 27 Feb 2018 18:43:54 +0000 (10:43 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 27 Feb 2018 18:43:54 +0000 (10:43 -0800)
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

submodule.c
t/lib-submodule-update.sh
unpack-trees.c
index 29677043174f8d77d6774bc2533b653d03adf990..47ddc9b2739bf52d9263ea9cd90edde6e9d1c738 100644 (file)
@@ -1657,7 +1657,9 @@ int submodule_move_head(const char *path,
        else
                argv_array_push(&cp.args, "-m");
 
-       argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+       if (!(flags & SUBMODULE_MOVE_HEAD_FORCE))
+               argv_array_push(&cp.args, old ? old : EMPTY_TREE_SHA1_HEX);
+
        argv_array_push(&cp.args, new ? new : EMPTY_TREE_SHA1_HEX);
 
        if (run_command(&cp)) {
index 38dadd2c2902f3621d54168d32a54d7863497968..1f38a85371ab49790d14d3d4b82a0ee6e52789dd 100755 (executable)
@@ -664,8 +664,8 @@ test_submodule_recursing_with_args_common() {
                        cd submodule_update &&
                        git -C sub1 checkout -b keep_branch &&
                        git -C sub1 rev-parse HEAD >expect &&
-                       git branch -t check-keep origin/modify_sub1 &&
-                       $command check-keep &&
+                       git branch -t modify_sub1 origin/modify_sub1 &&
+                       $command modify_sub1 &&
                        test_superproject_content origin/modify_sub1 &&
                        test_submodule_content sub1 origin/modify_sub1 &&
                        git -C sub1 rev-parse keep_branch >actual &&
@@ -885,6 +885,7 @@ test_submodule_switch_recursing_with_args () {
                (
                        cd submodule_update &&
                        git branch -t replace_sub1_with_file origin/replace_sub1_with_file &&
+                       echo ignored >.git/modules/sub1/info/exclude &&
                        : >sub1/ignored &&
                        $command replace_sub1_with_file &&
                        test_superproject_content origin/replace_sub1_with_file &&
@@ -1014,4 +1015,18 @@ test_submodule_forced_switch_recursing_with_args () {
                        test_submodule_content sub1 origin/modify_sub1
                )
        '
+
+       test_expect_success "$command: changed submodule worktree is reset" '
+               prolog &&
+               reset_work_tree_to_interested add_sub1 &&
+               (
+                       cd submodule_update &&
+                       rm sub1/file1 &&
+                       : >sub1/new_file &&
+                       git -C sub1 add new_file &&
+                       $command HEAD &&
+                       test_path_is_file sub1/file1 &&
+                       test_path_is_missing sub1/new_file
+               )
+       '
 }
index bf8b6029013c31000d83d6292f83ce0d0021d5d4..96c3327f19de4b1060ed43ef291a57a76ff2b8cc 100644 (file)
@@ -2139,6 +2139,9 @@ int oneway_merge(const struct cache_entry * const *src,
                            ie_match_stat(o->src_index, old, &st, CE_MATCH_IGNORE_VALID|CE_MATCH_IGNORE_SKIP_WORKTREE))
                                update |= CE_UPDATE;
                }
+               if (o->update && S_ISGITLINK(old->ce_mode) &&
+                   should_update_submodules() && !verify_uptodate(old, o))
+                       update |= CE_UPDATE;
                add_entry(o, old, update, 0);
                return 0;
        }