all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* GIT_DIR unset in vc-git.el
@ 2024-04-29 17:17 Emre Yolcu
  2024-04-30 12:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-04-30 12:55 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Emre Yolcu @ 2024-04-29 17:17 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

In vc-git.el, the function vc-git--call unsets GIT_DIR before calling git.  
What is the reason for this? I am curious because I use a bare Git  
repository to manage my home directory, and this involves temporarily  
modifying GIT_DIR and GIT_WORK_TREE. More specifically, I use the function  
below, which keeps a modified environment for the duration of the  
recursive edit.

   (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)))

This works fine for Magit, but not for VC. In particular, the Git branch  
information that is displayed in the mode line disappears because VC  
unsets GIT_DIR before calling git. Is there any harm in changing  
vc-git--call to not do that?

Best,
Emre




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_DIR unset in vc-git.el
  2024-04-29 17:17 GIT_DIR unset in vc-git.el Emre Yolcu
@ 2024-04-30 12:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
  2024-04-30 20:12   ` Emre Yolcu
  2024-04-30 12:55 ` Eli Zaretskii
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-04-30 12:55 UTC (permalink / raw)
  To: help-gnu-emacs

> 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




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_DIR unset in vc-git.el
  2024-04-29 17:17 GIT_DIR unset in vc-git.el Emre Yolcu
  2024-04-30 12:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-04-30 12:55 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Eli Zaretskii @ 2024-04-30 12:55 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Emre Yolcu <mail@emreyolcu.com>
> Date: Mon, 29 Apr 2024 13:17:15 -0400
> 
> Hi,
> 
> In vc-git.el, the function vc-git--call unsets GIT_DIR before calling git.  
> What is the reason for this? I am curious because I use a bare Git  
> repository to manage my home directory, and this involves temporarily  
> modifying GIT_DIR and GIT_WORK_TREE. More specifically, I use the function  
> below, which keeps a modified environment for the duration of the  
> recursive edit.
> 
>    (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)))
> 
> This works fine for Magit, but not for VC. In particular, the Git branch  
> information that is displayed in the mode line disappears because VC  
> unsets GIT_DIR before calling git. Is there any harm in changing  
> vc-git--call to not do that?

See bug#23769 for the reasons why we remove GIT_DIR from the
environment.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_DIR unset in vc-git.el
  2024-04-30 12:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
@ 2024-04-30 20:12   ` Emre Yolcu
  2024-04-30 20:38     ` Stefan Monnier
  0 siblings, 1 reply; 5+ messages in thread
From: Emre Yolcu @ 2024-04-30 20:12 UTC (permalink / raw)
  To: Stefan Monnier, help-gnu-emacs

> `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.

Thanks for the pointer; the discussion on bug#23769 has been helpful in 
solving my issue.

>>    (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`).

If I understood the suggestion correctly, this would make every 
invocation of git under my home directory think that it is in a 
repository. This is not my goal, since I rarely work on maintaining my 
home directory but often on other Git repositories residing somewhere in 
home. With the "linking" approach above, I enter recursive edit, work on 
some configuration files, and exit when I am done so that git becomes 
unaware that home is kept under version control.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: GIT_DIR unset in vc-git.el
  2024-04-30 20:12   ` Emre Yolcu
@ 2024-04-30 20:38     ` Stefan Monnier
  0 siblings, 0 replies; 5+ messages in thread
From: Stefan Monnier @ 2024-04-30 20:38 UTC (permalink / raw)
  To: Emre Yolcu; +Cc: help-gnu-emacs

> If I understood the suggestion correctly, this would make every invocation
> of git under my home directory think that it is in a repository. This is not
> my goal, since I rarely work on maintaining my home directory but often on
> other Git repositories residing somewhere in home. With the "linking"
> approach above, I enter recursive edit, work on some configuration files,
> and exit when I am done so that git becomes unaware that home is kept under
> version control.

FWIW, on some of my machines I have my home in Git (in a "plain" way,
i.e. with a normal `.git` subdirectory rather than a bare Git in
something like `.home.git`), and it doesn't get in the way of Git
repositories residing somewhere inside my home directory: Git uses the
"nearest" `.git`.


        Stefan


PS: Admittedly, over the years, I have found it more convenient to have
a separate `config` directory under Git's control, and then add symlinks
from my home dir into that one for those files which I want to have
under Git's control.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-30 20:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-29 17:17 GIT_DIR unset in vc-git.el Emre Yolcu
2024-04-30 12:55 ` Stefan Monnier via Users list for the GNU Emacs text editor
2024-04-30 20:12   ` Emre Yolcu
2024-04-30 20:38     ` Stefan Monnier
2024-04-30 12:55 ` Eli Zaretskii

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.