Skip to content
This repository has been archived by the owner on Mar 5, 2022. It is now read-only.

Commit

Permalink
Remove fork if exists (#33)
Browse files Browse the repository at this point in the history
*  Remove fork only if exists

*  Adding tests
  • Loading branch information
franciscocpg authored and spenczar committed Sep 11, 2017
1 parent 31601f0 commit 0a2404e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
23 changes: 23 additions & 0 deletions retool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,29 @@ func TestRetool(t *testing.T) {
}
})

t.Run("build_with_fork", func(t *testing.T) {
t.Parallel()
dir, cleanup := setupTempDir(t)
defer cleanup()
runRetoolCmd(t, dir, retool, "-f", "https://github.com/franciscocpg/retool.git", "add", "github.com/twitchtv/retool", "origin/master")

// Suppose we only have _tools/src available. Does `retool build` work?
_ = os.RemoveAll(filepath.Join(dir, "_tools", "bin"))
_ = os.RemoveAll(filepath.Join(dir, "_tools", "pkg"))
_ = os.RemoveAll(filepath.Join(dir, "_tools", "manifest.json"))

runRetoolCmd(t, dir, retool, "build")

// Now the binary should be installed
assertBinInstalled(t, dir, "retool")

// Legal files should be kept around
_, err := os.Stat(filepath.Join(dir, "_tools", "src", "github.com", "twitchtv", "retool", "LICENSE"))
if err != nil {
t.Error("missing license file")
}
})

t.Run("build_with_gobin_set", func(t *testing.T) {
// Even if GOBIN is set to a directory not controlled by retool, running
// 'retool build' should still put built binaries in _tools/bin.
Expand Down
22 changes: 20 additions & 2 deletions tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,31 @@ func get(t *tool) error {
func setVersion(t *tool) error {
// If we're using a fork, add it
if t.Fork != "" {
cmd := exec.Command("git", "remote", "rm", "fork")
cmd := exec.Command("git", "remote")
cmd.Dir = t.path()
_, err := cmd.Output()
b, err := cmd.Output()
if err != nil {
return err
}

rs := strings.Split(string(b), "\n")
containsFork := false
for _, r := range rs {
if r == "fork" {
containsFork = true
break
}
}

if containsFork {
cmd = exec.Command("git", "remote", "rm", "fork")
cmd.Dir = t.path()
_, err = cmd.Output()
if err != nil {
return err
}
}

cmd = exec.Command("git", "remote", "add", "-f", "fork", t.Fork)
cmd.Dir = t.path()
_, err = cmd.Output()
Expand Down

0 comments on commit 0a2404e

Please sign in to comment.