CanApplyPatch returns true if the specified patch can be applied to HEAD without conficts.
(ctx context.Context, patch string)
| 33 | // CanApplyPatch returns true if the specified patch can be applied to HEAD |
| 34 | // without conficts. |
| 35 | func (g Git) CanApplyPatch(ctx context.Context, patch string) (bool, error) { |
| 36 | stdin := bytes.NewBuffer([]byte(patch)) |
| 37 | _, stderr, err := g.runWithStdin(ctx, stdin, "apply", "--check") |
| 38 | if err != nil { |
| 39 | for _, substr := range []string{ |
| 40 | "No such file or directory", |
| 41 | "patch failed", |
| 42 | "which does not match the current contents", |
| 43 | } { |
| 44 | if strings.Contains(stderr, substr) { |
| 45 | return false, nil |
| 46 | } |
| 47 | } |
| 48 | return false, err |
| 49 | } |
| 50 | return true, nil |
| 51 | } |
nothing calls this directly
no test coverage detected