git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: a problem with git describe

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Apr 25, 2022, 06:03 UTC
Message-ID
<20220425060310.57tzqjopniul7h5p@carlos-mbp.lan>
In-Reply-To
<20220425050549.GA3280@szeder.dev>
On Mon, Apr 25, 2022 at 07:05:49AM +0200, SZEDER Gábor wrote:
Show 27 quoted lines
> 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'

didn't realize the orginal report was coming from `sudo make install` in git's own repository, but even that worked for me.

when I meant the original case I went with an artificial test where I run :

  $ mkdir -p r/t
  $ sudo chown root r
  $ cd r/t
  $ git init
  $ sudo git status
and I get no error, unlike the original version of the code.

of course, part of the "extra work needed" is to figure out if stdout is the best place to look at, I chose it just because that is the unoficial way to signal in our code that we are running interactively.

note that usually unless a pipe is involved or nohup is used, the tty is still attached to your process.

Carlo
Previous: SZEDER GáborNext: Junio C Hamano
Message 7 of 23 in “a problem with git describe”
  1. Guy MaurelApr 23, 2022
  2. Philip OakleyApr 23, 2022
  3. Junio C HamanoApr 23, 2022
  4. Junio C HamanoApr 23, 2022
  5. Carlo Marcelo Arenas BelónApr 25, 2022
  6. SZEDER GáborApr 25, 2022
  7. Carlo Marcelo Arenas BelónApr 25, 2022
  8. Junio C HamanoApr 25, 2022
  9. Carlo Marcelo Arenas BelónApr 25, 2022
  10. Carlo Marcelo Arenas BelónApr 25, 2022
  11. Guy MaurelApr 25, 2022
  12. Johannes SchindelinApr 26, 2022
  13. rsbecker@nexbridge.comApr 26, 2022
  14. Carlo ArenasApr 26, 2022
  15. Junio C HamanoApr 26, 2022
  16. Carlo ArenasApr 26, 2022
  17. Johannes SchindelinApr 26, 2022
  18. Junio C HamanoApr 26, 2022
  19. Taylor BlauApr 26, 2022
  20. Johannes SchindelinApr 26, 2022
  21. Taylor BlauApr 26, 2022
  22. Johannes SchindelinApr 26, 2022
  23. Junio C HamanoApr 26, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.