Commit 86d26f24 authored by Committed by Junio C Hamano
setup.c: re-fix d95138e6 (setup: set env $GIT_WORK_TREE when ..
Commit d95138e6  attempted to fix a .git file problem by setting GIT_WORK_TREE whenever GIT_DIR is set. It sounded harmless because we handle GIT_DIR and GIT_WORK_TREE side by side for most commands, with two exceptions: git-init and git-clone. "git clone" is not happy with d95138e6. This command ignores GIT_DIR but respects GIT_WORK_TREE   which means it used to run fine from a hook, where GIT_DIR was set but GIT_WORK_TREE was not (*). With d95138e6, GIT_WORK_TREE is set all the time and git-clone interprets that as "I give you order to put the worktree here", usually against the user's intention. The solution in d95138e6 is reverted earlier, and instead we reuse the solution from c0562611 . It fixed another setup-messed- up-by-alias by saving and restoring env and spawning a new process, but for git-clone and git-init only. Now we conclude that setup-messed-up-by-alias is always evil. So the env restoration is done for _all_ commands, including external ones, whenever aliases are involved. It fixes what d95138e6 tried to fix, without upsetting git-clone-inside-hooks. The test from d95138e6 remains to verify it's not broken by this. A new test is added to make sure git-clone-inside-hooks remains happy. (*) GIT_WORK_TREE was not set _most of the time_. In some cases GIT_WORK_TREE is set and git-clone will behave differently. The use of GIT_WORK_TREE to direct git-clone to put work tree elsewhere looks like a mistake because it causes surprises this way. But that's a separate story.  d95138e6 (setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR - 2015-06-26)  2beebd22 (clone: create intermediate directories of destination repo - 2008-06-25)  20ccef49 (make git-clone GIT_WORK_TREE aware - 2007-07-06)  c0562611 (git potty: restore environments after alias expansion - 2014-06-08) Reported-by: Anthony Sottile <email@example.com> Signed-off-by: Nguyễn Thái Ngọc Duy <firstname.lastname@example.org> Signed-off-by: Junio C Hamano <email@example.com>
Showing with 36 additions and 12 deletions