From b780e963f7e146f22ad2176a3acdd3044b474695 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 11 Jul 2018 22:36:13 -0700 Subject: [PATCH] fix: multiple oh-my-zsh plugins behavior --- antibodylib/antibody_test.go | 4 +++- project/git.go | 11 +++++++++++ project/git_test.go | 6 ++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/antibodylib/antibody_test.go b/antibodylib/antibody_test.go index 48226be..6bd51c2 100644 --- a/antibodylib/antibody_test.go +++ b/antibodylib/antibody_test.go @@ -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", @@ -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) { diff --git a/project/git.go b/project/git.go index f24a04f..be2c1c9 100644 --- a/project/git.go +++ b/project/git.go @@ -7,6 +7,7 @@ import ( "os/exec" "path/filepath" "strings" + "sync" "github.com/getantibody/folder" ) @@ -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", diff --git a/project/git_test.go b/project/git_test.go index df72b58..94bfed2 100644 --- a/project/git_test.go +++ b/project/git_test.go @@ -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 {