public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* GCC's Git update_hook doesn't support deleting branches
@ 2020-10-01 13:58 Jonathan Wakely
  2020-10-01 17:38 ` Joseph Myers
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Wakely @ 2020-10-01 13:58 UTC (permalink / raw)
  To: gcc

You get a nasty error like:

$ git push origin -d refs/users/redi/heads/calendar
remote: *** Update rejected by this repository's hooks.update-hook script
remote: *** (/git/gcc.git/hooks-bin/update_hook):
remote: *** fatal: bad object 0000000000000000000000000000000000000000
remote: *** Traceback (most recent call last):
remote: ***   File "/git/gcc.git/hooks-bin/update_hook", line 39, in <module>
remote: ***     main()
remote: ***   File "/git/gcc.git/hooks-bin/update_hook", line 27, in main
remote: ***     check=True, universal_newlines=True).stdout.split('\n')
remote: ***   File "/usr/lib64/python3.6/subprocess.py", line 438, in run
remote: ***     output=stdout, stderr=stderr)
remote: *** subprocess.CalledProcessError: Command '['git',
'rev-list', '0000000000000000000000000000000000000000',
'^4415a3e0965ae6e2a4bedd3584b2504ebb2d96f3']' returned non-zero exit
status 128.
remote: error: hook declined to update refs/users/redi/heads/calendar
To git+ssh://gcc.gnu.org/git/gcc.git
! [remote rejected]         refs/users/redi/heads/calendar (hook declined)
error: failed to push some refs to 'git+ssh://gcc.gnu.org/git/gcc.git'


The problem is that the script doesn't check whether the new_object is
000000000.

I think we want something like this:

--- update_hook 2020-09-02 23:30:25.074884982 +0000
+++ /tmp/update_hook    2020-10-01 13:57:14.681656258 +0000
@@ -12,6 +12,12 @@
    ref_name = sys.argv[1]
    old_object = sys.argv[2]
    new_object = sys.argv[3]
+    if re.fullmatch('0+', new_object) is not None:
+        if (not ref_name.startswith('refs/users/')
+            and not ref_name.startswith('refs/vendors/')):
+            error('Only personal and vendor branches can be deleted.')
+            sys.exit(1)
+        sys.exit(0)
    # Do not allow updates introducing ancestry based on the old
    # git-svn repository, to ensure people rebase onto the new history
    # rather than merging branches based on git-svn history into those

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

* Re: GCC's Git update_hook doesn't support deleting branches
  2020-10-01 13:58 GCC's Git update_hook doesn't support deleting branches Jonathan Wakely
@ 2020-10-01 17:38 ` Joseph Myers
  2020-10-01 18:05   ` Jonathan Wakely
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Myers @ 2020-10-01 17:38 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc

On Thu, 1 Oct 2020, Jonathan Wakely via Gcc wrote:

> The problem is that the script doesn't check whether the new_object is
> 000000000.
> 
> I think we want something like this:
> 
> --- update_hook 2020-09-02 23:30:25.074884982 +0000
> +++ /tmp/update_hook    2020-10-01 13:57:14.681656258 +0000
> @@ -12,6 +12,12 @@
>     ref_name = sys.argv[1]
>     old_object = sys.argv[2]
>     new_object = sys.argv[3]
> +    if re.fullmatch('0+', new_object) is not None:
> +        if (not ref_name.startswith('refs/users/')
> +            and not ref_name.startswith('refs/vendors/')):
> +            error('Only personal and vendor branches can be deleted.')
> +            sys.exit(1)

The check for which branches can be deleted is handled through the 
restrict-branch-deletion and allow-delete-branch settings.  All you should 
need is to exit early for new_object indicating ref deletion.

(Remember to use --author when committing to the hooks-bin scripts so the 
logs don't show all changes as authored by gccadmin.)

-- 
Joseph S. Myers
joseph@codesourcery.com

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

* Re: GCC's Git update_hook doesn't support deleting branches
  2020-10-01 17:38 ` Joseph Myers
@ 2020-10-01 18:05   ` Jonathan Wakely
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2020-10-01 18:05 UTC (permalink / raw)
  To: Joseph Myers; +Cc: gcc

On Thu, 1 Oct 2020 at 18:38, Joseph Myers wrote:
>
> On Thu, 1 Oct 2020, Jonathan Wakely via Gcc wrote:
>
> > The problem is that the script doesn't check whether the new_object is
> > 000000000.
> >
> > I think we want something like this:
> >
> > --- update_hook 2020-09-02 23:30:25.074884982 +0000
> > +++ /tmp/update_hook    2020-10-01 13:57:14.681656258 +0000
> > @@ -12,6 +12,12 @@
> >     ref_name = sys.argv[1]
> >     old_object = sys.argv[2]
> >     new_object = sys.argv[3]
> > +    if re.fullmatch('0+', new_object) is not None:
> > +        if (not ref_name.startswith('refs/users/')
> > +            and not ref_name.startswith('refs/vendors/')):
> > +            error('Only personal and vendor branches can be deleted.')
> > +            sys.exit(1)
>
> The check for which branches can be deleted is handled through the
> restrict-branch-deletion and allow-delete-branch settings.  All you should
> need is to exit early for new_object indicating ref deletion.
>
> (Remember to use --author when committing to the hooks-bin scripts so the
> logs don't show all changes as authored by gccadmin.)

Done.

$ git push origin -d refs/users/redi/heads/calendar
To git+ssh://gcc.gnu.org/git/gcc.git
- [deleted]                 refs/users/redi/heads/calendar

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

end of thread, other threads:[~2020-10-01 18:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-01 13:58 GCC's Git update_hook doesn't support deleting branches Jonathan Wakely
2020-10-01 17:38 ` Joseph Myers
2020-10-01 18:05   ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).