From b35b57a14a21c6e38ce2cd06909f6083f25c0437 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Dec 2013 11:23:18 -0500 Subject: [PATCH 1/7] Added git support when package use it as VCS --- cmd/get.go | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++---- gopm.go | 2 +- 2 files changed, 68 insertions(+), 6 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index ec0e81fb4..ec6632b7e 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -166,12 +166,20 @@ func getByPath(ctx *cli.Context) { } func copyToGopath(srcPath, destPath string) { + importPath := strings.TrimPrefix(destPath, installGopath+"/") + if len(getVcsName(destPath)) > 0 { + log.Warn("Package in GOPATH has version control: %s", importPath) + return + } + os.RemoveAll(destPath) err := com.CopyDir(srcPath, destPath) if err != nil { log.Error("download", "Fail to copy to GOPATH:") log.Fatal("", "\t"+err.Error()) } + + log.Log("Package copied to GOPATH: %s", importPath) } // downloadPackages downloads packages with certain commit, @@ -200,7 +208,6 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { if ctx.Bool("gopath") && com.IsExist(installPath) { copyToGopath(installPath, gopathDir) - log.Log("Package copied to GOPATH: %s", n.ImportPath) } continue } else { @@ -253,9 +260,9 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision) } - if ctx.Bool("gopath") && com.IsExist(installPath) { + if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") && + len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 { copyToGopath(installPath, gopathDir) - log.Log("Package copied to GOPATH: %s", n.ImportPath) } } } else { @@ -280,8 +287,18 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { // Mark as donwloaded. downloadCache[nod.RootPath] = true - nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value") - imports, err := doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags) + // Check if only need to use VCS tools. + var imports []string + var err error + gopathDir := path.Join(installGopath, nod.RootPath) + vcs := getVcsName(gopathDir) + if ctx.Bool("update") && ctx.Bool("gopath") && len(vcs) > 0 { + err = updateByVcs(vcs, gopathDir) + imports = doc.GetAllImports([]string{gopathDir}, nod.RootPath, false) + } else { + nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value") + imports, err = doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags) + } if err != nil { log.Error("get", "Fail to download pakage: "+nod.ImportPath) @@ -292,3 +309,48 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { } return nod, imports } + +func getVcsName(dirPath string) string { + switch { + case com.IsExist(path.Join(dirPath, ".git")): + return "git" + case com.IsExist(path.Join(dirPath, ".hg")): + return "hg" + case com.IsExist(path.Join(dirPath, ".svn")): + return "svn" + } + return "" +} + +func updateByVcs(vcs, dirPath string) error { + err := os.Chdir(dirPath) + if err != nil { + log.Error("Update by VCS", "Fail to change work directory:") + log.Fatal("", "\t"+err.Error()) + } + defer os.Chdir(workDir) + + switch vcs { + case "git": + stdout, _, err := com.ExecCmd("git", "status") + if err != nil { + log.Error("", "Error occurs when 'git status'") + log.Error("", "\t"+err.Error()) + } + + i := strings.Index(stdout, "\n") + if i == -1 { + log.Error("", "Empty result for 'git status'") + return nil + } + + branch := strings.TrimPrefix(stdout[:i], "# On branch ") + _, _, err = com.ExecCmd("git", "pull", "origin", branch) + if err != nil { + log.Error("", "Error occurs when 'git pull origin "+branch+"'") + log.Error("", "\t"+err.Error()) + } + + } + return nil +} diff --git a/gopm.go b/gopm.go index 9bf0c7d64..1dace5eb4 100644 --- a/gopm.go +++ b/gopm.go @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.6.0.1210" +const APP_VER = "0.6.0.1211" // //cmd.CmdSearch, // cmdClean, From 23538cf9a696b8c5a8fed3290299bf33910aa392 Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Dec 2013 11:33:17 -0500 Subject: [PATCH 2/7] Added hg support when package use it as VCS --- cmd/get.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/get.go b/cmd/get.go index ec6632b7e..cb20a36f3 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -350,7 +350,24 @@ func updateByVcs(vcs, dirPath string) error { log.Error("", "Error occurs when 'git pull origin "+branch+"'") log.Error("", "\t"+err.Error()) } + case "hg": + stdout, stderr, err := com.ExecCmd("hg", "pull") + if err != nil { + log.Error("", "Error occurs when 'hg pull'") + log.Error("", "\t"+err.Error()) + } + if len(stderr) > 0 { + log.Error("", "Error: "+stderr) + } + stdout, stderr, err = com.ExecCmd("hg", "up") + if err != nil { + log.Error("", "Error occurs when 'hg up'") + log.Error("", "\t"+err.Error()) + } + if len(stderr) > 0 { + log.Error("", "Error: "+stderr) + } } return nil } From 41d20aa9a5236c1a2e8289ad97edd55e289f8b8d Mon Sep 17 00:00:00 2001 From: Unknown Date: Wed, 11 Dec 2013 11:39:11 -0500 Subject: [PATCH 3/7] gofmt --- README.md | 10 +++++----- cmd/get.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a2ea519a1..1360a64d3 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ USAGE: gopm [global options] command [command options] [arguments...] VERSION: - 0.6.0.1209 + 0.6.0.1211 COMMANDS: get fetch remote package(s) and dependencies to local repository @@ -29,11 +29,11 @@ COMMANDS: build link dependencies and go build install link dependencies and go install help, h Shows a list of commands or help for one command - + GLOBAL OPTIONS: - --noterm disable color output - --version, -v print the version - --help, -h show help + --noterm disable color output + --version print the version + --help, -h show help ``` diff --git a/cmd/get.go b/cmd/get.go index cb20a36f3..009fd5049 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -351,7 +351,7 @@ func updateByVcs(vcs, dirPath string) error { log.Error("", "\t"+err.Error()) } case "hg": - stdout, stderr, err := com.ExecCmd("hg", "pull") + _, stderr, err := com.ExecCmd("hg", "pull") if err != nil { log.Error("", "Error occurs when 'hg pull'") log.Error("", "\t"+err.Error()) @@ -360,7 +360,7 @@ func updateByVcs(vcs, dirPath string) error { log.Error("", "Error: "+stderr) } - stdout, stderr, err = com.ExecCmd("hg", "up") + _, stderr, err = com.ExecCmd("hg", "up") if err != nil { log.Error("", "Error occurs when 'hg up'") log.Error("", "\t"+err.Error()) From 61bcb024f6da29dc92103ade330df5dc01c00dd8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 9 Jan 2014 23:35:36 +0800 Subject: [PATCH 4/7] Fixed bug: has revision but still force to check(which never changes) --- cmd/cmd.go | 16 ++--- cmd/gen.go | 10 +-- cmd/get.go | 180 ++++++++++++++++++++++++++++---------------------- doc/struct.go | 9 +-- gopm.go | 15 ++--- 5 files changed, 125 insertions(+), 105 deletions(-) diff --git a/cmd/cmd.go b/cmd/cmd.go index d2bff0c43..a2e608393 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -1,4 +1,4 @@ -// Copyright 2013 gopm authors. +// Copyright 2013-2014 gopm authors. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain @@ -57,24 +57,22 @@ func validPath(info string) (string, string) { l := len(infos) switch { case l == 1: - // for local imports + // For local imports. if com.IsFile(infos[0]) { return doc.LOCAL, infos[0] } - - return doc.BRANCH, "" case l == 2: switch infos[1] { case doc.TRUNK, doc.MASTER, doc.DEFAULT: infos[1] = "" } return infos[0], infos[1] - default: - log.Error("", "Cannot parse dependency version:") - log.Error("", "\t"+info) - log.Help("Try 'gopm help get' to get more information") - return "", "" } + + log.Error("", "Cannot parse dependency version:") + log.Error("", "\t"+info) + log.Help("Try 'gopm help get' to get more information") + return "", "" } func versionSuffix(value string) string { diff --git a/cmd/gen.go b/cmd/gen.go index 7cdf0f283..6abd821d8 100644 --- a/cmd/gen.go +++ b/cmd/gen.go @@ -41,7 +41,6 @@ Make sure you run this command in the root path of a go project.`, }, } -// scan a directory and gen a gopm file func runGen(ctx *cli.Context) { setup(ctx) @@ -55,15 +54,18 @@ func runGen(ctx *cli.Context) { log.Fatal("", "\t"+err.Error()) } + targetPath := parseTarget(gf.MustValue("target", "path")) // Get dependencies. - imports := doc.GetAllImports([]string{workDir}, - parseTarget(gf.MustValue("target", "path")), ctx.Bool("example")) + imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example")) for _, p := range imports { p = doc.GetProjectPath(p) - if strings.HasSuffix(workDir, p) { + // Skip subpackage(s) of current project. + if strings.HasSuffix(workDir, p) || strings.HasPrefix(p, targetPath) { continue } + + // Check if user specified the version. if value := gf.MustValue("deps", p); len(value) == 0 { gf.SetValue("deps", p, "") } diff --git a/cmd/get.go b/cmd/get.go index 009fd5049..c572159d5 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -1,4 +1,4 @@ -// Copyright 2013 gopm authors. +// Copyright 2013-2014 gopm authors. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain @@ -69,7 +69,6 @@ func init() { func runGet(ctx *cli.Context) { setup(ctx) - // Check conflicts. if ctx.Bool("gopath") && ctx.Bool("remote") { log.Error("get", "Command options have conflicts") @@ -119,11 +118,17 @@ func getByGopmfile(ctx *cli.Context) { } gf := doc.NewGopmfile(".") + targetPath := parseTarget(gf.MustValue("target", "path")) // Get dependencies. - imports := doc.GetAllImports([]string{workDir}, - parseTarget(gf.MustValue("target", "path")), ctx.Bool("example")) + imports := doc.GetAllImports([]string{workDir}, targetPath, ctx.Bool("example")) + nodes := make([]*doc.Node, 0, len(imports)) for _, p := range imports { + p = doc.GetProjectPath(p) + // Skip subpackage(s) of current project. + if strings.HasSuffix(workDir, p) || strings.HasPrefix(p, targetPath) { + continue + } node := doc.NewNode(p, p, doc.BRANCH, "", true) // Check if user specified the version. @@ -140,6 +145,7 @@ func getByGopmfile(ctx *cli.Context) { } func getByPath(ctx *cli.Context) { + return nodes := make([]*doc.Node, 0, len(ctx.Args())) for _, info := range ctx.Args() { pkgPath := info @@ -192,90 +198,99 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { if n.Type == doc.LOCAL { continue } - // Check if it is a valid remote path. - if doc.IsValidRemotePath(n.ImportPath) { - gopathDir := path.Join(installGopath, n.ImportPath) - n.RootPath = doc.GetProjectPath(n.ImportPath) - installPath := path.Join(installRepoPath, n.RootPath) + - versionSuffix(n.Value) - - if !ctx.Bool("update") { - // Check if package has been downloaded. - if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) || - com.IsExist(installPath) { - log.Trace("Skipped installed package: %s@%s:%s", - n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) - - if ctx.Bool("gopath") && com.IsExist(installPath) { - copyToGopath(installPath, gopathDir) - } - continue - } else { - doc.LocalNodes.SetValue(n.RootPath, "value", "") + // Check if it is a valid remote path or C. + if n.ImportPath == "C" { + continue + } else if !doc.IsValidRemotePath(n.ImportPath) { + // Invalid import path. + log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%s@%s:%s", + n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))) + failConut++ + continue + } + + // Valid import path. + gopathDir := path.Join(installGopath, n.ImportPath) + n.RootPath = doc.GetProjectPath(n.ImportPath) + installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value) + + // Indicates whether need to download package again. + if len(n.Value) > 0 && com.IsExist(installPath) { + n.IsGetDepsOnly = true + } + + if !ctx.Bool("update") { + // Check if package has been downloaded. + if (len(n.Value) == 0 && !ctx.Bool("remote") && com.IsExist(gopathDir)) || + com.IsExist(installPath) { + log.Trace("Skipped installed package: %s@%s:%s", + n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) + + // Only copy when no version control. + if ctx.Bool("gopath") && com.IsExist(installPath) || + len(getVcsName(gopathDir)) == 0 { + copyToGopath(installPath, gopathDir) } + continue + } else { + doc.LocalNodes.SetValue(n.RootPath, "value", "") + } + } + + if downloadCache[n.RootPath] { + log.Trace("Skipped downloaded package: %s@%s:%s", + n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) + continue + } + + // Download package. + nod, imports := downloadPackage(ctx, n) + if len(imports) > 0 { + var gf *goconfig.ConfigFile + + // Check if has gopmfile. + if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) { + log.Log("Found gopmfile: %s@%s:%s", + n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) + gf = doc.NewGopmfile(installPath) } - if !downloadCache[n.RootPath] { - // Download package. - nod, imports := downloadPackage(ctx, n) - if len(imports) > 0 { - var gf *goconfig.ConfigFile - - // Check if has gopmfile - if com.IsFile(installPath + "/" + doc.GOPM_FILE_NAME) { - log.Log("Found gopmfile: %s@%s:%s", - n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) - - gf = doc.NewGopmfile(installPath) - } - - // Need to download dependencies. - // Generate temporary nodes. - nodes := make([]*doc.Node, len(imports)) - for i := range nodes { - nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true) - - if gf == nil { - continue - } - - // Check if user specified the version. - if v, err := gf.GetValue("deps", imports[i]); err == nil && - len(v) > 0 { - nodes[i].Type, nodes[i].Value = validPath(v) - } - } - downloadPackages(ctx, nodes) + // Need to download dependencies. + // Generate temporary nodes. + nodes := make([]*doc.Node, len(imports)) + for i := range nodes { + nodes[i] = doc.NewNode(imports[i], imports[i], doc.BRANCH, "", true) + + if gf == nil { + continue } - // Only save package information with specific commit. - if nod != nil { - // Save record in local nodes. - log.Success("SUCC", "GET", fmt.Sprintf("%s@%s:%s", - n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))) - downloadCount++ - - // Only save non-commit node. - if len(nod.Value) == 0 && len(nod.Revision) > 0 { - doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision) - } - - if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") && - len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 { - copyToGopath(installPath, gopathDir) - } + // Check if user specified the version. + if v, err := gf.GetValue("deps", imports[i]); err == nil && len(v) > 0 { + nodes[i].Type, nodes[i].Value = validPath(v) } - } else { - log.Trace("Skipped downloaded package: %s@%s:%s", - n.ImportPath, n.Type, doc.CheckNodeValue(n.Value)) } - } else if n.ImportPath == "C" { + downloadPackages(ctx, nodes) + } + + // Only save package information with specific commit. + if nod == nil { continue - } else { - // Invalid import path. - log.Error("download", "Skipped invalid package: "+fmt.Sprintf("%s@%s:%s", - n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))) - failConut++ + } + + // Save record in local nodes. + log.Success("SUCC", "GET", fmt.Sprintf("%s@%s:%s", + n.ImportPath, n.Type, doc.CheckNodeValue(n.Value))) + downloadCount++ + + // Only save non-commit node. + if len(nod.Value) == 0 && len(nod.Revision) > 0 { + doc.LocalNodes.SetValue(nod.RootPath, "value", nod.Revision) + } + + if ctx.Bool("gopath") && com.IsExist(installPath) && !ctx.Bool("update") && + len(getVcsName(path.Join(installGopath, nod.RootPath))) == 0 { + copyToGopath(installPath, gopathDir) } } } @@ -296,6 +311,11 @@ func downloadPackage(ctx *cli.Context, nod *doc.Node) (*doc.Node, []string) { err = updateByVcs(vcs, gopathDir) imports = doc.GetAllImports([]string{gopathDir}, nod.RootPath, false) } else { + // If package has revision and exist, then just check dependencies. + if nod.IsGetDepsOnly { + return nod, doc.GetAllImports([]string{path.Join(installRepoPath, nod.RootPath) + versionSuffix(nod.Value)}, + nod.RootPath, ctx.Bool("example")) + } nod.Revision = doc.LocalNodes.MustValue(nod.RootPath, "value") imports, err = doc.PureDownload(nod, installRepoPath, ctx) //CmdGet.Flags) } diff --git a/doc/struct.go b/doc/struct.go index 96c538503..59258e8d9 100644 --- a/doc/struct.go +++ b/doc/struct.go @@ -59,10 +59,11 @@ func NewDefaultPkg(importPath string) *Pkg { type Node struct { Pkg - DownloadURL string - Synopsis string - IsGetDeps bool - Revision string + DownloadURL string + Synopsis string + IsGetDeps bool + IsGetDepsOnly bool + Revision string } func NewNode(importPath, downloadUrl, tp, value string, isGetDeps bool) *Node { diff --git a/gopm.go b/gopm.go index 1dace5eb4..f0db2cd41 100644 --- a/gopm.go +++ b/gopm.go @@ -1,4 +1,4 @@ -// Copyright 2013 gopm authors. +// Copyright 2013-2014 gopm authors. // // Licensed under the Apache License, Version 2.0 (the "License"): you may // not use this file except in compliance with the License. You may obtain @@ -12,7 +12,7 @@ // License for the specific language governing permissions and limitations // under the License. -// gopm(Go Package Manager) is a Go package manage tool for search, install, update and share packages in Go. +// gopm(Go Package Manager) is a Go package manage tool for searching, installing, updating and sharing your packages in Go. package main import ( @@ -29,7 +29,7 @@ import ( // Test that go1.1 tag above is included in builds. main.go refers to this definition. const go11tag = true -const APP_VER = "0.6.0.1211" +const APP_VER = "0.6.1.0110" // //cmd.CmdSearch, // cmdClean, @@ -37,7 +37,6 @@ const APP_VER = "0.6.0.1211" // cmdEnv, // cmdFix, // cmdList, -// cmdTest, // cmdTool, // cmdVet, // } @@ -53,11 +52,11 @@ func main() { app.Version = APP_VER app.Commands = []cli.Command{ cmd.CmdGet, - cmd.CmdBin, + //cmd.CmdBin, cmd.CmdGen, - cmd.CmdRun, - cmd.CmdBuild, - cmd.CmdInstall, + //cmd.CmdRun, + //cmd.CmdBuild, + //cmd.CmdInstall, //cmd.CmdUpdate, //cmd.CmdTest, } From d9e5e845393df397c9eb6b3e7581db0165746292 Mon Sep 17 00:00:00 2001 From: Unknown Date: Fri, 10 Jan 2014 16:20:26 +0800 Subject: [PATCH 5/7] Fixed bug: do not check update again when using tag and commit, not including branch. --- cmd/get.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index c572159d5..9157f351e 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -99,7 +99,7 @@ func runGet(ctx *cli.Context) { } // The gopm local repository. - installRepoPath = doc.HomeDir + "/repos" + installRepoPath = path.Join(doc.HomeDir, "repos") log.Log("Local repository path: %s", installRepoPath) // Check number of arguments to decide which function to call. @@ -188,6 +188,18 @@ func copyToGopath(srcPath, destPath string) { log.Log("Package copied to GOPATH: %s", importPath) } +func isUnchangablePoint(nod *doc.Node) bool { + if len(nod.Value) == 0 { + return false + } + + switch nod.Type { + case doc.COMMIT, doc.TAG: + return true + } + return false +} + // downloadPackages downloads packages with certain commit, // if the commit is empty string, then it downloads all dependencies, // otherwise, it only downloada package with specific commit only. @@ -215,7 +227,7 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value) // Indicates whether need to download package again. - if len(n.Value) > 0 && com.IsExist(installPath) { + if isUnchangablePoint(n) && com.IsExist(installPath) { n.IsGetDepsOnly = true } From 8fe66176a5e6aeec855a4844b634806950d98fe0 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Fri, 10 Jan 2014 17:41:32 +0800 Subject: [PATCH 6/7] change isUnchangablePoint to Pkg's method IsFixed --- cmd/get.go | 14 +------------- doc/struct.go | 9 +++++++++ 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cmd/get.go b/cmd/get.go index 9157f351e..4eeb9a471 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -188,18 +188,6 @@ func copyToGopath(srcPath, destPath string) { log.Log("Package copied to GOPATH: %s", importPath) } -func isUnchangablePoint(nod *doc.Node) bool { - if len(nod.Value) == 0 { - return false - } - - switch nod.Type { - case doc.COMMIT, doc.TAG: - return true - } - return false -} - // downloadPackages downloads packages with certain commit, // if the commit is empty string, then it downloads all dependencies, // otherwise, it only downloada package with specific commit only. @@ -227,7 +215,7 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value) // Indicates whether need to download package again. - if isUnchangablePoint(n) && com.IsExist(installPath) { + if n.IsFixed() && com.IsExist(installPath) { n.IsGetDepsOnly = true } diff --git a/doc/struct.go b/doc/struct.go index 59258e8d9..02e91b5b4 100644 --- a/doc/struct.go +++ b/doc/struct.go @@ -42,6 +42,15 @@ type Pkg struct { Value string // Branch, tag, commit or local. } +// If the package is fixed and no need to updated. +// For commit, tag and local, it's fixed. For branch +func (pkg *Pkg) IsFixed() bool { + if pkg.Type == BRANCH || len(pkg.Value) == 0 { + return false + } + return true +} + func (pkg *Pkg) VerString() string { if pkg.Value == "" { return pkg.Type From 9691733ace154d7890659312b5a5f2b7f55b277a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 12 Jan 2014 18:02:13 +0800 Subject: [PATCH 7/7] =?UTF-8?q?Added=20option=20=E2=80=9C=E2=80=94update,?= =?UTF-8?q?=20-u=E2=80=9D=20for=20build=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 24 ++++++++++++------------ cmd/build.go | 1 + cmd/cmd.go | 4 ++++ cmd/get.go | 9 +++++++-- cmd/gopath.go | 2 +- gopm.go | 8 ++++---- 6 files changed, 29 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 1360a64d3..40f5cafe4 100644 --- a/README.md +++ b/README.md @@ -19,21 +19,21 @@ USAGE: gopm [global options] command [command options] [arguments...] VERSION: - 0.6.0.1211 + 0.6.1.0110 COMMANDS: - get fetch remote package(s) and dependencies to local repository - bin download and link dependencies and build executable binary - gen generate a gopmfile according current Go project - run link dependencies and go run - build link dependencies and go build - install link dependencies and go install - help, h Shows a list of commands or help for one command - + get fetch remote package(s) and dependencies to local repository + bin download and link dependencies and build executable binary + gen generate a gopmfile according current Go project + run link dependencies and go run + build link dependencies and go build + install link dependencies and go install + help, h Shows a list of commands or help for one command + GLOBAL OPTIONS: - --noterm disable color output - --version print the version - --help, -h show help + --noterm disable color output + --version, -v print the version + --help, -h show help ``` diff --git a/cmd/build.go b/cmd/build.go index 4e4feaf21..5461e586d 100644 --- a/cmd/build.go +++ b/cmd/build.go @@ -34,6 +34,7 @@ and execute 'go build' gopm build `, Action: runBuild, Flags: []cli.Flag{ + cli.BoolFlag{"update, u", "update pakcage(s) and dependencies if any"}, cli.BoolFlag{"verbose, v", "show process details"}, }, } diff --git a/cmd/cmd.go b/cmd/cmd.go index a2e608393..8a2d5d24a 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -81,3 +81,7 @@ func versionSuffix(value string) string { } return "" } + +func isSubpackage(rootPath, targetPath string) bool { + return strings.HasSuffix(workDir, rootPath) || strings.HasPrefix(rootPath, targetPath) +} diff --git a/cmd/get.go b/cmd/get.go index 4eeb9a471..6a90b1aca 100644 --- a/cmd/get.go +++ b/cmd/get.go @@ -126,7 +126,7 @@ func getByGopmfile(ctx *cli.Context) { for _, p := range imports { p = doc.GetProjectPath(p) // Skip subpackage(s) of current project. - if strings.HasSuffix(workDir, p) || strings.HasPrefix(p, targetPath) { + if isSubpackage(p, targetPath) { continue } node := doc.NewNode(p, p, doc.BRANCH, "", true) @@ -145,7 +145,6 @@ func getByGopmfile(ctx *cli.Context) { } func getByPath(ctx *cli.Context) { - return nodes := make([]*doc.Node, 0, len(ctx.Args())) for _, info := range ctx.Args() { pkgPath := info @@ -214,6 +213,10 @@ func downloadPackages(ctx *cli.Context, nodes []*doc.Node) { n.RootPath = doc.GetProjectPath(n.ImportPath) installPath := path.Join(installRepoPath, n.RootPath) + versionSuffix(n.Value) + if isSubpackage(n.RootPath, ".") { + continue + } + // Indicates whether need to download package again. if n.IsFixed() && com.IsExist(installPath) { n.IsGetDepsOnly = true @@ -388,6 +391,8 @@ func updateByVcs(vcs, dirPath string) error { if len(stderr) > 0 { log.Error("", "Error: "+stderr) } + case "svn": + log.Error("", "Error: not support svn yet") } return nil } diff --git a/cmd/gopath.go b/cmd/gopath.go index 124906e77..9a32398ee 100644 --- a/cmd/gopath.go +++ b/cmd/gopath.go @@ -101,7 +101,7 @@ func getChildPkgs(ctx *cli.Context, cpath string, ppkg *doc.Pkg, cachePkgs map[s if pkgName != "" && strings.HasPrefix(pkg.ImportPath, pkgName) { newPath = filepath.Join(curPath, strings.TrimPrefix(pkg.ImportPath, pkgName)) } else { - if !com.IsExist(newPath) { + if !com.IsExist(newPath) || ctx.Bool("update") { node := doc.NewNode(pkg.ImportPath, pkg.ImportPath, pkg.Type, pkg.Value, true) nodes := []*doc.Node{node} diff --git a/gopm.go b/gopm.go index f0db2cd41..f58d1663a 100644 --- a/gopm.go +++ b/gopm.go @@ -52,11 +52,11 @@ func main() { app.Version = APP_VER app.Commands = []cli.Command{ cmd.CmdGet, - //cmd.CmdBin, + cmd.CmdBin, cmd.CmdGen, - //cmd.CmdRun, - //cmd.CmdBuild, - //cmd.CmdInstall, + cmd.CmdRun, + cmd.CmdBuild, + cmd.CmdInstall, //cmd.CmdUpdate, //cmd.CmdTest, }