removed '--patches' flag, added '--pre-patch', '--post-patch', '--skip-patch-update'

This commit is contained in:
partisan 2024-12-11 17:07:08 +01:00
parent f497ac9999
commit ad7f7bf778
2 changed files with 65 additions and 32 deletions

View file

@ -8,7 +8,7 @@ import (
)
// ApplyPatches handles cloning, updating, and applying patches
func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string) error {
func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, patchesCloneDir string, skipUpdateRepo bool) error {
// Define the full patches path
fullPatchesPath := filepath.Join(patchesCloneDir, patchesPath) // Cleaned path without double slashes
@ -28,6 +28,27 @@ func ApplyPatches(sourcePath string, patchesRepo string, patchesPath string, pat
return fmt.Errorf("failed to clone patches repository: %v", err)
}
fmt.Println("Patches repository cloned successfully.")
} else {
if skipUpdateRepo {
// 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 patches directory exists