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

Re: git gc changes ownerships of files linux

From
Torsten Bögershausen <tboegi@web.de>
Date
Feb 11, 2024, 15:14 UTC
Message-ID
<20240211151455.GA27103@tb-raspi4>
In-Reply-To
<CABkRduQNdgdF8WhZadP5hyYvpEWgP_AE8=qzxNiRNA71bdJcYQ@mail.gmail.com>
On Sat, Feb 10, 2024 at 08:52:22PM +0100, K_V wrote:
Show 20 quoted lines
> Hi team git
>
> Running 'git -C /srv/mssioncontrol/.git gc' on linux from a user which
> has access to another users files will occasionally change the
> ownership of the file 'packed-refs'. I believe git actually overwrites
> the file with a new one at the end af the gc command. But details
> about this is not writen in the help text. Could it be a bug?
>
> Use case: I'm using ansible to cleanup .git directories across
> multible servers and this issue is starting to cause problems.
>
> My solution is to make a variable containing the user and group id
> before running gc command and then reapply it afterwards:
> current_owner_uid_gid=$(stat -c "%u:%g" /srv/mssioncontrol/.git)
> git -C /srv/mssioncontrol/.git gc
> chown -R $current_owner_uid_gid "/srv/mssioncontrol/.git"
>
> Details:
> Debian GNU/Linux 12 (bookworm)
> git version 2.39.2

Thanks for reporting this - I think that you have a working workaround ?

However, Git has a feature called "shared repository". You need to define a (unix) group that is shared between your user(s) and the ansible user.

The basic trick is to do git config core.sharedRepository true

(And then change the ownership of all files/directories to the new group)

There is a docu here, please search for core.sharedRepository https://git-scm.com/docs/git-config

I wonder, which solution is easier to maintain ?
>
> Best:
> zinen
>
Previous: K_VNext: brian m. carlson
Message 2 of 8 in “git gc changes ownerships of files linux”
  1. K_VFeb 10, 2024
  2. Torsten BögershausenFeb 11, 2024
  3. brian m. carlsonFeb 11, 2024
  4. Torsten BögershausenFeb 11, 2024
  5. Junio C HamanoFeb 11, 2024
  6. Torsten BögershausenFeb 11, 2024
  7. brian m. carlsonFeb 11, 2024
  8. rsbecker@nexbridge.comFeb 11, 2024

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.