func (s *GitSuite) TestIsGitBranch(c *C) { g := new(Git) parts := strings.Split(os.Getenv("GOPATH"), ":") var path string for _, v := range parts { p := filepath.Join(v, "src", "github.com", "vube", "depman") if util.Exists(p) { path = p } } c.Assert(path, Not(Equals), "") util.Cd(path) c.Check(g.isBranch("master"), Equals, true) c.Check(g.isBranch("2.1.0"), Equals, false) c.Check(g.isBranch("7da42054c10f55d5f479b84f59013818ccbd1fd7"), Equals, false) util.Cd("/") c.Check(g.isBranch("master"), Equals, false) output := "pwd: /\n" + "git branch -r\n" + "fatal: Not a git repository (or any of the parent directories): .git\n" + "exit status 128\n" c.Check(s.buf.String(), Equals, output) }
//GetHead - Render a revspec to a commit ID func (g *Git) GetHead(d *Dependency) (hash string, err error) { var pwd string pwd = util.Pwd() util.Cd(d.Path()) c := exec.Command("git", "rev-parse", d.Version) { var out_bytes []byte out_bytes, err = c.CombinedOutput() hash = strings.TrimSuffix(string(out_bytes), "\n") } util.Cd(pwd) if err != nil { util.Print("pwd: " + util.Pwd()) util.PrintIndent(colors.Red("git rev-parse " + d.Version)) util.PrintIndent(colors.Red(string(hash))) util.PrintIndent(colors.Red(err.Error())) util.Fatal("") } return }
func (s *GitSuite) TestIsGitBranch(c *C) { g := new(Git) util.Cd(os.Getenv("GOPATH") + "/src/github.com/vube/depman") c.Check(g.isBranch("master"), Equals, true) c.Check(g.isBranch("2.1.0"), Equals, false) c.Check(g.isBranch("7da42054c10f55d5f479b84f59013818ccbd1fd7"), Equals, false) util.Cd("/") c.Check(g.isBranch("master"), Equals, false) output := "pwd: /\n" + "git branch -r\n" + "fatal: Not a git repository (or any of the parent directories): .git\n" + "exit status 128\n" c.Check(s.buf.String(), Equals, output) }
//GetHead - Render a revspec to a commit ID func (b *Bzr) GetHead(d *Dependency) (hash string, err error) { var pwd string pwd = util.Pwd() util.Cd(d.Path()) defer util.Cd(pwd) out, err := exec.Command("bzr", "revno", d.Version).CombinedOutput() hash = strings.TrimSuffix(string(out), "\n") if err != nil { util.Print("pwd: " + util.Pwd()) util.PrintIndent(colors.Red("bzr revno " + d.Version)) util.PrintIndent(colors.Red(hash)) util.PrintIndent(colors.Red(err.Error())) util.Fatal("") } return }
//GetHead - Render a revspec to a commit ID func (h *Hg) GetHead(d *Dependency) (hash string, err error) { var pwd string pwd = util.Pwd() util.Cd(d.Path()) defer util.Cd(pwd) out, err := exec.Command("hg", "id", "-i").CombinedOutput() hash = strings.TrimSuffix(string(out), "\n") if err != nil { util.Print("pwd: " + util.Pwd()) util.PrintIndent(colors.Red("hg id -i")) util.PrintIndent(colors.Red(hash)) util.PrintIndent(colors.Red(err.Error())) util.Fatal("") } return }
// Update rewrites Dependency name in deps.json to use the last commit in branch as version func Update(deps dep.DependencyMap, name string, branch string) { util.Print(colors.Blue("Updating:")) d, ok := deps.Map[name] if !ok { util.Fatal(colors.Red("Dependency Name '" + name + "' not found in deps.json")) } // record the old version oldVersion := d.Version // temporarily use the branch d.Version = branch pwd := util.Pwd() util.Cd(d.Path()) d.VCS.Checkout(d) d.VCS.Update(d) // get the last commit on the newly checked out branch v, err := d.VCS.LastCommit(d, branch) if err != nil { util.Fatal(err) } // set the version to be the last commit d.Version = v util.PrintIndent(colors.Blue(name) + " (" + oldVersion + " --> " + d.Version + ")") util.Cd(pwd) deps.Map[name] = d deps.Write() install.Install(deps) }
//GetHead - Render a revspec to a commit ID func (h *Hg) GetHead(d *Dependency) (hash string, err error) { var pwd string pwd = util.Pwd() util.Cd(d.Path()) { var out_bytes []byte out_bytes, err = exec.Command("hg", "id", "-i", d.Version).CombinedOutput() hash = strings.TrimSuffix(string(out_bytes), "\n") } util.Cd(pwd) if err != nil { util.Print("pwd: " + util.Pwd()) util.PrintIndent(colors.Red("hg id -i " + d.Version)) util.PrintIndent(colors.Red(hash)) util.PrintIndent(colors.Red(err.Error())) util.Fatal("") } return }
// recursively install a DependencyMap func recursiveInstall(deps dep.DependencyMap, set map[string]string) (err error) { for name, d := range deps.Map { start := time.Now() if duplicate(*d, set) { continue } stale := timelock.IsStale(d.Repo) util.PrintDep(name, d.Version, d.Repo, stale) subPath := d.Path() err = d.VCS.Clone(d) if err != nil { continue } util.Cd(subPath) if clean { d.VCS.Clean(d) } if stale { util.VerboseIndent(" # repo is stale, fetching") err = d.VCS.Fetch(d) if err != nil { continue } } err = d.VCS.Checkout(d) if err != nil { continue } if stale { err = d.VCS.Update(d) if err != nil { continue } } util.VerboseIndent(fmt.Sprintf("# time to install: %.3fs", time.Since(start).Seconds())) // Recursive depsFile := util.UpwardFind(subPath, dep.DepsFile) if depsFile != "" && Recurse { subDeps, err := dep.Read(depsFile) if err != nil { util.Print(colors.Red("Error reading deps from '" + depsFile + "': " + err.Error())) result.RegisterError() } else { util.IncreaseIndent() recursiveInstall(subDeps, set) util.DecreaseIndent() } } } return }