The word “cock” was once used as a playful substitute for “God”; i.e., cock's body, cock's bodikins, cock's bones, etc. “Pie” (or Pica) refers to a religious text, Sarum Ordinale. So, what you’re swearing on is “God & Church” - not cocks & pies.
"By Cocke and Pie, you shall not choose, Sir: come, come." (The Merry Wives of Windsor.)