Masterminds / glide

Package Management for Golang
https://glide.sh
Other
8.15k stars 541 forks source link

Glide update does not update packages to the latest version unless git cache is cleared #592

Open a13xb opened 8 years ago

a13xb commented 8 years ago

Your usage example states:

$ glide up                                # Update to newest versions of the package

However, it doesn't seem to do that at all. If I start with a clean repository with glide.yaml, where none of the packages are constrained, and a matching glide.lock, none of the dependencies are updated, even though upstream has new commits. Repository remains clean.

When (pre-0.12) Glide was still not stripping VCS files, I used to be able to go into venvor tree, checkout a specific version of a single dependency and run glide update, it would update the lock file to pin the dependency at the version I checked out. So I've been left with the impression that all glide update does is transfer the state of your vendor tree into glide.lock, that's it.

Obviously now vendor tree doesn't retain VCS information, I'm not sure what exactly glide update is supposed to do, and how to actually properly update dependencies to the latest version of the upstream.

mattfarina commented 8 years ago

I'm a little confused about something and I think I need some more information to understand what's going on.

The glide.yaml file holds the intent while the glide.lock file holds the specific revisions being pinned to. So, a version for a dependency in the glide.yaml file that's empty, tracks a branch, or has a version range causes Glide to go to the dependency source, pull down any updates, and store them locally. It does that automatically.

There was never the intent for someone to manually checkout a version inside the repo within the vendor/ folder. Glide tells the VCS (such as Git) to go out to the source and fetch updates.

This happens via the github.com/Masterminds/vcs package. For example, with Git it will drop down to git and use commands like git fetch and git pull expecting them to go out.

Is that not happening for you?

a13xb commented 8 years ago

Is that not happening for you?

When I run glide update, yes, it pulls the latest from the upstream VCS into cache, but the versions in the vendor/ workspace are not updated.

Let me clarify again: my glide.yaml is a plain list of dependencies, none of them specify a branch, a tag, a commit, or range of versions, none whatsoever. My expectation was that this will result in glide update always updating the glide.lock to the HEAD of master.

This doesn't seem to be happening. After the update of local cache, my glide.lock does not change, even though there are new commits in some upstream repos.

[INFO]  Replacing existing vendor dependencies
[INFO]  Versions did not change. Skipping glide.lock update.

There was never the intent for someone to manually checkout a version inside the repo within the vendor/ folder. Glide tells the VCS (such as Git) to go out to the source and fetch updates.

Yes, that was my misguided attempt to get a pinned version of a package updated in glide.lock because glide update would not do it otherwise.

mattfarina commented 8 years ago

@a13xb it sounds like there is a problem and one I'm not experiencing.

Can you provide an example project or glide.yaml file? And, can you share your OS/version and Go environment (go env)?

a13xb commented 8 years ago

OSX: 10.11.6 Glide: 0.12.0 (via Homebrew) Go: 1.7 Go environment:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/alex/workspace/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.7/libexec"
GOTOOLDIR="/usr/local/Cellar/go/1.7/libexec/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/73/jds74fnd03q8qkfyx_8zx8400000gn/T/go-build423096790=/tmp/go-build -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

Sample project:

glide.yaml

package: github.com/a13xb/glidetest
import:
- package: github.com/gorilla/mux

glide.lock

hash: be6ffa009beb31b542f3a93c368fa8213aaf2fed7fc7e10914021349fe65ce9f
updated: 2016-08-31T23:38:13.074624366+10:00
imports:
- name: github.com/gorilla/mux
  version: 9fa818a44c2bf1396a17f9d5a3c0f6dd39d2ff8e
testImports: []

Commit 9fa818a in the lock file is from June, actual HEAD of master is 0b13a92.

Running glide update:

[INFO]  Downloading dependencies. Please wait...
[INFO]  --> Fetching updates for github.com/gorilla/mux.
[INFO]  Resolving imports
[INFO]  Downloading dependencies. Please wait...
[INFO]  Setting references for remaining imports
[INFO]  Exporting resolved dependencies...
[INFO]  --> Exporting github.com/gorilla/mux
[INFO]  Replacing existing vendor dependencies
[INFO]  Versions did not change. Skipping glide.lock update.
[INFO]  Project relies on 1 dependencies.
mattfarina commented 8 years ago

Quick question, do you have github.com/gorilla/mux imported in your code? Glide code scans and follows imports found in the code to find the packages to use. If you have this in your glide.yaml file but didn't use it in your code it's dependencies won't be followed.

I setup an example with a file:

package main

import (
    "fmt"

    _ "github.com/gorilla/mux"
)

func main() {
    fmt.Println("test")
}

It fetched the dependencies.

Does this fix your problem?

a13xb commented 8 years ago

I've added this sample Go file and it adds the transitive dependency, so it completes the example, but the problem is still there.

I think it has something to do with cache. How to replicate:

  1. Starting with the empty cache, do a glide update, the dependencies are properly updated, git repos in cache end up checked out at master.
  2. Discard changes to glide.lock file.
  3. Do a glide install, old versions from lock file get installed, cache repos are checked out at the versions in the lock file (detached HEAD).
  4. Do a glide update, update won't happen and the cache stays pointing at the commit in the lock file.
  5. Remove the cache, glide update will update correctly.
karamani commented 8 years ago

+1 I had the same problem.

oschwald commented 8 years ago

I had a similar issue. Removing the cache fixed it for me.

vuleetu commented 7 years ago

Same here. Seems like Glide does not switch to the latest version before export to vendor.

KatelynHaworth commented 7 years ago

:+1: This also seems to affect me.

Go Version: go version go1.6.2 linux/amd64 Glide Version: glide version v0.12.3 Go Environment:

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/liam/.golib"
GORACE=""
GOROOT="/usr/lib/go-1.6"
GOTOOLDIR="/usr/lib/go-1.6/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"
jmazzitelli commented 7 years ago

I confirm this is happening to me too. I was wondering if I was doing something wrong, until I read this issue :) I even removed the entry of my dep from the glide.lock file (my dep is on github), ran update again, saw that the .lock file put the dep back, but vendor/ is still the old version and the entry in the .lock file is still the old hash. I want to pull the lastest from master branch, but it isn't setting my dep to the latest hash - the lock file is showing the git hash from the first time I pulled the dep via glide. Workaround: "rm -rf ~/.glide/cache/src/my-dep-directory" then run glide update.

adangert commented 7 years ago

same problem I was having "rm -rf ~/.glide/cache/" worked for me, glide.lock was not updating to the latest commit hash regardless of doing a glide update

sdboyer commented 7 years ago

i'm pretty sure the answer is "no," but just to be sure: have any of you who are experiencing this bug done any direct manipulation of the ~/.glide/cache dir?

also, if anyone is able to create some exact steps to reproduce, it would be tremendously helpful in solving this problem.

jmazzitelli commented 7 years ago

@sdboyer the answer for me is "no" - in fact, I didn't even know this cache existed let alone where it was until I researched this issue and found someone said "clear you cache" and I had to go hunt for what this cache even was :)

jmazzitelli commented 7 years ago

@sdboyer

if anyone is able to create some exact steps to reproduce, it would be tremendously helpful in solving this problem.

I just ran through a set of replication steps for you to try.

FYI, my versions are as follows: $ glide -v ; git version ; go version glide version v0.12.3 git version 2.5.5 go version go1.7.1 linux/amd64

1: Clone this repo and make it your GOPATH: https://github.com/hawkular/hawkular-openshift-agent

2: Make sure glide is in your path obviously (to do this, I run "make install_glide" from the root GOPATH directory - there is a Makefile in there - and glide goes in my GOPATH/bin that I then run)

3: cd src/github.com/hawkular/hawkular-openshift-agent/ (you will find the glide yaml and lock files here)

4: Run "glide update" - notice this:

--> Fetching github.com/hawkular/hawkular-client-go.

5: See that you have the latest code for that dependency (hawkular-client-go) in vendor directory by grepping for "Username" - this was a new field added in the latest PR merge and is now in the HEAD of master branch:

$ grep Username vendor/github.com/hawkular/hawkular-client-go/metrics/types.go 
    Username    string

6: edit the glide.yaml and add a "ref" so that dependency gets locked on a new hash (this hash is the one before the latest PR merge and did NOT have that "Username string" field) - so add the two lines "vcs" and "ref" below under the hawkular-client-go package dependency:

- package: github.com/hawkular/hawkular-client-go
  vcs: git
  ref: d3a0e3ccb068e354fc61c5811a24414792e6159b

7: Run "glide update" - notice this:

--> Setting version for github.com/hawkular/hawkular-client-go to d3a0e3ccb068e354fc61c5811a24414792e6159b.

8: Run the grep again, and notice the Username is missing (this is correct, it means glide updated the dependency source under vendor properly)

$ grep Username vendor/github.com/hawkular/hawkular-client-go/metrics/types.go 
(...no output here - which is what you want...)

9: Now go back to glide.yaml, remove that "vcs" and "ref" that you added in step 6 thus bringing back your dependency to the master head.

10: Run "glide update" - notice this:

--> Fetching github.com/hawkular/hawkular-client-go.

11: Now, you are back to where we were (or we should be) - the latest code of master HEAD that has the new Username field in the dependency code. But run that grep command and see that it is missing under vendor directory:

$ grep Username vendor/github.com/hawkular/hawkular-client-go/metrics/types.go 
(...no output here - which is NOT what you want... we should be back on master and this Username field should exist)

12: To confirm the cache is now bad, go to it and look at what is checked out of git:

$ cd ~/.glide/cache/src/https-github.com-hawkular-hawkular-client-go
$ git rev-parse HEAD
d3a0e3ccb068e354fc61c5811a24414792e6159b

That is NOT the git hash of the latest master. That's the git hash we put in in step 6. But we want master, which currently is:

$ git rev-parse origin/master
4f5da7e951592445b686f95a0acdb0f860095d70

So when I removed the ref: from the yaml file and I "glide update", it never pulled the HEAD from master - the cache stayed on the old hash that I pulled before and thus my vendor/ never updated.

Hope this helps.

sdboyer commented 7 years ago

@jmazzitelli 👼 👼 ✨ 💖 🎉

i won't have time to actually run these through until later today or tomorrow, but these kinds of reproducibility procedures are like manna from heaven.

jmazzitelli commented 7 years ago

@sdboyer - any word on this? Did my replication procedures yield any clues as to the problem and potential fix?

sdboyer commented 7 years ago

sorry, i've had a ridiculous couple weeks, and just totally forgot about this 😞 i'll look today

jmazzitelli commented 7 years ago

@sdboyer those replicate steps might be slightly different - I just committed a change to that repo that changes the project structure to be more like a "normal" golang project. Just follow the README.adoc to install it (it should now be more as you would expect anyway). Its not really different, I just move the src/ files up to the top directory rather than committing the files under the src/github.com.... directory structure.

sdboyer commented 7 years ago

4: Run "glide update"

This is hitting another, i guess different issue:

[ERROR] Error scanning k8s.io/client-go/1.4/kubernetes: open /Users/sdboyer/.glide/cache/src/https-k8s.io-client-go/1.4/kubernetes: no such file or directory

it went away when I glide install'd, after which i could glide update successfully. I'll have to investigate this later, too...

12: To confirm the cache is now bad, go to it and look at what is checked out of git:

Yep, I figured the issue would be something like this. The git commands glide is issuing to get information from the repo aren't working correctly because they're using porcelain commands that have subtle dependencies on local repo state. Specifically, git pull doesn't do anything unless you have the right local branch checked out, and it's set up to track the right remote branch.

I need to track down where the actual calls are in the code to fix this up, but it shouldn't be too terrible to deal with.

Also, just a note for the future - the cache having a particular version checked out in the working directory isn't necessarily an indication that it's "bad". The technique we use to quickly get files onto disk under vendor/ is not copying what's checked out, but rather doing some under-the-hood git goodness to perform that process quickly. Right now, it's probably an accurate indicator, but in the future the working directory may be something totally different, but you'll still have the right thing in your vendor/.

jmazzitelli commented 7 years ago

Also, just a note for the future - the cache having a particular version checked out in the working directory isn't necessarily an indication that it's "bad"

This is why I have step 11 in my replication procedure. I actually do look in /vendor to see that the code is "bad" there.

stevenroose commented 7 years ago

I have the same issue. I track a package as a fork I made and when I push updates to the fork, glide update does not make the lock file update to the latest version of the fork. Also worked after cleaning the cache.

sdboyer commented 7 years ago

So, the fix over in #703 should address this. The only note to make is that you have to specify the branch you want to follow in glide.yaml - it won't move properly if you don't. (Yeah, I'm not happy about that either).

I've verified this against @jmazzitelli's replication procedure, but if someone else could try with that PR, that'd be awesome.

jmazzitelli commented 7 years ago

@sdboyer I just tried it using your PR branch and it still failed. But maybe I'm not doing it right. What do you mean "you have to specify the branch you want to follow in glide.yaml". I was using:

vcs: git
ref: d3a0e3ccb068e354fc61c5811a24414792e6159b

So I'm giving a hash reference, not an actual branch name. Is that not correct anymore?

And what about tags? Can you use tag names rather than branch names?

franciscocpg commented 7 years ago

@jmazzitelli I think this would be

vcs: git
version: d3a0e3ccb068e354fc61c5811a24414792e6159b

https://github.com/Masterminds/glide/blob/master/docs/glide.yaml.md

jmazzitelli commented 7 years ago

OK, I got it to work. The missing link is that YOU MUST specify "ref: master" when switching back.

If you just delete the ref: line, it will not work.

I tried with both version: and ref: and it all works but, again, it only worked IF YOU SPECIFY the master branch when you go back.

So these worked:

This was the commit that has the missing "Username" (see my replication procedures for what I mean about the "Username" field):

version: d3a0e3ccb068e354fc61c5811a24414792e6159b

or

ref: d3a0e3ccb068e354fc61c5811a24414792e6159b

Master has "Username":

version: master

or

ref: master
sdboyer commented 7 years ago

I tried with both version: and ref: and it all works but, again, it only worked IF YOU SPECIFY the master branch when you go back.

Righto, this is what I meant by:

the only note to make is that you have to specify the branch you want to follow in glide.yaml - it won't move properly if you don't.

ref is deprecated, please don't use that at all. (It will stop working entirely under gps, anyway)

cep21 commented 7 years ago

Just to clarify, if I want to get the latest code when I run glide up I need to change my yaml to have version: master on every package like:

import:
- package: a
  version: master
- pacakge: b
  version: master
- package: c
  version master
- package: d
  version master

?

This seems like it should be the default. Maybe it's worth documenting that it's not.

jmazzitelli commented 7 years ago

@cep21 it is the default, the problem comes when you switch to another branch, and then want to go back to master (as you do when you are working in development and you want to pick up a bug fix in some package that hasn't been merged to master yet, then when it is fixed in master, you want to go back to master).. See my replication procedures above for what steps cause the problem.

sdboyer commented 7 years ago

The more I think about this, the more I think I need to go back in and see if I can make this work without having to specify the branch name. It's absolutely not acceptable that there would be two different outcomes to glide update depending solely on the state of the cache dir; in effect, that's changing the semantics of glide.yaml.

metral commented 7 years ago

@sdboyer Are there any updates to this issue that you can shine a light on? Thanks!

metral commented 7 years ago

To provide a bit more insight into my experience:

I'm hitting this issue in v0.12.3, so I don't even have an alternate branch in my package to switch to that could be causing the issue. Running glide up -v with packages that are set to pull master as the version are reverting back to the older versions stored in the glide cache. It isn't until I clear the cache that the latest commits are able to be acknowledged.

Case in point: I have a package foobar with commits A, B, C, D, where D is the most current commit in master and what glide previously set as the version the last time I updated - so far so good as this is what it should be set to. Some time later, I decide to run glide up -v again to update other packages, and is when I noticed that foobar's latest commit D reverted back to the older commit A for no good reason. Clearing the cache and rerunning glide was the only solution to update the rest of my packages without it affecting foobar as I've just described. This does not happen all of the time but rather seems to be some sort of flake.

I've had to resort to clearing the cache before I run any update to reliably keep my packages up-to-date.

XANi commented 7 years ago

got same issue. In my case setting version of package to origin/master was enough to "fix" it, but it was really confusing to debug it.

Also for some insane reason it puts cached deps that I commented out of glide.yaml and removed glide.lock into vendor dir. Deps are in imports but I commented it out because I wanted to use GOPATH version of them.

Aside of that, if force push was applied to upstream repo, glide cache goes to hell... looks like it did pull then got into merge, instead of doing git fetch and then git checkout on required object (probably because I told it to get master)

calvn commented 7 years ago

I also encountered the same issue, and glide cc to clear the cache seemed to have resolved it. It seems that if the repository is cached, glide up won't update from remote, even if there is a newer commit.

raven-chen commented 7 years ago

Have the same issue too. It takes me hours to figure out why my fix in other packages not work. just because it was not updated by glide... Although glide cc && glide up fixed it, still not a good experience.

tabacco commented 7 years ago

As a new user to glide, I was very confused by this until I found this issue and tried a glide cc. So, I guess that's a +1 from me as well.

stevenh commented 7 years ago

glide cc didn't fix it here I still have loads of changes in glide.lock which are not present in glide.yaml as a new user I may be missing something?

XANi commented 7 years ago

change version to origin/master and do glide update

Tri125 commented 7 years ago

New user to glide and same issue. glide cc didn't help.

metral commented 7 years ago

Fwiw I worked around this issue by reverting back to v0.11.1 https://github.com/Masterminds/glide/releases/tag/v0.11.1

sjmc7 commented 7 years ago

I also see this with glide v0.13; i've been in the habit of manually deleting the cached checkout of a dependency before updating.

jmcfarlane commented 7 years ago

The behavior suggests that glide is using the latest tag if no version is specified in glide.yaml. My observation is that most folks either want a tag or a branch (likely master) specified as the version. If this observation happens to be true, I personally recommend glide use master as the version when it's not specified, versus the latest tag.

But to be clear, I might be completely confused here :)

XANi commented 7 years ago

@jmcfarlane I had to use origin/master to actually force it to update on glide update. Leaving it on master made it update once to latest (when cache was empty) and then never do it again

G-Harmon commented 6 years ago

I think I hit this as well.

glide update; go build ./... ==> build failed because k8s.io/api was not update rm -rf ~/.glide/cache/; glide update; go build ./... ==> build succeeded

mattfarina commented 6 years ago

@G-Harmon Can you run glide --debug update. I'm curious what happened?

jaekwon commented 6 years ago

If a glide dependency ever gets --force updated, VcsVersion() will silently fail upon Update() and UpdateVersion(ver) which merges anything that already exists for that local branch. Update() definitely shouldn't call git pull, and UpdateVersion() should probably do more than just git checkout. This causes the dependency to get pinned to the wrong version, after an unwanted merge. (assuming that glide.yaml has a dependency set to a branch).

See https://github.com/Masterminds/glide/pull/961

G-Harmon commented 6 years ago

Hi @mattfarina, are you asking for debug output on the faulty update or the successful one? I assume the faulty one, but I'm not quite sure what it takes to get into that state. I normally only run glide update once in awhile.

mattfarina commented 6 years ago

Faulty one

wellsjo commented 6 years ago

Any updates here? This is still an issue...

G-Harmon commented 6 years ago

Hey @wellsjo, I haven't had a time to repro and provide debug data. Can you?