]> git.ipfire.org Git - thirdparty/git.git/commit
init: make --separate-git-dir work from within linked worktree
authorEric Sunshine <sunshine@sunshineco.com>
Mon, 31 Aug 2020 06:58:00 +0000 (02:58 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2020 18:47:45 +0000 (11:47 -0700)
commit59d876ccd688ae0fe761b571afe77a7c8317eb88
tree1756c6d41a14ad04bc522ba1fd7599a4e7b29015
parent42264bc841d416aab5a980cb4eeedf687f1190a5
init: make --separate-git-dir work from within linked worktree

The intention of `git init --separate-work-dir=<path>` is to move the
.git/ directory to a location outside of the main worktree. When used
within a linked worktree, however, rather than moving the .git/
directory as intended, it instead incorrectly moves the worktree's
.git/worktrees/<id> directory to <path>, thus disconnecting the linked
worktree from its parent repository and breaking the worktree in the
process since its local .git file no longer points at a location at
which it can find the object database. Fix this broken behavior.

An intentional side-effect of this change is that it also closes a
loophole not caught by ccf236a23a (init: disallow --separate-git-dir
with bare repository, 2020-08-09) in which the check to prevent
--separate-git-dir being used in conjunction with a bare repository was
unable to detect the invalid combination when invoked from within a
linked worktree. Therefore, add a test to verify that this loophole is
closed, as well.

Reported-by: Henré Botha <henrebotha@gmail.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
t/t0001-init.sh