Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 352381 - push should not push up all local branches to upstream
Summary: push should not push up all local branches to upstream
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 normal with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-07-18 14:41 EDT by Thomas Watson CLA
Modified: 2013-05-03 12:01 EDT (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Watson CLA 2011-07-18 14:41:32 EDT
I am new to eGit but have been using git command line for a while.  I just performed my first push to upstream with eGit and to my surprise it pushed up all my local branches to dev.eclipse.org and even created new branches that did not exist up stream.

I was very surprised by this behavior because I do not think that is how the command line git works.  In my experience it only pushes up the branch you have checked out (if you do a simple "git push" with no other parameters).

From command line I think you need to do something special to even get a new branch created upstream (something like "git push --set-upstream origin <branch_name>").

It seems the default should be to behave more like the command line git here.
Comment 1 Thomas Watson CLA 2011-07-18 14:55:20 EDT
One correction.  "git push" with no parameters will push all branches to upstream that exist upstream, but I don't think it creates new branches upstream that only exist locally.
Comment 2 Remy Suen CLA 2011-07-20 07:09:39 EDT
Root cause being bug 351314?
Comment 3 Stefan Lay CLA 2011-07-28 09:53:06 EDT
Which version of EGit are you using? I suppose that commit c6dd679 of 2011-07-06 has fixed this and the error does not occur in the nightly build, now the currently checked out branch is pushed.

(In reply to comment #2)
> Root cause being bug 351314?
No, I don't think so. This refspec which led to the described behavior that all local branches are created on the remote was created in EGit and passed to the PushCommand (in class PushOperationUI). Bug 351314 describes the behavior that the *currently checked out* branch is pushed when no refspec is given.
Comment 4 Thomas Watson CLA 2011-08-03 09:25:42 EDT
(In reply to comment #3)
> Which version of EGit are you using? I suppose that commit c6dd679 of
> 2011-07-06 has fixed this and the error does not occur in the nightly build,
> now the currently checked out branch is pushed.

I am using EGit version 1.0.0.201106090707-r
Comment 5 Matthias Sohn CLA 2011-08-04 04:26:50 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > Which version of EGit are you using? I suppose that commit c6dd679 of
> > 2011-07-06 has fixed this and the error does not occur in the nightly build,
> > now the currently checked out branch is pushed.
> 
> I am using EGit version 1.0.0.201106090707-r

this fix was submitted after this release, could you retry with current nightly build version from
http://download.eclipse.org/egit/updates-nightly ?
Comment 6 Remy Suen CLA 2011-08-15 19:36:09 EDT
(In reply to comment #0)
> I just
> performed my first push to upstream with eGit and to my surprise it pushed up
> all my local branches to dev.eclipse.org and even created new branches that did
> not exist up stream.

Tom, when you pushed, did you remember what you did? Did you go 'Team > Push to Upstream'? Or did you go 'Team > Remote... > Push' and went through a wizard?
Comment 7 Thomas Watson CLA 2011-08-16 09:22:43 EDT
(In reply to comment #6)
> (In reply to comment #0)
> > I just
> > performed my first push to upstream with eGit and to my surprise it pushed up
> > all my local branches to dev.eclipse.org and even created new branches that did
> > not exist up stream.
> 
> Tom, when you pushed, did you remember what you did? Did you go 'Team > Push to
> Upstream'? Or did you go 'Team > Remote... > Push' and went through a wizard?

IIRC I used 'Team > Push to Upstream'.  I don't see the 'Team > Remote...' option anywhere.
Comment 8 Remy Suen CLA 2011-08-16 09:26:36 EDT
(In reply to comment #7)
> IIRC I used 'Team > Push to Upstream'.  I don't see the 'Team > Remote...'
> option anywhere.

That should actually be 'Team > Remote > Push...' but I guess you don't see that either. You might be seeing a bug with Eclipse 4, if you restart it should show up again.
Comment 9 Thomas Watson CLA 2011-08-16 10:01:58 EDT
(In reply to comment #8)
> (In reply to comment #7)
> > IIRC I used 'Team > Push to Upstream'.  I don't see the 'Team > Remote...'
> > option anywhere.
> 
> That should actually be 'Team > Remote > Push...' but I guess you don't see
> that either. You might be seeing a bug with Eclipse 4, if you restart it should
> show up again.

restart made it show up again.  But looking at that wizard, nothing looks familiar.  I am almost certain I used 'Team > Push to Upstream'.  But this is all confusing to me.  How am I to know the difference between the two?  Why are there two ways to push in the UI.

Remy, is there an Eclipse 4 bug open about the disappearing menu item?
Comment 10 Remy Suen CLA 2011-08-16 10:08:28 EDT
(In reply to comment #9)
> Remy, is there an Eclipse 4 bug open about the disappearing menu item?

I just opened bug 354831 and have already CC'd you on it.
Comment 11 Dominik Schadow CLA 2011-08-19 02:37:50 EDT
I'm using EGit 1.0 (Eclipse 3.7) and trip over the same problem as Thomas Watson (see my question in the forum http://www.eclipse.org/forums/index.php/m/716515/#msg_716515). 

Steps to reproduce:
Clone a repository e.g. from GitHub. Create a local branch (it seems to make no difference whether it is based on a local or a remote branch) and choose Push to upstream (the one with no wizard) to push it. EGit pushes all local branches, even those that are not available remote, to the remote repository. This is different from the command line, as Thomas pointed out. 

The only way to prevent this is to configure push to upstream to only push e.g. local/master to remote/master. 

As Matthias Sohn mentioned in my forum post, the spec (http://kernel.org/pub/software/scm/git/docs/git-push.html) contains the following:

"The special refspec : (or +: to allow non-fast-forward updates) directs git to push "matching" branches: [xxx]for every branch that exists on the local side, the remote side is updated if a branch of the same name already exists on the remote side.[xxx] This is the default operation mode if no explicit refspec is found (that is neither on the command line nor in any Push line of the corresponding remotes file---see below)."

The important part is highlighted with [xxx]. In my eyes, EGit does not implement this correctly.
Comment 12 Stefan Lay CLA 2011-08-19 03:16:21 EDT
(In reply to comment #11)
> EGit pushes all local
> branches, even those that are not available remote, to the remote repository.
> This is different from the command line, as Thomas pointed out. 

This behavior has changed in the meantime. To prevent the users from pushing  all local branches accidentally now for the time being only the currently checked out branch is pushed if no refspec is given (like "git push <repository> HEAD"). (Yes, we have to fix the now wrong message in the Configure Push dialog.)

> The only way to prevent this is to configure push to upstream to only push e.g.
> local/master to remote/master. 

Yes, or HEAD/refs/heads/master if you do not want to merge into master locally each time you push.

> As Matthias Sohn mentioned in my forum post, the spec
> (http://kernel.org/pub/software/scm/git/docs/git-push.html) contains the
> following:
> 
> "The special refspec : (or +: to allow non-fast-forward updates) directs git to
> push "matching" branches: [xxx]for every branch that exists on the local side,
> the remote side is updated if a branch of the same name already exists on the
> remote side.[xxx] This is the default operation mode if no explicit refspec is
> found (that is neither on the command line nor in any Push line of the
> corresponding remotes file---see below)."
> 
> The important part is highlighted with [xxx]. In my eyes, EGit does not
> implement this correctly.

You are absolutely right and you may wonder why EGit does not just implement that behavior. The problem is that the underlying library JGit does not yet support it. 

There is a comment of Shawn Pearce (main author of JGit) about that: "We don't have a way to do the default update-only-if-existing-on-remote-side logic inside of JGit. The Transport code doesn't have a mode to do this matching, and the matching needs to happen only after the advertisement has been received from the remote side." (http://egit.eclipse.org/r/#patch,unified,3808,1,/COMMIT_MSG).

So someone has to dive into the JGit Transport code to fix that.
Comment 13 Stefan Lay CLA 2011-08-19 03:53:22 EDT
See also the posting of Shawn on the JGit mailing list: http://dev.eclipse.org/mhonarc/lists/jgit-dev/msg01227.html
Comment 14 Robin Stocker CLA 2013-05-03 12:01:17 EDT
(In reply to comment #12)
> You are absolutely right and you may wonder why EGit does not just implement
> that behavior. The problem is that the underlying library JGit does not yet
> support it. 

See bug 353405 for that.