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

Commit

Permalink
fix: multiple oh-my-zsh plugins behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jul 12, 2018
1 parent ff9ed6c commit b780e96
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 3 additions & 1 deletion antibodylib/antibody_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ func TestMultipleRepositories(t *testing.T) {
"zsh-users/zsh-completions",
"zsh-users/zsh-autosuggestions",
"",
"robbyrussell/oh-my-zsh folder:plugins/asdf",
"robbyrussell/oh-my-zsh folder:plugins/autoenv",
"# these should be at last!",
"sindresorhus/pure",
"zsh-users/zsh-syntax-highlighting",
Expand All @@ -77,7 +79,7 @@ func TestMultipleRepositories(t *testing.T) {
runtime.NumCPU(),
).Bundle()
assert.NoError(t, err)
assert.Len(t, strings.Split(sh, "\n"), 27)
assert.Len(t, strings.Split(sh, "\n"), 31)
}

func TestHome(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions project/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os/exec"
"path/filepath"
"strings"
"sync"

"github.com/getantibody/folder"
)
Expand Down Expand Up @@ -72,7 +73,17 @@ func NewGit(cwd, line string) Project {
}
}

var locks = map[string]*sync.Mutex{}
var lock sync.Mutex

func (g gitProject) Download() error {
lock.Lock()
if locks[g.folder] == nil {
locks[g.folder] = &sync.Mutex{}
}
lock.Unlock()
locks[g.folder].Lock()
defer locks[g.folder].Unlock()
if _, err := os.Stat(g.folder); os.IsNotExist(err) {
// #nosec
var cmd = exec.Command("git", "clone",
Expand Down
6 changes: 4 additions & 2 deletions project/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,10 @@ func TestSubFolder(t *testing.T) {

func TestMultipleSubFolders(t *testing.T) {
home := home()
assert.NoError(t, project.NewGit(home, "robbyrussell/oh-my-zsh folder:plugins/aws").Download())
assert.NoError(t, project.NewGit(home, "robbyrussell/oh-my-zsh folder:plugins/battery").Download())
assert.NoError(t, project.NewGit(home, strings.Join([]string{
"robbyrussell/oh-my-zsh folder:plugins/aws",
"robbyrussell/oh-my-zsh folder:plugins/battery",
}, "\n")).Download())
}

func home() string {
Expand Down

0 comments on commit b780e96

Please sign in to comment.