On Sun, Apr 24, 2022 at 07:01:08PM -0700, Carlo Marcelo Arenas Belón wrote: > On Sat, Apr 23, 2022 at 04:44:57PM -0700, Junio C Hamano wrote: > > > > Actually, not quite. when "git" runs in "sudo git", the real > > identity has long lost > > Right, but in this specific case, the terminal is still a good indication > of who the user is, so the following would work. > > diff --git a/git-compat-util.h b/git-compat-util.h > index 58fd813bd01..5d5d91688ee 100644 > --- a/git-compat-util.h > +++ b/git-compat-util.h > @@ -442,6 +442,11 @@ static inline int is_path_owned_by_current_uid(const char *path) > struct stat st; > if (lstat(path, &st)) > return 0; > + if (isatty(1)) { > + struct stat ttyst; > + if (!stat(ttyname(1), &ttyst)) > + return st.st_uid == ttyst.st_uid; > + } > return st.st_uid == geteuid(); > } Our 'GIT-VERSION-GEN' runs 'var=$(git describe ...)', so standard output is not a terminal during 'sudo make install' > It obviously needs more polishing and portability work, though, and I don't > like that it makes the general case more complicated, so maybe would be better > to only do it running as root? > > At that point, though you might as well excempt root from this check > > Carlo