From ec4cd5ed48b96157bfcfb45e9f14cf4da425a8ff Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Thu, 7 Jan 2021 11:36:09 -0300 Subject: [PATCH] Fix `.task` directory location Closes #247 --- CHANGELOG.md | 5 ++++- internal/status/checksum.go | 11 ++++++----- status.go | 3 ++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d1e7b0c8..550edf44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## Unreleased +- Fix the `.task` directory being created in the task directory instead of the + Taskfile directory + ([#247](https://github.com/go-task/task/issues/247)). - Fix a bug where dynamic variables (those declared with `sh:`) were not running in the task directory when the task has a custom dir or it was - in an included taskfile + in an included Taskfile ([#384](https://github.com/go-task/task/issues/384)). - The watch feature (via the `--watch` flag) got a few different bug fixes and should be more stable now diff --git a/internal/status/checksum.go b/internal/status/checksum.go index af2e9e43..16d730b9 100644 --- a/internal/status/checksum.go +++ b/internal/status/checksum.go @@ -14,7 +14,8 @@ import ( // Checksum validades if a task is up to date by calculating its source // files checksum type Checksum struct { - Dir string + BaseDir string + TaskDir string Task string Sources []string Generates []string @@ -32,7 +33,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { data, _ := ioutil.ReadFile(checksumFile) oldMd5 := strings.TrimSpace(string(data)) - sources, err := globs(c.Dir, c.Sources) + sources, err := globs(c.TaskDir, c.Sources) if err != nil { return false, err } @@ -43,7 +44,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { } if !c.Dry { - _ = os.MkdirAll(filepath.Join(c.Dir, ".task", "checksum"), 0755) + _ = os.MkdirAll(filepath.Join(c.BaseDir, ".task", "checksum"), 0755) if err = ioutil.WriteFile(checksumFile, []byte(newMd5+"\n"), 0644); err != nil { return false, err } @@ -52,7 +53,7 @@ func (c *Checksum) IsUpToDate() (bool, error) { if len(c.Generates) > 0 { // For each specified 'generates' field, check whether the files actually exist for _, g := range c.Generates { - generates, err := glob(c.Dir, g) + generates, err := glob(c.TaskDir, g) if os.IsNotExist(err) { return false, nil } @@ -107,7 +108,7 @@ func (*Checksum) Kind() string { } func (c *Checksum) checksumFilePath() string { - return filepath.Join(c.Dir, ".task", "checksum", c.normalizeFilename(c.Task)) + return filepath.Join(c.BaseDir, ".task", "checksum", c.normalizeFilename(c.Task)) } var checksumFilenameRegexp = regexp.MustCompile("[^A-z0-9]") diff --git a/status.go b/status.go index 9e2ad1a5..fcffa456 100644 --- a/status.go +++ b/status.go @@ -76,7 +76,8 @@ func (e *Executor) timestampChecker(t *taskfile.Task) status.Checker { func (e *Executor) checksumChecker(t *taskfile.Task) status.Checker { return &status.Checksum{ - Dir: t.Dir, + BaseDir: e.Dir, + TaskDir: t.Dir, Task: t.Name(), Sources: t.Sources, Generates: t.Generates,