mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 20:28:22 +00:00
fix: Workspace Error when include-git-untracked-files is true (#5288)
Signed-off-by: X-Guardian <32168619+X-Guardian@users.noreply.github.com>
This commit is contained in:
@@ -455,23 +455,17 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.IncludeGitUntrackedFiles {
|
||||
ctx.Log.Debug(("'include-git-untracked-files' option is set, getting untracked files"))
|
||||
untrackedFiles, err := p.WorkingDir.GetGitUntrackedFiles(ctx.Log, ctx.HeadRepo, ctx.Pull, DefaultWorkspace)
|
||||
ctx.Log.Debug("%d files were modified in this pull request. Modified files: %v", len(modifiedFiles), modifiedFiles)
|
||||
|
||||
// If we're not including git untracked files, we can skip the clone if there are no modified files.
|
||||
if !p.IncludeGitUntrackedFiles {
|
||||
shouldSkipClone, err := p.shouldSkipClone(ctx, modifiedFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
modifiedFiles = append(modifiedFiles, untrackedFiles...)
|
||||
}
|
||||
|
||||
ctx.Log.Debug("%d files were modified in this pull request. Modified files: %v", len(modifiedFiles), modifiedFiles)
|
||||
|
||||
shouldSkipClone, err := p.shouldSkipClone(ctx, modifiedFiles)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if shouldSkipClone {
|
||||
return []command.ProjectContext{}, nil
|
||||
if shouldSkipClone {
|
||||
return []command.ProjectContext{}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// Need to lock the workspace we're about to clone to.
|
||||
@@ -490,6 +484,15 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if p.IncludeGitUntrackedFiles {
|
||||
ctx.Log.Debug(("'include-git-untracked-files' option is set, getting untracked files"))
|
||||
untrackedFiles, err := p.WorkingDir.GetGitUntrackedFiles(ctx.Log, ctx.HeadRepo, ctx.Pull, DefaultWorkspace)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
modifiedFiles = append(modifiedFiles, untrackedFiles...)
|
||||
}
|
||||
|
||||
// Parse config file if it exists.
|
||||
repoCfgFile := p.GlobalCfg.RepoConfigFile(ctx.Pull.BaseRepo.ID())
|
||||
hasRepoCfg, err := p.ParserValidator.HasRepoCfg(repoDir, repoCfgFile)
|
||||
|
||||
@@ -45,7 +45,7 @@ var defaultUserConfig = struct {
|
||||
AutoplanFileList: "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
|
||||
RestrictFileList: false,
|
||||
SilenceNoProjects: false,
|
||||
IncludeGitUntrackedFiles: true,
|
||||
IncludeGitUntrackedFiles: false,
|
||||
AutoDiscoverMode: "auto",
|
||||
}
|
||||
|
||||
@@ -1695,27 +1695,40 @@ projects:
|
||||
// Test that we don't clone the repo if there were no changes based on the atlantis.yaml file.
|
||||
func TestDefaultProjectCommandBuilder_SkipCloneNoChanges(t *testing.T) {
|
||||
cases := []struct {
|
||||
AtlantisYAML string
|
||||
ExpectedCtxs int
|
||||
ExpectedClones InvocationCountMatcher
|
||||
ModifiedFiles []string
|
||||
AtlantisYAML string
|
||||
ExpectedCtxs int
|
||||
ExpectedClones InvocationCountMatcher
|
||||
ModifiedFiles []string
|
||||
IncludeGitUntrackedFiles bool
|
||||
}{
|
||||
{
|
||||
AtlantisYAML: `
|
||||
version: 3
|
||||
projects:
|
||||
- dir: dir1`,
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Never(),
|
||||
ModifiedFiles: []string{"dir2/main.tf"},
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Never(),
|
||||
ModifiedFiles: []string{"dir2/main.tf"},
|
||||
IncludeGitUntrackedFiles: false,
|
||||
},
|
||||
{
|
||||
AtlantisYAML: `
|
||||
version: 3
|
||||
projects:
|
||||
- dir: dir1`,
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Once(),
|
||||
ModifiedFiles: []string{"dir2/main.tf"},
|
||||
IncludeGitUntrackedFiles: true,
|
||||
},
|
||||
{
|
||||
AtlantisYAML: `
|
||||
version: 3
|
||||
parallel_plan: true`,
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Once(),
|
||||
ModifiedFiles: []string{"README.md"},
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Once(),
|
||||
ModifiedFiles: []string{"README.md"},
|
||||
IncludeGitUntrackedFiles: false,
|
||||
},
|
||||
{
|
||||
AtlantisYAML: `
|
||||
@@ -1724,9 +1737,10 @@ autodiscover:
|
||||
mode: enabled
|
||||
projects:
|
||||
- dir: dir1`,
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Once(),
|
||||
ModifiedFiles: []string{"dir2/main.tf"},
|
||||
ExpectedCtxs: 0,
|
||||
ExpectedClones: Once(),
|
||||
ModifiedFiles: []string{"dir2/main.tf"},
|
||||
IncludeGitUntrackedFiles: false,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1770,7 +1784,7 @@ projects:
|
||||
userConfig.AutoplanFileList,
|
||||
userConfig.RestrictFileList,
|
||||
userConfig.SilenceNoProjects,
|
||||
userConfig.IncludeGitUntrackedFiles,
|
||||
c.IncludeGitUntrackedFiles,
|
||||
userConfig.AutoDiscoverMode,
|
||||
scope,
|
||||
terraformClient,
|
||||
|
||||
Reference in New Issue
Block a user