(exec latest.SyncExec, changedFiles []string)
| 332 | } |
| 333 | |
| 334 | func (u *upstream) execCommand(exec latest.SyncExec, changedFiles []string) error { |
| 335 | matched := "" |
| 336 | if len(exec.OnChange) > 0 { |
| 337 | Outer: |
| 338 | for _, pattern := range exec.OnChange { |
| 339 | pattern = path.Clean(pattern) |
| 340 | for _, file := range changedFiles { |
| 341 | if len(file) == 1 { |
| 342 | continue |
| 343 | } |
| 344 | |
| 345 | hasMatched, _ := doublestar.Match(pattern, file[1:]) |
| 346 | if hasMatched { |
| 347 | matched = file[1:] |
| 348 | break Outer |
| 349 | } |
| 350 | } |
| 351 | } |
| 352 | if matched == "" { |
| 353 | return nil |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | execCommand := exec.Command |
| 358 | execArgs := exec.Args |
| 359 | if u.sync.Options.ResolveCommand != nil { |
| 360 | var err error |
| 361 | execCommand, execArgs, err = u.sync.Options.ResolveCommand(execCommand, execArgs) |
| 362 | if err != nil { |
| 363 | return errors.Wrap(err, "resolve command") |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | execCommandName := exec.Name |
| 368 | if execCommandName == "" { |
| 369 | execCommandName = command.FormatCommandName(execCommand, execArgs) |
| 370 | } |
| 371 | |
| 372 | if exec.Local { |
| 373 | if matched != "" { |
| 374 | u.sync.log.Infof("Upstream - Execute command '%s' locally, because '%s' changed", execCommandName, matched) |
| 375 | } else { |
| 376 | u.sync.log.Infof("Upstream - Execute command '%s' locally", execCommandName) |
| 377 | } |
| 378 | |
| 379 | // if args are nil we execute the command in a shell |
| 380 | var ( |
| 381 | err error |
| 382 | out = &bytes.Buffer{} |
| 383 | ) |
| 384 | if exec.Args == nil { |
| 385 | err = engine.ExecuteSimpleShellCommand(u.sync.ctx, u.sync.LocalPath, expand.ListEnviron(os.Environ()...), out, out, nil, execCommand) |
| 386 | } else { |
| 387 | err = command.Command(u.sync.ctx, u.sync.LocalPath, expand.ListEnviron(os.Environ()...), out, out, nil, execCommand, exec.Args...) |
| 388 | } |
| 389 | if err != nil { |
| 390 | if exec.FailOnError { |
| 391 | return fmt.Errorf("error executing command %s: %s %v", execCommandName, out.String(), err) |
no test coverage detected