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

Re: Server-side preventing some files from being overwritten

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jul 15, 2016, 13:56 UTC
Message-ID
<CACBZZX7YFQ3o+5wbVz0ca6__3ViD0b-qbrX06CkxhAHE8uQ6oQ@mail.gmail.com>
In-Reply-To
<CAPc5daXxAqXtUvs1Xr_vgncXqcvR8-VG67oDAgOQ8xPcT7nCeQ@mail.gmail.com>
On Thu, Jul 14, 2016 at 8:44 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 19 quoted lines
> On Thu, Jul 14, 2016 at 11:27 AM, Junio C Hamano <gitster@pobox.com> wrote:
>> Thorsten Glaser <t.glaser@tarent.de> writes:
>>
>>>       if test x"0" != x"$(comm -23z \
>>>           <(git ls-tree -r -z "$old" "$subdir" | sort -z) \
>>>           <(git ls-tree -r -z "$new" "$subdir" | sort -z) | wc -c)"; then
>>>               echo >&2 'Untouchable files touched, commit rejected!'
>>>               exit 1
>>>       fi
>>
>> Can't this become simpler, e.g.
>>
>>         if ! git diff-tree --quiet "$old" "$new" -- "$subdir"
>>         then
>>                 echo >&2 "Ooh, $subdir is touched"
>>                 exit 1
>>         fi
>
> Ehh, you need to tell diff-tree to recurse, i.e. "diff-tree -r".

Note that although this is literally what Thorsten is asking for, I think it's worth noting for the list explicitly that all these examples that do "diff $old..$new" will *not* prevent your repository from having *commits* that touch those files, but they will prevent you from having *pushes* where the end state is a net change in those files.

I.e. it allows pushing a series which is a series of two commits which:
  1. Change the forbidden file(s)
  2. Undo changes to the forbidden file(s)

This *can* be critically important or not matter at all depending on your use case, i.e. does it matter that disallowed and potentially malicious changes come up in "git bisect", or will you ever be rolling out anything but the latest tip of the branch you're testing in production?

If the answer to either of those is "yes" you need something that does a "git log --stat $old..$new" and parses out if *any* of the commits make changes to those files.

See e.g. my https://github.com/avar/pre-receive-reject-binaries for one example of that, although it rejects binaries you could easily modify it to check the filename(s) instead.

Previous: Stefan BellerNext: Thorsten Glaser
Message 7 of 12 in “Server-side preventing some files from being overwritten”
  1. Thorsten GlaserJul 14, 2016
  2. Stefan BellerJul 14, 2016
  3. Thorsten GlaserJul 14, 2016
  4. Junio C HamanoJul 14, 2016
  5. Junio C HamanoJul 14, 2016
  6. Stefan BellerJul 14, 2016
  7. Ævar Arnfjörð BjarmasonJul 15, 2016
  8. Thorsten GlaserJul 15, 2016
  9. Thorsten GlaserJul 14, 2016
  10. Junio C HamanoJul 14, 2016
  11. Jakub NarębskiJul 21, 2016
  12. Thorsten GlaserJul 21, 2016

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.