diff --git a/cli/Makefile b/cli/Makefile index 29e0b369740e7..8d0baa2e0d631 100644 --- a/cli/Makefile +++ b/cli/Makefile @@ -1,6 +1,7 @@ PWD := $(shell pwd) PARENT_DIR := $(shell dirname $(PWD)) VERSION ?= $(shell ../scripts/get-version.sh) +PLUGINS_BRANCH ?= master OS ?= linux darwin windows OUTPUT_DIR := _output @@ -27,7 +28,7 @@ endif .PHONY: build build: export CGO_ENABLED=0 build: - gox -ldflags '-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION) -s -w -extldflags "-static"' \ + gox -ldflags '-X github.com/hasura/graphql-engine/cli/version.BuildVersion=$(VERSION) -X github.com/hasura/graphql-engine/cli/plugins.IndexBranchRef=$(PLUGINS_BRANCH) -s -w -extldflags "-static"' \ -rebuild \ -os="$(OS)" \ -arch="amd64" \ diff --git a/cli/plugins/plugins.go b/cli/plugins/plugins.go index e268751908acd..409929e5dc76d 100644 --- a/cli/plugins/plugins.go +++ b/cli/plugins/plugins.go @@ -30,6 +30,9 @@ var ( ErrVersionNotAvailable = errors.New("plugin version is not available") ) +// IndexBranchRef - branch to be used for index +var IndexBranchRef = "master" + const ( indexURI string = "https://github.com/hasura/cli-plugins-index.git" ) @@ -56,7 +59,7 @@ func New(base string) *Config { p := paths.NewPaths(base) return &Config{ Paths: p, - Repo: util.NewGitUtil(indexURI, p.IndexPath(), "multiple-version"), + Repo: util.NewGitUtil(indexURI, p.IndexPath(), IndexBranchRef), } } diff --git a/cli/util/git.go b/cli/util/git.go index 338642e778f17..c805db8ca91ab 100644 --- a/cli/util/git.go +++ b/cli/util/git.go @@ -5,6 +5,7 @@ import ( "path/filepath" "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/config" "gopkg.in/src-d/go-git.v4/plumbing" ) @@ -77,7 +78,9 @@ func (g *GitUtil) updateAndCleanUntracked() error { if err != nil { return err } - err = repo.Fetch(&git.FetchOptions{}) + err = repo.Fetch(&git.FetchOptions{ + RefSpecs: []config.RefSpec{"refs/*:refs/*"}, + }) if err != nil && err != git.NoErrAlreadyUpToDate { return err } @@ -85,13 +88,20 @@ func (g *GitUtil) updateAndCleanUntracked() error { if err != nil { return err } - err = wt.Pull(&git.PullOptions{}) + err = wt.Checkout(&git.CheckoutOptions{ + Branch: g.ReferenceName, + }) + if err != nil { + return err + } + err = wt.Pull(&git.PullOptions{ + ReferenceName: g.ReferenceName, + }) if err != nil && err != git.NoErrAlreadyUpToDate { return err } err = wt.Reset(&git.ResetOptions{ - Commit: plumbing.ZeroHash, - Mode: git.HardReset, + Mode: git.HardReset, }) if err != nil { return err