@@ -73,7 +73,18 @@ func ComputeIdentity(
7373 DistroVersion : distroRef .Version ,
7474 }
7575
76- // 1. Hash the resolved config struct (excluding fingerprint:"-" fields).
76+ // 1. Verify all source files have a hash. Without a hash the fingerprint
77+ // cannot detect content changes, so we refuse to compute one.
78+ for i := range component .SourceFiles {
79+ if component .SourceFiles [i ].Hash == "" {
80+ return nil , fmt .Errorf (
81+ "source file %#q has no hash; cannot compute a deterministic fingerprint" ,
82+ component .SourceFiles [i ].Filename ,
83+ )
84+ }
85+ }
86+
87+ // 2. Hash the resolved config struct (excluding fingerprint:"-" fields).
7788 configHash , err := hashstructure .Hash (component , hashstructure .FormatV2 , & hashstructure.HashOptions {
7889 TagName : hashstructureTagName ,
7990 })
@@ -83,15 +94,15 @@ func ComputeIdentity(
8394
8495 inputs .ConfigHash = configHash
8596
86- // 2 . Hash overlay source file contents.
97+ // 3 . Hash overlay source file contents.
8798 overlayHashes , err := hashOverlayFiles (fs , component .Overlays )
8899 if err != nil {
89100 return nil , fmt .Errorf ("hashing overlay files:\n %w" , err )
90101 }
91102
92103 inputs .OverlayFileHashes = overlayHashes
93104
94- // 3 . Combine all inputs into the overall fingerprint.
105+ // 4 . Combine all inputs into the overall fingerprint.
95106 return & ComponentIdentity {
96107 Fingerprint : combineInputs (inputs ),
97108 Inputs : inputs ,
0 commit comments