From 4a02996d643d025e9d518cd92590c353cbfaadc6 Mon Sep 17 00:00:00 2001 From: Junichi Sato <22004610+sato11@users.noreply.github.com> Date: Sat, 7 Jan 2023 17:14:23 +0900 Subject: [PATCH] Make info dir when it is absent Fixes #413 --- internal/git/repository.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/internal/git/repository.go b/internal/git/repository.go index 0c7e0a11..27c30515 100644 --- a/internal/git/repository.go +++ b/internal/git/repository.go @@ -18,6 +18,7 @@ const ( cmdStagedFiles = "git diff --name-only --cached" cmdAllFiles = "git ls-files --cached" cmdPushFiles = "git diff --name-only HEAD @{push} || git diff --name-only HEAD master" + infoDirMode = 0o775 ) // Repository represents a git repository. @@ -48,8 +49,12 @@ func NewRepository(fs afero.Fs) (*Repository, error) { if err != nil { return nil, err } - if exists, _ := afero.DirExists(fs, filepath.Join(rootPath, infoPath)); exists { - infoPath = filepath.Join(rootPath, infoPath) + infoPath = filepath.Join(rootPath, infoPath) + if exists, _ := afero.DirExists(fs, infoPath); !exists { + err = fs.Mkdir(infoPath, infoDirMode) + if err != nil { + return nil, err + } } gitPath, err := execGit(cmdGitPath)