Skip to content

Commit

Permalink
fix: replace cmd in jobs (#918)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox authored Jan 10, 2025
1 parent 3e3f880 commit 4f85d04
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
12 changes: 12 additions & 0 deletions internal/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,18 @@ func mergeJobsSlice(src, dest []interface{}) []interface{} {
destSubJobs = mergeJobsSlice(srcSubJobs, destSubJobs)
}

// Replace possible {cmd} before merging the jobs
switch srcRun := srcJob["run"].(type) {
case string:
switch destRun := destJob["run"].(type) {
case string:
newRun := strings.ReplaceAll(srcRun, CMD, destRun)
srcJob["run"] = newRun
default:
}
default:
}

maps.Merge(srcJob, destJob)

if len(destSubJobs) != 0 {
Expand Down
30 changes: 30 additions & 0 deletions internal/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,36 @@ pre-commit:
},
},
},
"with jobs overwrite": {
files: map[string]string{
"lefthook.yml": `
pre-commit:
jobs:
- name: job 1
run: echo from job 1
`,
"lefthook-local.yml": `
pre-commit:
jobs:
- name: job 1
run: wrap {cmd}
`,
},
result: &Config{
SourceDir: ".lefthook",
SourceDirLocal: ".lefthook-local",
Hooks: map[string]*Hook{
"pre-commit": {
Jobs: []*Job{
{
Name: "job 1",
Run: "wrap echo from job 1",
},
},
},
},
},
},
} {
fs := afero.Afero{Fs: afero.NewMemMapFs()}
repo := &git.Repository{
Expand Down

0 comments on commit 4f85d04

Please sign in to comment.