From a17062cf42556593fb73547e613b0be867026257 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 2 May 2017 12:32:12 -0700 Subject: submodule_move_head: reuse child_process structure for futher commands We do not need to declare another struct child_process, but we can just reuse the existing `cp` struct. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- submodule.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/submodule.c b/submodule.c index d3299e29c0..a2377ce019 100644 --- a/submodule.c +++ b/submodule.c @@ -1468,15 +1468,15 @@ int submodule_move_head(const char *path, if (!(flags & SUBMODULE_MOVE_HEAD_DRY_RUN)) { if (new) { - struct child_process cp1 = CHILD_PROCESS_INIT; + child_process_init(&cp); /* also set the HEAD accordingly */ - cp1.git_cmd = 1; - cp1.no_stdin = 1; - cp1.dir = path; + cp.git_cmd = 1; + cp.no_stdin = 1; + cp.dir = path; - argv_array_pushl(&cp1.args, "update-ref", "HEAD", new, NULL); + argv_array_pushl(&cp.args, "update-ref", "HEAD", new, NULL); - if (run_command(&cp1)) { + if (run_command(&cp)) { ret = -1; goto out; } -- cgit v1.2.3 From da27bc81f00fb5315341b26db8879c266e8ba1a2 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 2 May 2017 12:32:13 -0700 Subject: submodule: avoid auto-discovery in new working tree manipulator code All commands that are run in a submodule, are run in a correct setup, there is no need to prepare the environment without setting the GIT_DIR variable. By setting the GIT_DIR variable we fix issues as discussed in 10f5c52656 (submodule: avoid auto-discovery in prepare_submodule_repo_env(), 2016-09-01) Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- submodule.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/submodule.c b/submodule.c index a2377ce019..b0141a66dd 100644 --- a/submodule.c +++ b/submodule.c @@ -1363,7 +1363,7 @@ static int submodule_has_dirty_index(const struct submodule *sub) { struct child_process cp = CHILD_PROCESS_INIT; - prepare_submodule_repo_env_no_git_dir(&cp.env_array); + prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; argv_array_pushl(&cp.args, "diff-index", "--quiet", @@ -1380,7 +1380,7 @@ static int submodule_has_dirty_index(const struct submodule *sub) static void submodule_reset_index(const char *path) { struct child_process cp = CHILD_PROCESS_INIT; - prepare_submodule_repo_env_no_git_dir(&cp.env_array); + prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; cp.no_stdin = 1; @@ -1438,7 +1438,7 @@ int submodule_move_head(const char *path, } } - prepare_submodule_repo_env_no_git_dir(&cp.env_array); + prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; cp.no_stdin = 1; -- cgit v1.2.3 From 218c883783ee7c23a0955507f5b7ac4027428d63 Mon Sep 17 00:00:00 2001 From: Stefan Beller Date: Tue, 2 May 2017 12:32:14 -0700 Subject: submodule: properly recurse for read-tree and checkout We forgot to prepare the submodule env, which is only a problem for nested submodules. See 2e5d6503bd (ls-files: fix recurse-submodules with nested submodules, 2017-04-13) for further explanation. To come up with a proper test for this, we'd need to look at nested submodules just as in that given commit. It turns out we're lucky and these tests already exist, but are marked as failing. We need to pass `--recurse-submodules` to read-tree additionally to make these tests pass. Passing that flag alone would not make the tests pass, such that this covers testing for the bug fix of the submodule env as well. Signed-off-by: Stefan Beller Signed-off-by: Junio C Hamano --- submodule.c | 3 ++- t/lib-submodule-update.sh | 7 +------ t/t1013-read-tree-submodule.sh | 1 - t/t2013-checkout-submodule.sh | 1 - 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/submodule.c b/submodule.c index b0141a66dd..b3ae642f29 100644 --- a/submodule.c +++ b/submodule.c @@ -1446,7 +1446,7 @@ int submodule_move_head(const char *path, argv_array_pushf(&cp.args, "--super-prefix=%s%s/", get_super_prefix_or_empty(), path); - argv_array_pushl(&cp.args, "read-tree", NULL); + argv_array_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) argv_array_push(&cp.args, "-n"); @@ -1474,6 +1474,7 @@ int submodule_move_head(const char *path, cp.no_stdin = 1; cp.dir = path; + prepare_submodule_repo_env(&cp.env_array); argv_array_pushl(&cp.args, "update-ref", "HEAD", new, NULL); if (run_command(&cp)) { diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index fb4f7b014e..2c17826e95 100755 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -787,11 +787,6 @@ test_submodule_switch_recursing () { then RESULTDS=failure fi - RESULTR=success - if test "$KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED" = 1 - then - RESULTR=failure - fi RESULTOI=success if test "$KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED" = 1 then @@ -1003,7 +998,7 @@ test_submodule_switch_recursing () { ' # recursing deeper than one level doesn't work yet. - test_expect_$RESULTR "$command: modified submodule updates submodule recursively" ' + test_expect_success "$command: modified submodule updates submodule recursively" ' prolog && reset_work_tree_to_interested add_nested_sub && ( diff --git a/t/t1013-read-tree-submodule.sh b/t/t1013-read-tree-submodule.sh index de1ba02dc5..7019d0a04f 100755 --- a/t/t1013-read-tree-submodule.sh +++ b/t/t1013-read-tree-submodule.sh @@ -5,7 +5,6 @@ test_description='read-tree can handle submodules' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-submodule-update.sh -KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1 KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 KNOWN_FAILURE_SUBMODULE_OVERWRITE_IGNORED_UNTRACKED=1 diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index e8f70b806f..aa35223369 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -64,7 +64,6 @@ test_expect_success '"checkout " honors submodule.*.ignore from .git/ ' KNOWN_FAILURE_DIRECTORY_SUBMODULE_CONFLICTS=1 -KNOWN_FAILURE_SUBMODULE_RECURSIVE_NESTED=1 test_submodule_switch_recursing "git checkout --recurse-submodules" test_submodule_forced_switch_recursing "git checkout -f --recurse-submodules" -- cgit v1.2.3