refs: use chdir_notify to update cached relative paths
commitfb9c2d27039a23457cb9710d86e00c51dfb910dc
authorJeff King <peff@peff.net>
Fri, 30 Mar 2018 18:35:12 +0000 (30 14:35 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 30 Mar 2018 19:50:03 +0000 (30 12:50 -0700)
treeb5a6eb64aaea881017bdf5e935f6accc42c21b8d
parent8500e0de3fe2e33ba503d432a4a5301ce2fb60fa
refs: use chdir_notify to update cached relative paths

Commit f57f37e2e1 (files-backend: remove the use of
git_path(), 2017-03-26) introduced a regression when a
relative $GIT_DIR is used in a working tree:

  - when we initialize the ref backend, we make a copy of
    get_git_dir(), which may be relative

  - later, we may call setup_work_tree() and chdir to the
    root of the working tree

  - further calls to the ref code will use the stored git
    directory, but relative paths will now point to the
    wrong place

The new test in t1501 demonstrates one such instance (the
bug causes us to write the ref update to the nonsense
"relative/relative/.git").

Since setup_work_tree() now uses chdir_notify, we can just
ask it update our relative paths when necessary.

Reported-by: Rafael Ascensao <rafa.almas@gmail.com>
Helped-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs/files-backend.c
refs/packed-backend.c
t/t1501-work-tree.sh