Skip to content

Commit

Permalink
Merge pull request #54 from hashicorp/IPL-5717-github-is-not-able-to-…
Browse files Browse the repository at this point in the history
…download-terraform-module-as-of-v-1-7-0

Static defaultExclusions rules are not congruent
  • Loading branch information
brandonc committed Jan 30, 2024
2 parents aebdd99 + c37bb9b commit 0480d9e
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
18 changes: 10 additions & 8 deletions internal/ignorefiles/terraformignore.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func readRules(input io.Reader) ([]rule, error) {
pattern = "**" + string(os.PathSeparator) + pattern
}
rule.val = pattern
rule.dirs = strings.Split(pattern, string(os.PathSeparator))
rules = append(rules, rule)
currentRuleIndex += 1
}
Expand All @@ -73,7 +72,6 @@ type rule struct {
val string // the value of the rule itself
negated bool // prefixed by !, a negated rule
negationsAfter bool // negatied rules appear after this rule
dirs []string // directories of the rule
regex *regexp.Regexp // regular expression to match for the rule
}

Expand Down Expand Up @@ -173,16 +171,20 @@ func (r *rule) compile() error {

var defaultExclusions = []rule{
{
val: strings.Join([]string{"**", ".git", "**"}, string(os.PathSeparator)),
negated: false,
val: strings.Join([]string{"**", ".terraform", "**"}, string(os.PathSeparator)),
negated: false,
negationsAfter: true,
},
// Place negation rules as high as possible in the list
{
val: strings.Join([]string{"**", ".terraform", "**"}, string(os.PathSeparator)),
negated: false,
val: strings.Join([]string{"**", ".terraform", "modules", "**"}, string(os.PathSeparator)),
negated: true,
negationsAfter: false,
},
{
val: strings.Join([]string{"**", ".terraform", "modules", "**"}, string(os.PathSeparator)),
negated: true,
val: strings.Join([]string{"**", ".git", "**"}, string(os.PathSeparator)),
negated: false,
negationsAfter: false,
},
}

Expand Down
33 changes: 33 additions & 0 deletions slug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,39 @@ func TestPack(t *testing.T) {
assertArchiveFixture(t, slug, meta)
}

func TestPack_defaultRulesOnly(t *testing.T) {
slug := bytes.NewBuffer(nil)
meta, err := Pack("testdata/archive-dir-defaults-only", slug, true)
if err != nil {
t.Fatalf("err: %v", err)
}

// Make sure .terraform/modules/** are included.
subModuleDir := false

// Make sure .terraform/plugins are excluded.
pluginsDir := false

for _, file := range meta.Files {
if strings.HasPrefix(file, filepath.Clean(".terraform/modules/subdir/README")) {
subModuleDir = true
continue
}

if strings.HasPrefix(file, filepath.Clean(".terraform/plugins/")) {
pluginsDir = true
continue
}
}
if !subModuleDir {
t.Fatal("expected to include .terraform/modules/subdir/README")
}

if pluginsDir {
t.Fatal("expected to exclude .terraform/plugins")
}
}

func TestPack_rootIsSymlink(t *testing.T) {
for _, path := range []string{
"testdata/archive-dir",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep this file and directory here to test if its properly ignored
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Keep this file and directory here to test if its properly ignored
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This file should be ignored
1 change: 1 addition & 0 deletions testdata/archive-dir-defaults-only/bar.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bar

0 comments on commit 0480d9e

Please sign in to comment.