updated patching process
This commit is contained in:
parent
7840cb8b39
commit
1e5d7528f6
4 changed files with 134 additions and 43 deletions
spitfire
50
spitfire/patch.go
Normal file
50
spitfire/patch.go
Normal file
|
@ -0,0 +1,50 @@
|
|||
package spitfire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// ApplyPatches handles cloning and applying patches
|
||||
func ApplyPatches(sourcePath string, patchesRepo string) error {
|
||||
// Define the patches repository and clone directory
|
||||
patchesCloneDir := filepath.Join(sourcePath, "patches")
|
||||
fmt.Printf("Source Path: %s\n", sourcePath)
|
||||
fmt.Printf("Patches Clone Directory: %s\n", patchesCloneDir)
|
||||
fmt.Printf("Patches Repository URL: %s\n", patchesRepo)
|
||||
|
||||
// Check if the patches directory already exists
|
||||
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
||||
// Clone the patches repository
|
||||
fmt.Println("Patches directory does not exist. Proceeding to clone.")
|
||||
cmdClone := exec.Command("git", "clone", patchesRepo, patchesCloneDir)
|
||||
cmdClone.Stdout = os.Stdout
|
||||
cmdClone.Stderr = os.Stderr
|
||||
if err := cmdClone.Run(); err != nil {
|
||||
return fmt.Errorf("failed to clone patches repository: %v", err)
|
||||
}
|
||||
fmt.Println("Patches repository cloned successfully.")
|
||||
} else {
|
||||
fmt.Println("Patches directory already exists. Skipping clone.")
|
||||
}
|
||||
|
||||
// Verify the directory exists
|
||||
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
||||
return fmt.Errorf("patches directory not found after cloning: %s", patchesCloneDir)
|
||||
}
|
||||
|
||||
// Apply the patches using `go run apply.go`
|
||||
applyCmd := exec.Command("go", "run", "apply.go", "--path="+sourcePath)
|
||||
applyCmd.Dir = patchesCloneDir // Run from the patches directory
|
||||
applyCmd.Stdout = os.Stdout
|
||||
applyCmd.Stderr = os.Stderr
|
||||
fmt.Println("Applying patches...")
|
||||
if err := applyCmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to apply patches: %v", err)
|
||||
}
|
||||
|
||||
fmt.Println("Patches applied successfully.")
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue