Skip to content

Commit

Permalink
fix: git worktree switch invalidation loop
Browse files Browse the repository at this point in the history
Invalidation loop of cached git worktree on every werf invocation may occur when WERF_HOME (`~/.werf`) is a symlink to another volume.

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Apr 21, 2022
1 parent a2d26ec commit e698bff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/true_git/work_tree.go
Expand Up @@ -81,12 +81,17 @@ func prepareWorkTree(ctx context.Context, repoDir, workTreeCacheDir string, comm
case err != nil:
return "", fmt.Errorf("error accessing %q: %w", workTreeDir, err)
default:
resolvedWorkTreeDir, err := filepath.EvalSymlinks(workTreeDir)
if err != nil {
return "", fmt.Errorf("unable to eval symlinks of %q: %w", workTreeDir, err)
}

isWorkTreeRegistered := false
if workTreeList, err := GetWorkTreeList(ctx, repoDir); err != nil {
return "", fmt.Errorf("unable to get worktree list for repo %s: %w", repoDir, err)
} else {
for _, workTreeDesc := range workTreeList {
if filepath.ToSlash(workTreeDesc.Path) == filepath.ToSlash(workTreeDir) {
if filepath.ToSlash(workTreeDesc.Path) == filepath.ToSlash(resolvedWorkTreeDir) {
isWorkTreeRegistered = true
}
}
Expand Down

0 comments on commit e698bff

Please sign in to comment.