Skip to content

Commit 9fd576e

Browse files
feat: patching now runs git apply
1 parent 42cbed2 commit 9fd576e

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

cmd/apply.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ var applyCmd = &cobra.Command{
1717
// check for setup
1818
return filesystem.ValidateDevLocalFilesystem()
1919
},
20-
2120
RunE: func(cmd *cobra.Command, args []string) error {
2221
return apply.Run()
2322
},

internal/git/patches.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ package git
22

33
import "fmt"
44

5-
func Generate(files []string) error {
5+
func checkPatchValidity(patchFile string) error {
6+
checkApplyArgs := append(
7+
[]string{
8+
"apply",
9+
"--check",
10+
},
11+
patchFile,
12+
)
613

7-
filesToDiff := sanitizeToTrackedFiles(files)
14+
return executeGitCommand(checkApplyArgs)
15+
}
816

9-
if len(filesToDiff) == 0 {
10-
return fmt.Errorf("[Error] No files provided to generate patches that are being tracked by git")
17+
func ApplyPatches(filesToPatch []string) error {
18+
for _, filePath := range filesToPatch {
19+
if err := checkPatchValidity(filePath); err != nil {
20+
fmt.Printf("\t[Error] while trying to patch file %s : %s\n", filePath, err.Error())
21+
}
1122
}
1223

1324
return nil

internal/git/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func executeGitCommand(args []string) error {
1111
out, err := cmd.CombinedOutput()
1212

1313
if err != nil {
14-
return fmt.Errorf("[Error] Failed to run Skip Worktree: %s", out)
14+
return fmt.Errorf("Failed to run git command: %s", out)
1515
}
1616

1717
return nil

internal/service/apply/applicator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,16 @@ func applyPatches(patchFiles []string) error {
1515
}
1616

1717
fmt.Println("[Running] patch for files: ", strings.Join(patchFiles, ", "))
18+
if len(patchFiles) == 0 {
19+
fmt.Println("[Warn] No patche files found in patches section of devloca config, skipping")
20+
return nil
21+
}
22+
23+
if err := git.ApplyPatches(patchFiles); err != nil {
24+
return err
25+
}
1826

27+
fmt.Println("[Completed] applying patches")
1928
return nil
2029
}
2130

@@ -53,5 +62,6 @@ func Run() error {
5362
return overlookErr
5463
}
5564

65+
fmt.Println("[Completed] applying devlocal changes")
5666
return nil
5767
}

0 commit comments

Comments
 (0)