mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-28 21:48:25 +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,17 +455,10 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
|
|||||||
return nil, err
|
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...)
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.Log.Debug("%d files were modified in this pull request. Modified files: %v", len(modifiedFiles), modifiedFiles)
|
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)
|
shouldSkipClone, err := p.shouldSkipClone(ctx, modifiedFiles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -473,6 +466,7 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
|
|||||||
if shouldSkipClone {
|
if shouldSkipClone {
|
||||||
return []command.ProjectContext{}, nil
|
return []command.ProjectContext{}, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Need to lock the workspace we're about to clone to.
|
// Need to lock the workspace we're about to clone to.
|
||||||
workspace := DefaultWorkspace
|
workspace := DefaultWorkspace
|
||||||
@@ -490,6 +484,15 @@ func (p *DefaultProjectCommandBuilder) buildAllCommandsByCfg(ctx *command.Contex
|
|||||||
return nil, err
|
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.
|
// Parse config file if it exists.
|
||||||
repoCfgFile := p.GlobalCfg.RepoConfigFile(ctx.Pull.BaseRepo.ID())
|
repoCfgFile := p.GlobalCfg.RepoConfigFile(ctx.Pull.BaseRepo.ID())
|
||||||
hasRepoCfg, err := p.ParserValidator.HasRepoCfg(repoDir, repoCfgFile)
|
hasRepoCfg, err := p.ParserValidator.HasRepoCfg(repoDir, repoCfgFile)
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ var defaultUserConfig = struct {
|
|||||||
AutoplanFileList: "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
|
AutoplanFileList: "**/*.tf,**/*.tfvars,**/*.tfvars.json,**/terragrunt.hcl,**/.terraform.lock.hcl",
|
||||||
RestrictFileList: false,
|
RestrictFileList: false,
|
||||||
SilenceNoProjects: false,
|
SilenceNoProjects: false,
|
||||||
IncludeGitUntrackedFiles: true,
|
IncludeGitUntrackedFiles: false,
|
||||||
AutoDiscoverMode: "auto",
|
AutoDiscoverMode: "auto",
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1699,6 +1699,7 @@ func TestDefaultProjectCommandBuilder_SkipCloneNoChanges(t *testing.T) {
|
|||||||
ExpectedCtxs int
|
ExpectedCtxs int
|
||||||
ExpectedClones InvocationCountMatcher
|
ExpectedClones InvocationCountMatcher
|
||||||
ModifiedFiles []string
|
ModifiedFiles []string
|
||||||
|
IncludeGitUntrackedFiles bool
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
AtlantisYAML: `
|
AtlantisYAML: `
|
||||||
@@ -1708,6 +1709,17 @@ projects:
|
|||||||
ExpectedCtxs: 0,
|
ExpectedCtxs: 0,
|
||||||
ExpectedClones: Never(),
|
ExpectedClones: Never(),
|
||||||
ModifiedFiles: []string{"dir2/main.tf"},
|
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: `
|
AtlantisYAML: `
|
||||||
@@ -1716,6 +1728,7 @@ parallel_plan: true`,
|
|||||||
ExpectedCtxs: 0,
|
ExpectedCtxs: 0,
|
||||||
ExpectedClones: Once(),
|
ExpectedClones: Once(),
|
||||||
ModifiedFiles: []string{"README.md"},
|
ModifiedFiles: []string{"README.md"},
|
||||||
|
IncludeGitUntrackedFiles: false,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
AtlantisYAML: `
|
AtlantisYAML: `
|
||||||
@@ -1727,6 +1740,7 @@ projects:
|
|||||||
ExpectedCtxs: 0,
|
ExpectedCtxs: 0,
|
||||||
ExpectedClones: Once(),
|
ExpectedClones: Once(),
|
||||||
ModifiedFiles: []string{"dir2/main.tf"},
|
ModifiedFiles: []string{"dir2/main.tf"},
|
||||||
|
IncludeGitUntrackedFiles: false,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1770,7 +1784,7 @@ projects:
|
|||||||
userConfig.AutoplanFileList,
|
userConfig.AutoplanFileList,
|
||||||
userConfig.RestrictFileList,
|
userConfig.RestrictFileList,
|
||||||
userConfig.SilenceNoProjects,
|
userConfig.SilenceNoProjects,
|
||||||
userConfig.IncludeGitUntrackedFiles,
|
c.IncludeGitUntrackedFiles,
|
||||||
userConfig.AutoDiscoverMode,
|
userConfig.AutoDiscoverMode,
|
||||||
scope,
|
scope,
|
||||||
terraformClient,
|
terraformClient,
|
||||||
|
|||||||
Reference in New Issue
Block a user