patches will override when patches folder exist

This commit is contained in:
partisan 2024-12-08 15:39:19 +01:00
parent 1e5d7528f6
commit a71e0804f2

View file

@ -7,7 +7,7 @@ import (
"path/filepath"
)
// ApplyPatches handles cloning and applying patches
// ApplyPatches handles cloning, updating, and applying patches
func ApplyPatches(sourcePath string, patchesRepo string) error {
// Define the patches repository and clone directory
patchesCloneDir := filepath.Join(sourcePath, "patches")
@ -27,12 +27,29 @@ func ApplyPatches(sourcePath string, patchesRepo string) error {
}
fmt.Println("Patches repository cloned successfully.")
} else {
fmt.Println("Patches directory already exists. Skipping clone.")
// If the directory exists, fetch and pull the latest changes
fmt.Println("Patches directory already exists. Fetching latest changes.")
cmdFetch := exec.Command("git", "fetch", "--all")
cmdFetch.Dir = patchesCloneDir
cmdFetch.Stdout = os.Stdout
cmdFetch.Stderr = os.Stderr
if err := cmdFetch.Run(); err != nil {
return fmt.Errorf("failed to fetch updates for patches repository: %v", err)
}
cmdReset := exec.Command("git", "reset", "--hard", "origin/main")
cmdReset.Dir = patchesCloneDir
cmdReset.Stdout = os.Stdout
cmdReset.Stderr = os.Stderr
if err := cmdReset.Run(); err != nil {
return fmt.Errorf("failed to reset patches repository to latest state: %v", err)
}
fmt.Println("Patches repository updated successfully.")
}
// Verify the directory exists
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
return fmt.Errorf("patches directory not found after cloning: %s", patchesCloneDir)
return fmt.Errorf("patches directory not found after update: %s", patchesCloneDir)
}
// Apply the patches using `go run apply.go`