Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Different behavior on Fetch and Pull #470

Closed
calvn opened this issue Jul 10, 2017 · 5 comments
Closed

Different behavior on Fetch and Pull #470

calvn opened this issue Jul 10, 2017 · 5 comments
Labels

Comments

@calvn
Copy link

calvn commented Jul 10, 2017

I am getting different error behavior on Fetch() and Pull() for a fresh repository that I have created. The repository has one initial commit, and two branches, both on the same commit. The repository object is created via PlainClone().

$ mkdir -p test-repo && cd test-repo
$ git init .
$ echo $(date) > test
$ git add . && git commit -am "Initial commit"
$ git checkout -b "test"
...
	// This returns git.NoErrAlreadyUpToDate
        err := repo.Fetch(&git.FetchOptions{
		RefSpecs: []gconfig.RefSpec{"+refs/heads/master:refs/remotes/origin/master", "+refs/heads/test:refs/remotes/origin/test"},
	})
	if err == git.NoErrAlreadyUpToDate {
		fmt.Println("No changes detected on fetch")
		return nil
	} else if err != nil {
		return err
	}

	// This returns nil
	err := repo.Pull(&git.PullOptions{
		RemoteName:    "origin",
		ReferenceName: refName, // This is either refs/heads/master or refs/heads/test
	})
	if err == git.NoErrAlreadyUpToDate {
		fmt.Println("No changes detected on pull")
		return nil
	} else if err != nil {
		return err
	}
...
@calvn
Copy link
Author

calvn commented Jul 10, 2017

It seems that the source of the problem is in https://github.com/src-d/go-git/blob/v4/repository.go#L605

The fetch() call in https://github.com/src-d/go-git/blob/v4/repository.go#L582 returns NoErrAlreadyUpToDate , but then updated gets changed to true back when r. updateReferences() is called.

@calvn
Copy link
Author

calvn commented Jul 10, 2017

I think I know what's going on. Pull() operation updates the HEAD ref, which is seen as a change so that's why it returns nil instead of NoErrAlreadyUpToDate .

When pulling master:

ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/test
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/test
ref: ref: refs/heads/test HEAD
Pulling...
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/test
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/test
ref: ref: refs/heads/master HEAD

When pulling test:

ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/test
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/test
ref: ref: refs/heads/master HEAD
Pulling...
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/heads/test
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/master
ref: 1411d28d549b70832a10ad146b94a3b1c0f5bbca refs/remotes/origin/test
ref: ref: refs/heads/test HEAD

So this becomes a back and forth cycle that is always treated as an update. I am not sure if native git-pull exhibits that behavior. I believe that HEAD remains unchanged, and FETCH_HEAD is what gets updated.

@calvn
Copy link
Author

calvn commented Jul 10, 2017

#207 (comment) mentions that this is not the expected behavior, but the PR still ended up getting approved.

@smola can you shine some light as to why this is the behavior on go-git, and whether there will be a fix/convergence back to the original git behavior in the future?

@mcuadros
Copy link
Contributor

@calvn we will take a look ASAP.

@calvn
Copy link
Author

calvn commented Aug 3, 2017

This seems to have been resolved the issue I was having, thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants