init: do not set unnecessary core.worktree
commit6311cfaf93716bcc43dd1151cb1763e3f80d8099
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sun, 25 Sep 2016 03:14:39 +0000 (25 10:14 +0700)
committerJunio C Hamano <gitster@pobox.com>
Sun, 25 Sep 2016 23:32:35 +0000 (25 16:32 -0700)
tree70e5c6f6a1f580a0fd837e7a4a0d5645300102f3
parent1bd1907951a42040fa14fd19e432df9cb4107180
init: do not set unnecessary core.worktree

The function needs_work_tree_config() that is called from
create_default_files() is supposed to be fed the path to ".git" that
looks as if it is at the top of the working tree, and decide if that
location matches the actual worktree being used.  This comparison allows
"git init" to decide if core.worktree needs to be recorded in the
working tree.

In the current code, however, we feed the return value from
get_git_dir(), which can be totally different from what the function
expects when "gitdir" file is involved.  Instead of giving the path to
the ".git" at the top of the working tree, we end up feeding the actual
path that the file points at.

This original location of ".git" however is only known to init_db().
Make init_db() save it and have it passed to create_default_files() as a
new parameter, which passes the correct location down to
needs_work_tree_config() to fix this.

Noticed-by: Max Nordlund <max.nordlund@sqore.com>
Helped-by: Michael J Gruber <git@drmicha.warpmail.net>
Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/init-db.c
t/t0001-init.sh