@@ -186,6 +186,18 @@ func createGoMod(tempDir, appDirName, goVersion string, opts BuildOpts, verbose
186186 return fmt .Errorf ("failed to copy existing go.mod: %w" , err )
187187 }
188188
189+ // Also copy go.sum if it exists
190+ originalGoSumPath := filepath .Join (opts .Dir , "go.sum" )
191+ if _ , err := os .Stat (originalGoSumPath ); err == nil {
192+ tempGoSumPath := filepath .Join (tempDir , "go.sum" )
193+ if err := copyFile (originalGoSumPath , tempGoSumPath ); err != nil {
194+ return fmt .Errorf ("failed to copy existing go.sum: %w" , err )
195+ }
196+ if verbose {
197+ log .Printf ("Found and copied existing go.sum from %s" , originalGoSumPath )
198+ }
199+ }
200+
189201 // Parse the existing go.mod
190202 goModContent , err := os .ReadFile (tempGoModPath )
191203 if err != nil {
@@ -545,14 +557,16 @@ func moveFilesBack(tempDir, originalDir string, verbose bool) error {
545557 log .Printf ("Moved go.mod back to %s" , goModDest )
546558 }
547559
548- // Move go.sum back to original directory
560+ // Move go.sum back to original directory (only if it exists)
549561 goSumSrc := filepath .Join (tempDir , "go.sum" )
550- goSumDest := filepath .Join (originalDir , "go.sum" )
551- if err := copyFile (goSumSrc , goSumDest ); err != nil {
552- return fmt .Errorf ("failed to copy go.sum back: %w" , err )
553- }
554- if verbose {
555- log .Printf ("Moved go.sum back to %s" , goSumDest )
562+ if _ , err := os .Stat (goSumSrc ); err == nil {
563+ goSumDest := filepath .Join (originalDir , "go.sum" )
564+ if err := copyFile (goSumSrc , goSumDest ); err != nil {
565+ return fmt .Errorf ("failed to copy go.sum back: %w" , err )
566+ }
567+ if verbose {
568+ log .Printf ("Moved go.sum back to %s" , goSumDest )
569+ }
556570 }
557571
558572 // Ensure static directory exists in original directory
0 commit comments