Bug 491464 - EGit doesn't prevent creation of "refs/for/master" branch
Summary: EGit doesn't prevent creation of "refs/for/master" branch
Status: RESOLVED FIXED
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: 4.4   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 501102 493352
  Show dependency tree
 
Reported: 2016-04-11 14:50 EDT by Sergey Prigogin CLA
Modified: 2016-09-13 10:02 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sergey Prigogin CLA 2016-04-11 14:50:26 EDT
When "Push to Gerrit" command is used but instead of the Gerrit URI, the GIT is selected, the branch called "refs/for/master" is created in the remote repository and all pushes to Gerrit stop working.
Comment 1 Matthias Sohn CLA 2016-04-11 16:44:26 EDT
I think this should be prevented on server side by installing a pre-receive hook,
this way also pushes from other git implementations to this magic ref will be rejected

Contact webmaster@eclipse.org if you want this for a git repository hosted at Eclipse

the hook may look like (completely untested):

#! /bin/sh
# reject push to Gerrit magic refs "refs/for/<branch name>" which is not
# understood by plain git
while read old new longref; do
    case $longref in
    refs/for/*)
        echo "push to $longref rejected
        You pushed to a plain bare git repository using a Gerrit magic ref
        which isn't supported by plain git
        Push to https://git.eclipse.org/r if you want to use Gerrit Code Review at Eclipse"
        exit 1
    esac
done

for details about pre-receive hooks see section "pre-receive" in [1]

[1] https://git-scm.com/docs/githooks
Comment 2 Sergey Prigogin CLA 2016-04-11 16:49:04 EDT
Why doesn't EGit check that the server used for "Push to Gerrit" is in fact Gerrit?
Comment 3 Matthias Sohn CLA 2016-04-11 18:30:42 EDT
Currently we only check if the server is a Gerrit server when cloning a repository to avoid sending additional requests to the server. When the user cloned using EGit it should auto-detect if the server is a gerrit server and configure the clone correctly so that push to gerrit again goes to Gerrit.

From there in order to push to git (and not Gerrit) the user has to manually change the git config of the clone. Why would a user want to do that ?

Maybe I miss some use case ...
Comment 4 Sergey Prigogin CLA 2016-04-11 18:43:52 EDT
(In reply to Matthias Sohn from comment #3)

The repository was cloned from Git, not Gerrit. Gerrit URI was added later. EGit should be able to determine that the Git server was not Gerrit when cloning from it, shouldn't it?
Comment 5 Matthias Sohn CLA 2016-04-12 02:39:26 EDT
yes

This explains why it didn't work like you expected:

- when cloning a repository EGit checks if the server is Gerrit
- if yes it configures EGit for Gerrit by setting the option gerrit.createchangeid = true in .git/config
- though it does not persist the server's URL

If we would in addition also persist the Gerrit URL we could detect that the user
pushes to refs/for using a URL which we don't know yet. Then we could again check if this new URL is also a Gerrit server (a project could use multiple Gerrit instances like we do e.g. for our internal fork of Gerrit). If not we could reject push to refs/for or at least raise a warning
Comment 6 Eclipse Genie CLA 2016-04-17 18:29:00 EDT
New Gerrit change created: https://git.eclipse.org/r/70827
Comment 7 Eclipse Genie CLA 2016-04-25 04:47:10 EDT
Gerrit change https://git.eclipse.org/r/70827 was merged to [master].
Commit: http://git.eclipse.org/c/egit/egit.git/commit/?id=34b9ae2577af951a0d2b683229501fafa24e2b08
Comment 8 Matthias Sohn CLA 2016-04-25 04:57:43 EDT
(In reply to Eclipse Genie from comment #7)
> Gerrit change https://git.eclipse.org/r/70827 was merged to [master].
> Commit:
> http://git.eclipse.org/c/egit/egit.git/commit/
> ?id=34b9ae2577af951a0d2b683229501fafa24e2b08

With this change submitted EGit will only push URLs in the "Push to Gerrit" command which are configured to use one of the Gerrit magic refs. So the plain Git URL from
your example should no longer be shown in this wizard.

You can try this using latest nightly build from
http://download.eclipse.org/egit/updates-nightly
Comment 9 Dani Megert CLA 2016-05-10 10:59:58 EDT
Please see possible regression bug 493352.
Comment 10 Markus Keller CLA 2016-09-13 10:02:19 EDT
> Please see possible regression bug 493352.

And more damage in bug 501102.