patches will override when patches folder exist
This commit is contained in:
parent
1e5d7528f6
commit
a71e0804f2
1 changed files with 20 additions and 3 deletions
|
@ -7,7 +7,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ApplyPatches handles cloning and applying patches
|
// ApplyPatches handles cloning, updating, and applying patches
|
||||||
func ApplyPatches(sourcePath string, patchesRepo string) error {
|
func ApplyPatches(sourcePath string, patchesRepo string) error {
|
||||||
// Define the patches repository and clone directory
|
// Define the patches repository and clone directory
|
||||||
patchesCloneDir := filepath.Join(sourcePath, "patches")
|
patchesCloneDir := filepath.Join(sourcePath, "patches")
|
||||||
|
@ -27,12 +27,29 @@ func ApplyPatches(sourcePath string, patchesRepo string) error {
|
||||||
}
|
}
|
||||||
fmt.Println("Patches repository cloned successfully.")
|
fmt.Println("Patches repository cloned successfully.")
|
||||||
} else {
|
} 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
|
// Verify the directory exists
|
||||||
if _, err := os.Stat(patchesCloneDir); os.IsNotExist(err) {
|
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`
|
// Apply the patches using `go run apply.go`
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue