Unpushed commits on remote changes #557

Closed
rejeep opened this Issue Feb 18, 2013 · 34 comments

Projects

None yet

5 participants

@rejeep
rejeep commented Feb 18, 2013

Hey,

Since I updated Magit a few days ago I've noticed something rather strange. If I pull a remote branch (with changes), the changes are listed under "Unpushed commits".

If I push them, they disappear. They also disappear if I pull in a terminal.

Anyone else noticed this?

@rejeep
rejeep commented Feb 18, 2013

Also noticed that pulling (F F) does not fetch any new remote branches.

@aaa707
Contributor
aaa707 commented Feb 19, 2013

I think it caused by b453ce5 change.
I don't know 'git pull' well, but

$ git --no-pager pull -v origin refs/heads/master:master

does not work.

$ git --no-pager pull -v origin refs/heads/master:refs/remotes/origin/master

does work.
Here is simple diff. I don't know this is correct.

diff --git a/magit.el b/magit.el
index d3d23cc..b6d3bdb 100644
--- a/magit.el
+++ b/magit.el
@@ -4396,7 +4396,8 @@ If there is no default remote, ask for one."
          (merge-branch (or (and (not current-prefix-arg)
                                 config-branch)
                            (magit-read-remote-branch
-                            pull-remote (format "Pull branch from remote %s" pull-remote)))))
+                            pull-remote (format "Pull branch from remote %s" pull-remote))))
+         (destination (format "refs/remotes/%s/%s" branch-remote branch)))
     (when (and branch (not config-branch))
       (magit-set branch-remote "branch" branch "remote")
       (magit-set (format "refs/heads/%s" merge-branch)
@@ -4406,7 +4407,7 @@ If there is no default remote, ask for one."
             magit-custom-options
             (list pull-remote)
             (when merge-branch
-               (list (format "%s:%s" merge-branch branch)))))))
+               (list (format "%s:%s" merge-branch destination)))))))

 (eval-when-compile (require 'eshell))
@yyr
yyr commented Feb 19, 2013

lately I have problems with merge as well, did any one notice that.

@dudebout
Member

@aaa707, what system are you using? OS, emacs version, and git version?
I am on Debian unstable, emacs 24.2.1, and git 1.7.10.4 and $ git --no-pager pull -v origin refs/heads/master:master works.

@dudebout
Member

@rejeep, what do you mean by "does not fetch any new remote branches"?

@rejeep
rejeep commented Feb 19, 2013

@dudebout I got a pull request so I did a "fetch all" to be able to checkout the remote branch. But the branch was not fetched, so I had to manually fetch it in the terminal.

@dudebout
Member

@rejeep, But fetch all is on (f a) right?

@rejeep
rejeep commented Feb 19, 2013

@dudebout Yes, sorry if I was unclear

@dudebout
Member

So you are saying that f a did not work in your case?
We might want to split the issues then.
Because f a uses git remote whereas F F uses git pull.

@rejeep
rejeep commented Feb 19, 2013

No, it did not fetch the new (pull request) branch.

@dudebout
Member

I am sorry but I am getting confused. I do not understand what command you ran and what happen/did not happen.

@rejeep
rejeep commented Feb 19, 2013

Allright, let's focus on the original issue, which is the "unpushed commits" and I'll open a new issue for the fetch issue. Do you have any questions regarding the "unpushed commits" issue?

@dudebout
Member

OK thanks.
I think I have seen it too, but I am not sure where to start.

@dudebout
Member

@yyr and @aaa707 please open separate issues for your problem as it is not clear they are related. Thanks

@rejeep
rejeep commented Feb 19, 2013

The fetch issue: #558

@yyr
yyr commented Feb 19, 2013

@dudebout Thanks, I will open, after I narrowed it down..

@aaa707
Contributor
aaa707 commented Feb 20, 2013

The versions are git version 1.7.12.4 (Apple Git-37), GNU Emacs 24.2.1, also Ubuntu is same behavior.

I think

$ git --no-pager pull -v origin refs/heads/master:master

executes

$ git --no-pager pull -v origin refs/heads/master:refs/heads/master

according to refname rule (you can see git help rev-parse).
And these commands say some warnings.

Warning: fetch updated the current branch head.
Warning: fast-forwarding your working tree from
Warning: commit 40a1027....

So we have to indicate remote ref like this.

$ git --no-pager pull -v origin refs/heads/master:refs/remotes/origin/master

But my change may does not work fine if remote branch and local branch are different.

@dudebout
Member

@aaa707 you are right.
There is an inherent asymmetry between push and pull.

$ git --no-pager push -v origin master:refs/heads/master will be translated $ git --no-pager push -v origin refs/headsmaster:refs/heads/master which is the desired behavior.

However, $ git --no-pager pull -v origin refs/heads/master:master will similarly be translated to $ git --no-pager pull -v origin refs/headsmaster:refs/heads/master which is not the desired behavior. We want $ git --no-pager pull -v origin refs/headsmaster:refs/remotes/origin/master.

This explained the unpushed commit problem that @rejeep is seeing.

@sigma sigma added a commit that referenced this issue Feb 22, 2013
@dudebout @sigma dudebout + sigma Fixes the incorrect pull refspec.
This fixes issue #557.
85db584
@bradwright
Contributor

This is still an issue for me with the above commit.

@dudebout
Member

What is still an issue?

@bradwright
Contributor

Make a commit, do the Magit equivalent of git pull --rebase (F, F with rebase=true in my gitconfig), push (P, P).

Commits still sit in the "unpushed commits" section until I pull again.

@dudebout
Member

Does this work? dudebout/magit@842bd55

@dudebout
Member

@bradleywright you can find that change in #566

@dudebout
Member

@yyr Does #566 fix your problem? If not please open a new issue.
@rejeep If this issue is resolved please close it.

@sigma sigma added a commit that referenced this issue Feb 22, 2013
@dudebout @sigma dudebout + sigma Adds refs/remotes as it seems to be necessary for git pull
This fixes issue #557.
1635c0c
@aaa707
Contributor
aaa707 commented Feb 26, 2013

If local branch name and remote branch name are different, it does not work fine.

e.g.

remote: test
local: test

magit-pull executes

$ git --no-pager pull -v origin refs/heads/test:refs/remotes/origin/test

This work.

remote: test
local: origin-test

magit-pull executes

$ git --no-pager pull -v origin refs/heads/test:refs/remotes/origin/origin-test

This doesn't.
magit-pull should execute

$ git --no-pager pull -v origin refs/heads/test:refs/remotes/origin/test

even if local and remote branches are different.
But I can't extract remote branch name easily.
Any ideas?

@dudebout
Member

@aaa707 You are right. I started fixing the issue and realized magit-pull was a tangled mess. I am almost done rewriting it in a clean understandable way. Thank you for your very relevant comments.

@dudebout
Member

@aaa707 can you take a look at this last pull request. The code should be clearer and the behavior as expected. I have changed the approach slightly. I do not use the colon notation anymore as it does not buy us anything. Instead I do git --no-page pull -v origin test.

@aaa707
Contributor
aaa707 commented Feb 27, 2013

Using prefix is nice idea.
But I think

$ git --no-page pull -v origin test

executes

$ git --no-pager pull -v origin refs/heads/test:refs/heads/test

This is revert back and does not work fine.

@dudebout
Member

It was a concern of mine.
However, I am almost positive that it executes:
$ git --no-pager pull -v origin refs/heads/test:FETCH_HEAD

See for proof the following run:

$ git --no-pager pull -v origin test
remote: Counting objects: 4, done.        
Unpacking objects: 100% (3/3), done.
From /home/ddb/magit-testing/repo
 * branch            test       -> FETCH_HEAD
Updating 8990710..1df7fc8
Fast-forward
 d |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 d
git finished.

Furthermore, I tried it on a repository with the structure you described:

  • local: origin-test
  • remote: test

And git pull origin test does not create a local repository named test.

@aaa707
Contributor
aaa707 commented Feb 28, 2013

Hi @dudebout,

In my enviroment, I call manually like this

$ git --no-pager pull -v origin test
remote: Counting objects: 5, done.        
remote: Total 3 (delta 0), reused 0 (delta 0)        
Unpacking objects: 100% (3/3), done.
From /home/aaa707/t
 * branch            test       -> FETCH_HEAD
Updating ead55aa..d4428be
Fast-forward
 a |    1 +
 1 file changed, 1 insertion(+)

after this call magit buffer shows

Unpushed commits:
d4428be * a

and it does not pull anything.

@dudebout
Member

Perfect. This is the exact behavior intended by the command. It did the pull command. However, it did not store the information retrieved from the remote in the local copy of the remote (refs/remotes/origin/test). It used FETCH_HEAD instead to store the information temporarily. It then did the merge.

Now, when comparing refs/heads/test and refs/remotes/origin/test, it looks like the local branch is ahead.

I will therefore revert to the more explicit colon notation to specify the fetch action. See the updated pull request

@aaa707
Contributor
aaa707 commented Mar 3, 2013

It works fine.
Thank you @dudebout.

@dudebout
Member
dudebout commented Mar 4, 2013

@rejeep consider closing the issue if everything is resolved on your part.

@rejeep
rejeep commented Mar 4, 2013

Works great, thanks!

@rejeep rejeep closed this Mar 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment