From fe5237d09db9a4b8f37b7f1c2040d28fe8a0ceff Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 25 Dec 2017 19:19:01 -0800 Subject: [PATCH 1/2] Actually update instead of failing silently and merging --- .gitignore | 1 + glide.lock | 7 ++++--- glide.yaml | 3 ++- vendor/github.com/Masterminds/vcs/git.go | 25 +++++++++++++++++------- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 2bd0e515..9210b998 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ glide.exe dist/ .DS_Store .idea +*.sw[po] diff --git a/glide.lock b/glide.lock index 430edf9d..cbd47fd9 100644 --- a/glide.lock +++ b/glide.lock @@ -1,12 +1,13 @@ -hash: 1f13d16b2759f4c698bf1fa66a55ef06a42ba86859153c478f903e60502a1273 -updated: 2017-10-04T10:27:41.570512797-04:00 +hash: f0323666f16ae33bf7a84e9c69919d8ee27bfb1e873bdbf826b03ddecb734e49 +updated: 2017-12-25T18:38:31.670159745-08:00 imports: - name: github.com/codegangsta/cli version: cfb38830724cc34fedffe9a2a29fb54fa9169cd1 - name: github.com/Masterminds/semver version: 15d8430ab86497c5c0da827b748823945e1cf1e1 - name: github.com/Masterminds/vcs - version: 6f1c6d150500e452704e9863f68c2559f58616bf + version: 60a10ee61f2fc0c5026cef4ccdd2abd299ce8bba + repo: https://github.com/jaekwon/vcs.git - name: github.com/mitchellh/go-homedir version: b8bc1bf767474819792c23f32d8286a45736f1c6 - name: gopkg.in/yaml.v2 diff --git a/glide.yaml b/glide.yaml index 5b6c0790..b5901abd 100644 --- a/glide.yaml +++ b/glide.yaml @@ -11,7 +11,8 @@ owners: import: - package: gopkg.in/yaml.v2 - package: github.com/Masterminds/vcs - version: ^1.12.0 + repo: https://github.com/jaekwon/vcs.git + branch: master - package: github.com/codegangsta/cli version: ^1.16.0 - package: github.com/Masterminds/semver diff --git a/vendor/github.com/Masterminds/vcs/git.go b/vendor/github.com/Masterminds/vcs/git.go index 4094e0d0..89f5dd84 100644 --- a/vendor/github.com/Masterminds/vcs/git.go +++ b/vendor/github.com/Masterminds/vcs/git.go @@ -148,7 +148,7 @@ func (s *GitRepo) Update() error { return nil } - out, err = s.RunFromDir("git", "pull") + out, err = s.RunFromDir("git", "reset", "--hard") if err != nil { return NewRemoteError("Unable to update repository", err, string(out)) } @@ -158,9 +158,20 @@ func (s *GitRepo) Update() error { // UpdateVersion sets the version of a package currently checked out via Git. func (s *GitRepo) UpdateVersion(version string) error { - out, err := s.RunFromDir("git", "checkout", version) + upstream, err := s.RunFromDir("git", "for-each-ref", "--format='%(upstream:short)'", version) if err != nil { - return NewLocalError("Unable to update checked out version", err, string(out)) + return NewLocalError("Unable to track upstream", err, "") + } + if len(upstream) == 0 { + out, err := s.RunFromDir("git", "reset", "--hard", version) + if err != nil { + return NewLocalError("Unable to update checked out version", err, string(out)) + } + } else { + out, err := s.RunFromDir("git", "reset", "--hard", string(upstream)) + if err != nil { + return NewLocalError("Unable to update checked out version", err, string(out)) + } } return s.defendAgainstSubmodules() @@ -366,7 +377,7 @@ func (s *GitRepo) Ping() bool { // EscapePathSeparator escapes the path separator by replacing it with several. // Note: this is harmless on Unix, and needed on Windows. -func EscapePathSeparator(path string) (string) { +func EscapePathSeparator(path string) string { switch runtime.GOOS { case `windows`: // On Windows, triple all path separators. @@ -379,7 +390,7 @@ func EscapePathSeparator(path string) (string) { // used with --prefix, like this: --prefix=C:\foo\bar\ -> --prefix=C:\\\foo\\\bar\\\ return strings.Replace(path, string(os.PathSeparator), - string(os.PathSeparator) + string(os.PathSeparator) + string(os.PathSeparator), + string(os.PathSeparator)+string(os.PathSeparator)+string(os.PathSeparator), -1) default: return path @@ -404,7 +415,7 @@ func (s *GitRepo) ExportDir(dir string) error { return NewLocalError("Unable to create directory", err, "") } - path = EscapePathSeparator( dir ) + path = EscapePathSeparator(dir) out, err := s.RunFromDir("git", "checkout-index", "-f", "-a", "--prefix="+path) s.log(out) if err != nil { @@ -412,7 +423,7 @@ func (s *GitRepo) ExportDir(dir string) error { } // and now, the horror of submodules - path = EscapePathSeparator( dir + "$path" + string(os.PathSeparator) ) + path = EscapePathSeparator(dir + "$path" + string(os.PathSeparator)) out, err = s.RunFromDir("git", "submodule", "foreach", "--recursive", "git checkout-index -f -a --prefix="+path) s.log(out) if err != nil { From e3064beb079d1fb80956db6040d3819acda5450e Mon Sep 17 00:00:00 2001 From: Jae Kwon Date: Mon, 25 Dec 2017 23:10:32 -0800 Subject: [PATCH 2/2] Update vcs dependency w/ UpdateVersion() fix --- glide.lock | 2 +- vendor/github.com/Masterminds/vcs/git.go | 23 ++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/glide.lock b/glide.lock index cbd47fd9..8d589396 100644 --- a/glide.lock +++ b/glide.lock @@ -6,7 +6,7 @@ imports: - name: github.com/Masterminds/semver version: 15d8430ab86497c5c0da827b748823945e1cf1e1 - name: github.com/Masterminds/vcs - version: 60a10ee61f2fc0c5026cef4ccdd2abd299ce8bba + version: 89ac364c7b6b44926d8c59d8c352affd0b959871 repo: https://github.com/jaekwon/vcs.git - name: github.com/mitchellh/go-homedir version: b8bc1bf767474819792c23f32d8286a45736f1c6 diff --git a/vendor/github.com/Masterminds/vcs/git.go b/vendor/github.com/Masterminds/vcs/git.go index 89f5dd84..f07f2ace 100644 --- a/vendor/github.com/Masterminds/vcs/git.go +++ b/vendor/github.com/Masterminds/vcs/git.go @@ -158,22 +158,23 @@ func (s *GitRepo) Update() error { // UpdateVersion sets the version of a package currently checked out via Git. func (s *GitRepo) UpdateVersion(version string) error { - upstream, err := s.RunFromDir("git", "for-each-ref", "--format='%(upstream:short)'", version) + + // If version is a remote branch, prepend s.RemoteLocation (aka "origin") + branches, err := s.Branches() // Remote branches if err != nil { - return NewLocalError("Unable to track upstream", err, "") + return NewLocalError("Unable to query for repo branches", err, "") } - if len(upstream) == 0 { - out, err := s.RunFromDir("git", "reset", "--hard", version) - if err != nil { - return NewLocalError("Unable to update checked out version", err, string(out)) - } - } else { - out, err := s.RunFromDir("git", "reset", "--hard", string(upstream)) - if err != nil { - return NewLocalError("Unable to update checked out version", err, string(out)) + for _, branch := range branches { + if version == branch { + version = s.RemoteLocation + "/" + branch // e.g. "origin/develop" } } + out, err := s.RunFromDir("git", "reset", "--hard", version) + if err != nil { + return NewLocalError("Unable to update checked out version", err, string(out)) + } + return s.defendAgainstSubmodules() }