Re: builtin command's prefix question
From: Junio C Hamano <hidden>
Date: 2016-06-15 22:43:56
Junio C Hamano [off-list ref] writes:
* I would say it is a misconfiguration if GIT_DIR is not set and GIT_WORK_TREE is, as the sole purpose of GIT_WORK_TREE is so that you can work from a subdirectory when you set GIT_DIR. I may be missing an obvious use case that this is useful, but I do not think of any. Dscho may be able to correct me on this, as he fixed up the original work tree series that was even messier quite a bit during the last round.
I had a short discussion with Dscho on this. One scenario that was
brought up was this.
You have a work tree of mixed contents that logically belong to
separate repository. Think $HOME/.?*, and tracking .vimrc and
.pinerc as separate "projects". You have $HOME/gits/vim.git and
$HOME/gits/pine.git bare-looking repositories.
The "kosher" way of doing this might be:
$ cd $HOME
$ GIT_WORK_TREE=$HOME; export GIT_WORK_TREE
$ edit .vimrc
$ GIT_DIR=gits/vim.git git commit .vimrc
$ edit .pinerc
$ GIT_DIR=gits/pine.git git commit .pinerc
However, if we define setup() to behave this way when GIT_DIR is not
defined and GIT_WORK_TREE is:
(1) internally pretend as if GIT_DIR was specified to be the
directory where the command was started from (iow, do getcwd()
once upon startup);
(2) chdir to GIT_WORK_TREE (which means "callers of setup() always
run from the top of the work tree");
(3) set prefix to NULL;
Then this workflow becomes possible:
$ cd $HOME
$ GIT_WORK_TREE=$HOME; export GIT_WORK_TREE
$ edit .vimrc .pinerc
$ cd $HOME/gits/vimrc.git && git commit .vimrc
$ cd $HOME/gits/pinerc.git && git commit .pinerc
I am not convinced this is giving any natural user experience, nor an
alternative:
$ cd $HOME
$ GIT_WORK_TREE=$HOME; export GIT_WORK_TREE
$ cd $HOME/gits/vimrc.git
$ edit $HOME/.vimrc
$ git commit .vimrc
$ cd $HOME/gits/pinerc.git
$ edit $HOME/.pinerc
$ git commit .pinerc
While I still think the combination is simply crazy and does not make
any sense, if enough users on the list agrees that it makes sense, I
wouldn't mind setup() did (1) to (3) mentioned above. The alternative
is simply to declare GIT_WORK_TREE without GIT_DIR is a nonsense and
either error error out or ignore GIT_WORK_TREE, which might be easier to
explain to people.
Opinions?