help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: GIT_DIR unset in vc-git.el


From: Stefan Monnier
Subject: Re: GIT_DIR unset in vc-git.el
Date: Tue, 30 Apr 2024 08:55:18 -0400
User-agent: Gnus/5.13 (Gnus v5.13)

> In vc-git.el, the function vc-git--call unsets GIT_DIR before calling
> git.  What is the reason for this?

When GIT_DIR is set (as in your case), it is usually valid only for some
of the files, and `vc-git` has no reason to believe that the GIT_DIR
that happened to be set in the process from which Emacs was started
applies to all the files that will be visited during this Emacs session.

`vc-region-history` says that the commit which introduced this GIT_DIR
override is:

    commit dc5e65b5deb2f5b67f6c3a06ae81c6b074bd4b56
    Author: Dmitry Gutov <dgutov@yandex.ru>
    Date:   Wed Jun 22 02:04:33 2016 +0300
    
        Unset GIT_DIR when calling Git commands
        
        * lisp/vc/vc-git.el (vc-git--call, vc-git-command):
        Unset GIT_DIR (bug#23769).

So you can check bug#23769 for further info.

>   (defun git-link-home ()
>     (interactive)
>     (let ((process-environment
>            `(,(format "GIT_DIR=%s" (expand-file-name "~/.home.git/"))
>              ,(format "GIT_WORK_TREE=%s" (expand-file-name "~/"))
>              ,@process-environment)))
>       (recursive-edit)))

Maybe you can save yourself the trouble.

    cd ~/.home.git; git worktree add ~ main

won't work because it will complain that ~ "already exists", but that's
just Git being too protective.  You can "do it by hand":

    cd ~/.home.git; git worktree add ~/dummy main
    mv ~/dummy/.git ~/.
    sed -i s/.dummy// ~/.home.git/worktrees/dummy/gitdir

and then your home's Git data will still be stored in that bare
`.home.git` but without having to mess with `GIT_DIR` and
`GIT_WORK_TREE`.  The only/main difference is that you'll now have
a `~/.git` file (which points at `~/.home.git/worktrees/dummy`).

> Is there any harm in changing vc-git--call to not do that?

In general there can be, but only in some specific circumstances, so you
can also opt to do that, of course.


        Stefan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]