• Stefan Beller's avatar
    submodule: unset core.worktree if no working tree is present · 898c2e65
    Stefan Beller authored
    When a submodules work tree is removed, we should unset its core.worktree
    setting as the worktree is no longer present. This is not just in line
    with the conceptual view of submodules, but it fixes an inconvenience
    for looking at submodules that are not checked out:
    
        git clone --recurse-submodules git://github.com/git/git && cd git &&
        git checkout --recurse-submodules v2.13.0
        git -C .git/modules/sha1collisiondetection log
        fatal: cannot chdir to '../../../sha1collisiondetection': \
            No such file or directory
    
    With this patch applied, the final call to git log works instead of dying
    in its setup, as the checkout will unset the core.worktree setting such
    that following log will be run in a bare repository.
    
    This patch covers all commands that are in the unpack machinery, i.e.
    checkout, read-tree, reset. A follow up patch will address
    "git submodule deinit", which will also make use of the new function
    submodule_unset_core_worktree(), which is why we expose it in this patch.
    
    This patch was authored as 4fa4f90c (submodule: unset core.worktree if
    no working tree is present, 2018-06-12), which was reverted as part of
    f178c13f (Revert "Merge branch 'sb/submodule-core-worktree'",
    2018-09-07). The revert was needed as the nearby commit e9831750
    (submodule: ensure core.worktree is set after update, 2018-06-18) is
    faulty and at the time of 7e25437d (Merge branch
    'sb/submodule-core-worktree', 2018-07-18) we could not revert the faulty
    commit only, as they were depending on each other: If core.worktree is
    unset, we have to have ways to ensure that it is set again once
    the working tree reappears again.
    
    Now that 4d6d6ef1 (Merge branch 'sb/submodule-update-in-c', 2018-09-17),
    specifically 74d4731d (submodule--helper: replace
    connect-gitdir-workingtree by ensure-core-worktree, 2018-08-13) is
    present, we already check and ensure core.worktree is set when
    populating a new work tree, such that we can re-introduce the commits
    that unset core.worktree when removing the worktree.
    Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
    Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    Signed-off-by: Stefan Beller's avatarStefan Beller <sbeller@google.com>
    Signed-off-by: 's avatarJunio C Hamano <gitster@pobox.com>
    898c2e65
submodule.h 5.38 KB