@@ -130,7 +130,6 @@ func planWorkflow(ctx context.Context, wr checks.WorkflowReport, opts PlanOption
130130 if rewriteRefs == nil {
131131 rewriteRefs = wr .ActionRefs
132132 }
133- rewriteRefKeys := actionRefKeys (rewriteRefs )
134133 selfActionRefKeys := actionRefKeys (wr .SelfActionRefs )
135134 if opts .PartialScan && ! opts .NoNarrow && opts .Tagger != nil {
136135 // ponytail: refuse any local-action repair in a partial scan; track
@@ -150,7 +149,7 @@ func planWorkflow(ctx context.Context, wr checks.WorkflowReport, opts PlanOption
150149
151150 if ! wr .NeedsAttention () && ! repinMoved {
152151 entries = verifiedEntries (inventory , wr .Path )
153- rw := narrowVerifiedEntries (ctx , entries , opts , rewriteRefKeys )
152+ rw := narrowVerifiedEntries (ctx , entries , opts , rewriteRefs )
154153 wplans = append (wplans , WorkflowPlan {Path : wr .Path , Rewrites : rw , SelfActionFiles : wr .SelfActionFiles })
155154 return planResult {entries : entries , wplans : wplans }, nil
156155 }
@@ -184,7 +183,7 @@ func planWorkflow(ctx context.Context, wr checks.WorkflowReport, opts PlanOption
184183 }
185184
186185 if len (unrecordedRefs ) == 0 {
187- rw := narrowVerifiedEntries (ctx , entries , opts , rewriteRefKeys )
186+ rw := narrowVerifiedEntries (ctx , entries , opts , rewriteRefs )
188187 wplans = append (wplans , WorkflowPlan {Path : wr .Path , Rewrites : rw , SelfActionFiles : wr .SelfActionFiles })
189188 return planResult {entries : entries , wplans : wplans }, nil
190189 }
@@ -274,7 +273,7 @@ func planWorkflow(ctx context.Context, wr checks.WorkflowReport, opts PlanOption
274273
275274 // Record workflow plan if there are rewrites.
276275 // Also narrow any verified (already-recorded) entries that have imprecise refs.
277- if verifiedRW := narrowVerifiedEntries (ctx , entries , opts , rewriteRefKeys ); len (verifiedRW ) > 0 {
276+ if verifiedRW := narrowVerifiedEntries (ctx , entries , opts , rewriteRefs ); len (verifiedRW ) > 0 {
278277 for k , v := range verifiedRW {
279278 rewrites [k ] = v
280279 }
@@ -643,10 +642,11 @@ func verifiedEntries(inventory []checks.InventoryEntry, path string) []Entry {
643642// narrowVerifiedEntries upgrades already-recorded direct deps to full semver
644643// tags when possible, returning the workflow-YAML rewrites. Skipped for
645644// --no-narrow, transitive deps, and refs the user kept imprecise (sticky v4).
646- func narrowVerifiedEntries (ctx context.Context , entries []Entry , opts PlanOptions , rewriteRefKeys map [ string ] bool ) map [string ]string {
645+ func narrowVerifiedEntries (ctx context.Context , entries []Entry , opts PlanOptions , rewriteRefs []parserlock. ActionRef ) map [string ]string {
647646 if opts .NoNarrow || opts .Tagger == nil {
648647 return nil
649648 }
649+ rewriteRefKeys := actionRefKeys (rewriteRefs )
650650 rewrites := make (map [string ]string )
651651 for i := range entries {
652652 e := & entries [i ]
@@ -664,8 +664,15 @@ func narrowVerifiedEntries(ctx context.Context, entries []Entry, opts PlanOption
664664 if newRef == "" {
665665 continue
666666 }
667+ if parserlock .IsFullSha (newRef ) || hasConflictingLockTarget (opts .Store , e .NWO , newRef , e .SHA ) {
668+ continue
669+ }
667670 oldRef := e .Ref
668- rewrites [e .NWO + "@" + oldRef ] = e .NWO + "@" + newRef
671+ for _ , ref := range rewriteRefs {
672+ if strings .EqualFold (ref .Owner + "/" + ref .Repo , e .NWO ) && ref .Ref == oldRef {
673+ rewrites [ref .FullName ()+ "@" + oldRef ] = ref .FullName () + "@" + newRef
674+ }
675+ }
669676 e .Ref = newRef
670677 e .AutoFixedRef = oldRef
671678 continue
@@ -716,6 +723,18 @@ func narrowVerifiedEntries(ctx context.Context, entries []Entry, opts PlanOption
716723 return rewrites
717724}
718725
726+ func hasConflictingLockTarget (store * lockfile.State , nwo , ref , sha string ) bool {
727+ if store == nil {
728+ return false
729+ }
730+ action , ok := store .File ().Dependencies [nwo + "@" + ref ]
731+ if ! ok {
732+ return false
733+ }
734+ _ , targetSHA , ok := strings .Cut (action .Commit , "-" )
735+ return ok && ! strings .EqualFold (targetSHA , sha )
736+ }
737+
719738func actionRefKeys (refs []parserlock.ActionRef ) map [string ]bool {
720739 keys := make (map [string ]bool , len (refs ))
721740 for _ , ref := range refs {
0 commit comments