From a71e0804f221e246c942fcbc42088dd433899e60 Mon Sep 17 00:00:00 2001 From: partisan Date: Sun, 8 Dec 2024 15:39:19 +0100 Subject: [PATCH] patches will override when patches folder exist --- spitfire/patch.go | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/spitfire/patch.go b/spitfire/patch.go index cebe6c0..3066048 100644 --- a/spitfire/patch.go +++ b/spitfire/patch.go @@ -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`