MCPcopy Create free account
hub / github.com/google/gapid / CanApplyPatch

Method CanApplyPatch

core/git/patch.go:35–51  ·  view source on GitHub ↗

CanApplyPatch returns true if the specified patch can be applied to HEAD without conficts.

(ctx context.Context, patch string)

Source from the content-addressed store, hash-verified

33// CanApplyPatch returns true if the specified patch can be applied to HEAD
34// without conficts.
35func (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}

Callers

nothing calls this directly

Calls 2

runWithStdinMethod · 0.95
ContainsMethod · 0.65

Tested by

no test coverage detected