{"thread":{"id":"46291","subject":"[PATCH] recursive submodules: detach HEAD from new state, keeping branches sane","startedAt":"2017-06-30T00:38:59Z","lastAt":"2017-06-30T00:38:59Z","messageCount":1,"participants":["Stefan Beller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"323542","messageId":"20170630003851.17288-1-sbeller@google.com","threadId":"46291","inReplyTo":null,"subject":"[PATCH] recursive submodules: detach HEAD from new state, keeping branches sane","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2017-06-30T00:38:51Z","receivedAt":"2017-06-30T00:38:59Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"When a submodule is on a branch and in its superproject you run a recursive\ncheckout, the branch of the submodule is updated to what the superproject\nchecks out. This is very unexpected. Instead detach the HEAD when updating\nit.\n\nSigned-off-by: Stefan Beller <sbeller@google.com>\n---\n submodule.c               |  3 ++-\n t/lib-submodule-update.sh | 17 +++++++++++++++++\n 2 files changed, 19 insertions(+), 1 deletion(-)\n\ndiff --git a/submodule.c b/submodule.c\nindex da0b805493..719e8bd7a2 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1604,7 +1604,8 @@ int submodule_move_head(const char *path,\n \t\t\tcp.dir = path;\n \n \t\t\tprepare_submodule_repo_env(&cp.env_array);\n-\t\t\targv_array_pushl(&cp.args, \"update-ref\", \"HEAD\", new, NULL);\n+\t\t\targv_array_pushl(&cp.args, \"update-ref\", \"HEAD\",\n+\t\t\t\t\t \"--no-deref\", new, NULL);\n \n \t\t\tif (run_command(&cp)) {\n \t\t\t\tret = -1;\ndiff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh\nindex 2d26f86800..fc406b95d7 100755\n--- a/t/lib-submodule-update.sh\n+++ b/t/lib-submodule-update.sh\n@@ -848,6 +848,23 @@ test_submodule_switch_recursing_with_args () {\n \t\t\ttest_submodule_content sub1 origin/add_sub1\n \t\t)\n \t'\n+\ttest_expect_success \"$command: submodule branch is not changed, detach HEAD instead\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to_interested add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit -C sub1 checkout -b keep_branch &&\n+\t\t\tgit -C sub1 rev-parse HEAD >expect &&\n+\t\t\tgit branch -t check-keep origin/modify_sub1 &&\n+\t\t\t$command check-keep &&\n+\t\t\ttest_superproject_content origin/modify_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/modify_sub1 &&\n+\t\t\tgit -C sub1 rev-parse keep_branch >actual &&\n+\t\t\ttest_cmp expect actual &&\n+\t\t\ttest_must_fail git -C sub1 symbolic-ref HEAD\n+\t\t)\n+\t'\n+\n \t# Replacing a tracked file with a submodule produces a checked out submodule\n \ttest_expect_success \"$command: replace tracked file with submodule checks out submodule\" '\n \t\tprolog &&\n-- \n2.13.0.31.g9b732c453e\n\n"}]}